#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 /*<<< orphan*/ scanf(char *, int *);
void iterative_fibobacci() {
  int term;
  int first = 0, second = 1, next, i;
  printf("Please input the term number for Iterative Fibonacci Sequence:\n");
  scanf("%d", &term);
  printf("The first %d terms of Fibonacci Sequences are :\n", term);
  for (i = 0; i < term;) {
    if (i <= 1) {
      next = i;
    } else {
      next = first + second;
      first = second;
      second = next;
    }
    printf("%d term -> %d\n", i, next);
    i = i + 1;
  }
}


x86 assembly (clang, -O0):
<iterative_fibobacci>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
lea    0xec3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xef5(%rip),%rdi
lea    -0x4(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x4(%rbp),%esi
lea    0xee5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11c4 <iterative_fibobacci+0xa4>
cmpl   $0x1,-0x14(%rbp)
jg     118d <iterative_fibobacci+0x6d>
mov    -0x14(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    11a2 <iterative_fibobacci+0x82>
mov    -0x8(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x14(%rbp),%esi
mov    -0x10(%rbp),%edx
lea    0xec5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    116c <iterative_fibobacci+0x4c>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<iterative_fibobacci>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xf05(%rip),%rdi
call   1030 <puts@plt>
lea    0xeb6(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1050 <scanf@plt>
mov    0x4(%rsp),%esi
lea    0xea4(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cmpl   $0x0,0x4(%rsp)
jle    11a6 <iterative_fibobacci+0x76>
mov    $0x1,%ebx
lea    0xebb(%rip),%r14
xor    %ebp,%ebp
xor    %r15d,%r15d
xchg   %ax,%ax
lea    (%rbx,%r15,1),%edx
cmp    $0x2,%ebp
cmovae %ebx,%r15d
cmovae %edx,%ebx
cmovb  %ebp,%edx
mov    %r14,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%ebp
cmp    0x4(%rsp),%ebp
jl     1180 <iterative_fibobacci+0x50>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [64 x i8] c"Please input the term number for Iterative Fibonacci Sequence:\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [49 x i8] c"The first %d terms of Fibonacci Sequences are :\0A\00"
@.str.3 = [15 x i8] c"%d term -> %d\0A\00"
define void @iterative_fibobacci() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %2
store i32 1, i32* %3
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%8 = load i32, i32* %1
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.2, i64 0, i64 0), i32 %8)
store i32 0, i32* %5
br label %10
10: ; preds = %25, %0
%11 = load i32, i32* %5
%12 = load i32, i32* %1
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %31
14: ; preds = %10
%15 = load i32, i32* %5
%16 = icmp sle i32 %15, 1
br i1 %16, label %17, label %19
17: ; preds = %14
%18 = load i32, i32* %5
store i32 %18, i32* %4
br label %25
19: ; preds = %14
%20 = load i32, i32* %2
%21 = load i32, i32* %3
%22 = add nsw i32 %20, %21
store i32 %22, i32* %4
%23 = load i32, i32* %3
store i32 %23, i32* %2
%24 = load i32, i32* %4
store i32 %24, i32* %3
br label %25
25: ; preds = %19, %17
%26 = load i32, i32* %5
%27 = load i32, i32* %4
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 %26, i32 %27)
%29 = load i32, i32* %5
%30 = add nsw i32 %29, 1
store i32 %30, i32* %5
br label %10
31: ; preds = %10
ret void
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [49 x i8] c"The first %d terms of Fibonacci Sequences are :\0A\00"
@.str.3 = [15 x i8] c"%d term -> %d\0A\00"
@str = [63 x i8] c"Please input the term number for Iterative Fibonacci Sequence:\00"
define void @iterative_fibobacci() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([63 x i8], [63 x i8]* @str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%5 = load i32, i32* %1
%6 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @.str.2, i64 0, i64 0), i32 %5)
%7 = load i32, i32* %1
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %22
9: ; preds = %0, %9
%10 = phi i32 [ %19, %9 ], [ 0, %0 ]
%11 = phi i32 [ %16, %9 ], [ 1, %0 ]
%12 = phi i32 [ %15, %9 ], [ 0, %0 ]
%13 = icmp ult i32 %10, 2
%14 = add nsw i32 %11, %12
%15 = select i1 %13, i32 %12, i32 %11
%16 = select i1 %13, i32 %11, i32 %14
%17 = select i1 %13, i32 %10, i32 %14
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 %10, i32 %17)
%19 = add nuw nsw i32 %10, 1
%20 = load i32, i32* %1
%21 = icmp slt i32 %19, %20
br i1 %21, label %9, label %22
22: ; preds = %9, %0
ret void
}