// Calculate the nth sequence number and return it. unsigned long long sequence(unsigned long long n) { if (n < 2) { return 1; } // This function cannot clear its stack memory until the next call returns. return n + sequence(n-1); }
sequence: pushq %rbp movq %rsp, %rbp subq $16, %rsp movq %rdi, -8(%rbp) cmpq $1, -8(%rbp) ja .L2 movl $1, %eax jmp .L3 .L2: movq -8(%rbp), %rax subq $1, %rax movq %rax, %rdi call sequence movq -8(%rbp), %rdx addq %rdx, %rax .L3: leave .cfi_def_cfa 7, 8 ret .cfi_endproc