#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);
int fibonacci_series(int limit) {
  int fib1 = 0, fib2 = 1, fib3, count = 0;
  printf("%d\n", fib1);
  printf("%d\n", fib2);
  count = 2;
  while (count < limit) {
    fib3 = fib1 + fib2;
    count++;
    printf("%d\n", fib3);
    fib1 = fib2;
    fib2 = fib3;
  }
  return fib3;
}


x86 assembly (clang, -O0):
<fibonacci_series>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%esi
lea    0xec6(%rip),%rdi
call   1030 <printf@plt>
mov    -0xc(%rbp),%esi
lea    0xeb7(%rip),%rdi
call   1030 <printf@plt>
movl   $0x2,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1193 <fibonacci_series+0x83>
mov    -0x8(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%esi
lea    0xe83(%rip),%rdi
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    1155 <fibonacci_series+0x45>
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fibonacci_series>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edi,%ebx
lea    0xedf(%rip),%r14
xor    %r15d,%r15d
mov    %r14,%rdi
xor    %esi,%esi
call   1030 <printf@plt>
mov    $0x1,%ebp
mov    %r14,%rdi
mov    $0x1,%esi
call   1030 <printf@plt>
cmp    $0x3,%ebx
jl     116b <fibonacci_series+0x5b>
add    $0xfffffffe,%ebx
lea    0xeb1(%rip),%r14
nop
mov    %ebp,%r12d
mov    %r15d,%ebp
add    %r12d,%ebp
mov    %r14,%rdi
mov    %ebp,%esi
call   1030 <printf@plt>
mov    %r12d,%r15d
add    $0xffffffff,%ebx
jne    1150 <fibonacci_series+0x40>
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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