#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
int lucas_numbers(int n) {
  unsigned long preprevious_number = 2, previous_number = 1, current_number;
  int i;
  printf("N#1=2\n");
  printf("N#2=1\n");
  for (i = 3; i <= n; i++) {
    current_number = preprevious_number + previous_number;
    printf("N#%d=%lu\n", i, current_number);
    preprevious_number = previous_number;
    previous_number = current_number;
  }
}


x86 assembly (clang, -O0):
<lucas_numbers>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
movq   $0x2,-0x10(%rbp)
movq   $0x1,-0x18(%rbp)
lea    0xece(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xec7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x3,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     1199 <lucas_numbers+0x89>
mov    -0x10(%rbp),%rax
add    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x24(%rbp),%esi
mov    -0x20(%rbp),%rdx
lea    0xe9a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    114e <lucas_numbers+0x3e>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lucas_numbers>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %edi,%r15d
lea    0xed7(%rip),%rdi
call   1030 <puts@plt>
lea    0xed1(%rip),%rdi
call   1030 <puts@plt>
cmp    $0x3,%r15d
jl     11a1 <lucas_numbers+0x81>
neg    %r15d
mov    $0x1,%r13d
mov    $0x2,%eax
mov    $0x3,%r12d
lea    0xe9b(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rax,%rbx
add    %r13,%rbx
mov    %r14,%rdi
mov    %r12d,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
lea    (%r15,%r12,1),%ecx
add    $0x1,%ecx
mov    %r12d,%eax
add    $0x1,%eax
mov    %eax,%r12d
mov    %r13,%rax
mov    %rbx,%r13
cmp    $0x1,%ecx
jne    1170 <lucas_numbers+0x50>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [7 x i8] c"N=2\0A\00"
@.str.1 = [7 x i8] c"N=1\0A\00"
@.str.2 = [10 x i8] c"N#%d=%lu\0A\00"
define i32 @lucas_numbers(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca i32
store i32 %0, i32* %3
store i64 2, i64* %4
store i64 1, i64* %5
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
store i32 3, i32* %7
br label %10
10: ; preds = %23, %1
%11 = load i32, i32* %7
%12 = load i32, i32* %3
%13 = icmp sle i32 %11, %12
br i1 %13, label %14, label %26
14: ; preds = %10
%15 = load i64, i64* %4
%16 = load i64, i64* %5
%17 = add i64 %15, %16
store i64 %17, i64* %6
%18 = load i32, i32* %7
%19 = load i64, i64* %6
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %18, i64 %19)
%21 = load i64, i64* %5
store i64 %21, i64* %4
%22 = load i64, i64* %6
store i64 %22, i64* %5
br label %23
23: ; preds = %14
%24 = load i32, i32* %7
%25 = add nsw i32 %24, 1
store i32 %25, i32* %7
br label %10
26: ; preds = %10
%27 = load i32, i32* %2
ret i32 %27
}

LLVM IR (-O2):
@.str.2 = [10 x i8] c"N#%d=%lu\0A\00"
@str = [6 x i8] c"N=2\00"
@str.3 = [6 x i8] c"N=1\00"
define i32 @lucas_numbers(i32 %0) {
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0))
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str.3, i64 0, i64 0))
%4 = icmp slt i32 %0, 3
br i1 %4, label %13, label %5
5: ; preds = %1, %5
%6 = phi i32 [ %11, %5 ], [ 3, %1 ]
%7 = phi i64 [ %8, %5 ], [ 2, %1 ]
%8 = phi i64 [ %9, %5 ], [ 1, %1 ]
%9 = add i64 %7, %8
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %6, i64 %9)
%11 = add nuw i32 %6, 1
%12 = icmp eq i32 %6, %0
br i1 %12, label %13, label %5
13: ; preds = %5, %1
ret i32 undef
}