Difference in generated code - Swift and C

fair enough

i’m just trying to understand this assembly here:

movq _T0s27_ContiguousArrayStorageBaseC16countAndCapacitys01_B4BodyVvpWvd@GOTPCREL(%rip), %rax

why are we loading things from the instruction pointer?

  movq (%rax), %rax
  movq (%rdi,%rax), %rcx
  testq %rcx, %rcx
  je .LBB2_1
  movl 32(%rdi), %eax
  addq $36, %rdi
  decq %rcx

I assume this has something to do with arrays keeping their count in a header attached to their backing storage,, or?

.LBB2_4:
  testq %rcx, %rcx
  je .LBB2_2
  decq %rcx
  addl (%rdi), %eax
  leaq 4(%rdi), %rdi
  jae .LBB2_4
  ud2

why did the compiler insert an invalid instruction right after the end of the loop? it never gets executed,, but why is it there?