#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 *, ...);
void lucas_sequence(int n) {
  unsigned long L0 = 2, L1 = 1, Ln;
  int i;
  for (i = 0; i <= n; i++) {
    if (i == 0) {
      printf("\n\n\n\t   |N|        LUCAS NUMBER\n\n\n");
      printf("\t[ n = %d ] -\t [ %lu ]\t\n\n\n", i, L0);
    } else if (i == 1) {
      printf("\t[ n = %d ] -\t [ %lu ]\t\n\n\n", i, L1);
    } else {
      Ln = L0 + L1;
      printf("\t[ n = %d ] -\t [ %lu ]\t\n\n\n", i, Ln);
      L0 = L1;
      L1 = Ln;
    }
  }
}


x86 assembly (clang, -O0):
<lucas_sequence>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
movq   $0x2,-0x10(%rbp)
movq   $0x1,-0x18(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x4(%rbp),%eax
jg     11dd <lucas_sequence+0xcd>
cmpl   $0x0,-0x24(%rbp)
jne    1170 <lucas_sequence+0x60>
lea    0xeb1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x24(%rbp),%esi
mov    -0x10(%rbp),%rdx
lea    0xebe(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11ca <lucas_sequence+0xba>
cmpl   $0x1,-0x24(%rbp)
jne    1194 <lucas_sequence+0x84>
mov    -0x24(%rbp),%esi
mov    -0x18(%rbp),%rdx
lea    0xe9a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11c5 <lucas_sequence+0xb5>
mov    -0x10(%rbp),%rax
add    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x24(%rbp),%esi
mov    -0x20(%rbp),%rdx
lea    0xe74(%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)
jmp    11ca <lucas_sequence+0xba>
jmp    11cf <lucas_sequence+0xbf>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1132 <lucas_sequence+0x22>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lucas_sequence>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %edi,%edi
js     11b7 <lucas_sequence+0x97>
mov    %edi,%r12d
add    $0x1,%r12d
mov    $0x1,%ebx
mov    $0x2,%r13d
lea    0xeb4(%rip),%r14
lea    0xec8(%rip),%r15
xor    %ebp,%ebp
jmp    1183 <lucas_sequence+0x63>
nopw   0x0(%rax,%rax,1)
add    %rbx,%r13
mov    %r14,%rdi
mov    %ebp,%esi
mov    %r13,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r13,%rax
mov    %rbx,%r13
add    $0x1,%ebp
mov    %rax,%rbx
cmp    %ebp,%r12d
je     11b7 <lucas_sequence+0x97>
cmp    $0x1,%ebp
je     11a0 <lucas_sequence+0x80>
test   %ebp,%ebp
jne    1160 <lucas_sequence+0x40>
mov    %r15,%rdi
call   1030 <puts@plt>
mov    %r14,%rdi
xor    %esi,%esi
mov    %r13,%rdx
jmp    11ab <lucas_sequence+0x8b>
xchg   %ax,%ax
mov    %r14,%rdi
mov    $0x1,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rax
jmp    1178 <lucas_sequence+0x58>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [34 x i8] c"\0A\0A\0A\09 |N| LUCAS NUMBER\0A\0A\0A\00"
@.str.1 = [27 x i8] c"\09[ n = %d ] -\09 [ %lu ]\09\0A\0A\0A\00"
define void @lucas_sequence(i32 %0) {
%2 = alloca i32
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = alloca i32
store i32 %0, i32* %2
store i64 2, i64* %3
store i64 1, i64* %4
store i32 0, i32* %6
br label %7
7: ; preds = %37, %1
%8 = load i32, i32* %6
%9 = load i32, i32* %2
%10 = icmp sle i32 %8, %9
br i1 %10, label %11, label %40
11: ; preds = %7
%12 = load i32, i32* %6
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %19
14: ; preds = %11
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%16 = load i32, i32* %6
%17 = load i64, i64* %3
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 %16, i64 %17)
br label %36
19: ; preds = %11
%20 = load i32, i32* %6
%21 = icmp eq i32 %20, 1
br i1 %21, label %22, label %26
22: ; preds = %19
%23 = load i32, i32* %6
%24 = load i64, i64* %4
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 %23, i64 %24)
br label %35
26: ; preds = %19
%27 = load i64, i64* %3
%28 = load i64, i64* %4
%29 = add i64 %27, %28
store i64 %29, i64* %5
%30 = load i32, i32* %6
%31 = load i64, i64* %5
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 %30, i64 %31)
%33 = load i64, i64* %4
store i64 %33, i64* %3
%34 = load i64, i64* %5
store i64 %34, i64* %4
br label %35
35: ; preds = %26, %22
br label %36
36: ; preds = %35, %14
br label %37
37: ; preds = %36
%38 = load i32, i32* %6
%39 = add nsw i32 %38, 1
store i32 %39, i32* %6
br label %7
40: ; preds = %7
ret void
}

LLVM IR (-O2):
@.str.1 = [27 x i8] c"\09[ n = %d ] -\09 [ %lu ]\09\0A\0A\0A\00"
@str = [33 x i8] c"\0A\0A\0A\09 |N| LUCAS NUMBER\0A\0A\00"
define void @lucas_sequence(i32 %0) {
%2 = icmp slt i32 %0, 0
br i1 %2, label %20, label %3
3: ; preds = %1, %15
%4 = phi i32 [ %18, %15 ], [ 0, %1 ]
%5 = phi i64 [ %17, %15 ], [ 2, %1 ]
%6 = phi i64 [ %16, %15 ], [ 1, %1 ]
switch i32 %4, label %12 [
i32 0, label %7
i32 1, label %10
]
7: ; preds = %3
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str, i64 0, i64 0))
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 0, i64 %5)
br label %15
10: ; preds = %3
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 1, i64 %6)
br label %15
12: ; preds = %3
%13 = add i64 %5, %6
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 %4, i64 %13)
br label %15
15: ; preds = %7, %12, %10
%16 = phi i64 [ %6, %7 ], [ %6, %10 ], [ %13, %12 ]
%17 = phi i64 [ %5, %7 ], [ %5, %10 ], [ %6, %12 ]
%18 = add nuw i32 %4, 1
%19 = icmp eq i32 %4, %0
br i1 %19, label %20, label %3
20: ; preds = %15, %1
ret void
}