#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 fib(int, int);
int /*<<< orphan*/ init_fib();
int pisano(int m) {
  int i = 2;
  init_fib();
  while (1) {
    if (0 == fib(i, m)) {
      ++i;
      if (1 == fib(i, m)) {
        break;
      }
    }
    ++i;
  }
  return (i - 1);
}


x86 assembly (clang, -O0):
<pisano>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x2,-0x8(%rbp)
mov    $0x0,%al
call   1040 <init_fib@plt>
mov    -0x8(%rbp),%edi
mov    -0x4(%rbp),%esi
call   1030 <fib@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    %ecx,%eax
jne    117d <pisano+0x5d>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x4(%rbp),%esi
call   1030 <fib@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cmp    %ecx,%eax
jne    1178 <pisano+0x58>
jmp    118b <pisano+0x6b>
jmp    117d <pisano+0x5d>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1139 <pisano+0x19>
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pisano>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%r14d
xor    %eax,%eax
call   1040 <init_fib@plt>
mov    $0x2,%ebx
jmp    1147 <pisano+0x27>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ebx,%ebp
add    $0x1,%ebp
mov    %ebp,%ebx
mov    %ebx,%edi
mov    %r14d,%esi
call   1030 <fib@plt>
test   %eax,%eax
jne    1140 <pisano+0x20>
lea    0x1(%rbx),%ebp
mov    %ebp,%edi
mov    %r14d,%esi
call   1030 <fib@plt>
cmp    $0x1,%eax
jne    1142 <pisano+0x22>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @pisano(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
store i32 2, i32* %3
%4 = call i32 (...) @init_fib()
br label %5
5: ; preds = %1, %19
%6 = load i32, i32* %3
%7 = load i32, i32* %2
%8 = call i32 @fib(i32 %6, i32 %7)
%9 = icmp eq i32 0, %8
br i1 %9, label %10, label %19
10: ; preds = %5
%11 = load i32, i32* %3
%12 = add nsw i32 %11, 1
store i32 %12, i32* %3
%13 = load i32, i32* %3
%14 = load i32, i32* %2
%15 = call i32 @fib(i32 %13, i32 %14)
%16 = icmp eq i32 1, %15
br i1 %16, label %17, label %18
17: ; preds = %10
br label %22
18: ; preds = %10
br label %19
19: ; preds = %18, %5
%20 = load i32, i32* %3
%21 = add nsw i32 %20, 1
store i32 %21, i32* %3
br label %5
22: ; preds = %17
%23 = load i32, i32* %3
%24 = sub nsw i32 %23, 1
ret i32 %24
}

LLVM IR (-O2):
define i32 @pisano(i32 %0) {
%2 = tail call i32 (...) @init_fib()
br label %3
3: ; preds = %11, %1
%4 = phi i32 [ 2, %1 ], [ %13, %11 ]
%5 = tail call i32 @fib(i32 %4, i32 %0)
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %11
7: ; preds = %3
%8 = add nsw i32 %4, 1
%9 = tail call i32 @fib(i32 %8, i32 %0)
%10 = icmp eq i32 %9, 1
br i1 %10, label %14, label %11
11: ; preds = %7, %3
%12 = phi i32 [ %8, %7 ], [ %4, %3 ]
%13 = add nsw i32 %12, 1
br label %3
14: ; preds = %7
ret i32 %4
}