However, the machine code looks different in both cases:
julia> @code_native N_iterator(A, N)
.text
; ┌ @ eachindex.jl:3 within `N_iterator'
pushq %rbp
movq %rsp, %rbp
; │ @ eachindex.jl:4 within `N_iterator'
; │┌ @ range.jl:5 within `Colon'
; ││┌ @ range.jl:280 within `UnitRange'
; │││┌ @ range.jl:285 within `unitrange_last'
; ││││┌ @ operators.jl:350 within `>='
; │││││┌ @ int.jl:441 within `<='
testq %rsi, %rsi
; │└└└└└
jle L80
movq %rsi, %rax
sarq $63, %rax
andnq %rsi, %rax, %rcx
movq (%rdi), %r9
movq 8(%rdi), %rsi
; │ @ eachindex.jl:5 within `N_iterator'
; │┌ @ array.jl:847 within `setindex!'
leaq 1(%rsi), %r8
negq %rsi
negq %rcx
movl $1, %eax
nopl (%rax,%rax)
L48:
leaq (%rsi,%rax), %rdx
cmpq $1, %rdx
je L85
movq %rax, -8(%r9,%rax,8)
; │└
; │┌ @ range.jl:624 within `iterate'
; ││┌ @ promotion.jl:398 within `=='
leaq (%rcx,%rax), %rdx
addq $1, %rdx
; ││└
incq %rax
; ││┌ @ promotion.jl:398 within `=='
cmpq $1, %rdx
; │└└
jne L48
L80:
movq %rbp, %rsp
popq %rbp
retq
; │┌ @ array.jl:847 within `setindex!'
L85:
movq %rsp, %rax
leaq -16(%rax), %rsi
movq %rsi, %rsp
movq %r8, -16(%rax)
movabsq $jl_bounds_error_ints, %rax
movl $1, %edx
callq *%rax
nopw %cs:(%rax,%rax)
nop
; └└
julia> @code_native length_iterator(A)
.text
; ┌ @ eachindex.jl:9 within `length_iterator'
pushq %rbp
movq %rsp, %rbp
subq $16, %rsp
movq %rsi, -8(%rbp)
movq (%rsi), %rdi
; │ @ eachindex.jl:10 within `length_iterator'
; │┌ @ array.jl:219 within `length'
movq 8(%rdi), %rax
; │└
; │┌ @ range.jl:5 within `Colon'
; ││┌ @ range.jl:280 within `UnitRange'
; │││┌ @ range.jl:285 within `unitrange_last'
; ││││┌ @ operators.jl:350 within `>='
; │││││┌ @ int.jl:441 within `<='
testq %rax, %rax
; │└└└└└
jle L96
movq %rax, %rcx
sarq $63, %rcx
andnq %rax, %rcx, %rdx
movq (%rdi), %r9
; │ @ eachindex.jl:11 within `length_iterator'
; │┌ @ array.jl:847 within `setindex!'
leaq 1(%rax), %r8
negq %rax
negq %rdx
movl $1, %ecx
nopw %cs:(%rax,%rax)
L64:
leaq (%rax,%rcx), %rsi
cmpq $1, %rsi
je L111
movq %rcx, -8(%r9,%rcx,8)
; │└
; │┌ @ range.jl:624 within `iterate'
; ││┌ @ promotion.jl:398 within `=='
leaq (%rdx,%rcx), %rsi
addq $1, %rsi
; ││└
incq %rcx
; ││┌ @ promotion.jl:398 within `=='
cmpq $1, %rsi
; │└└
jne L64
L96:
movabsq $jl_system_image_data, %rax
; │ @ eachindex.jl:11 within `length_iterator'
movq %rbp, %rsp
popq %rbp
retq
; │┌ @ array.jl:847 within `setindex!'
L111:
movq %rsp, %rax
leaq -16(%rax), %rsi
movq %rsi, %rsp
movq %r8, -16(%rax)
movabsq $jl_bounds_error_ints, %rax
movl $1, %edx
callq *%rax
; └└