#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 */
typedef int /*<<< orphan*/ s;

/* Variables and functions */
int fibsrch(int *, int, int);
int /*<<< orphan*/ printf(char *, int);
int main(int argc, char *argv[]) {
  int s[10000];
  for (int i = 0; i < 10000; i++)
    s[i] = i + 1;
  int key, idx;
  key = 7989;
  printf("fib search iterative: %d\n", key);
  idx = fibsrch(s, sizeof(s) / sizeof(int), key);
  printf("hit %d\n", idx);
  key = 10100;
  printf("fib search iterative: %d\n", key);
  idx = fibsrch(s, sizeof(s) / sizeof(int), key);
  printf("hit %d\n", idx);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x9c60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x9c54(%rbp)
cmpl   $0x2710,-0x9c54(%rbp)
jge    117e <main+0x5e>
mov    -0x9c54(%rbp),%ecx
add    $0x1,%ecx
movslq -0x9c54(%rbp),%rax
mov    %ecx,-0x9c50(%rbp,%rax,4)
mov    -0x9c54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x9c54(%rbp)
jmp    1143 <main+0x23>
movl   $0x1f35,-0x9c58(%rbp)
mov    -0x9c58(%rbp),%esi
lea    0xe6b(%rip),%rdi
call   1040 <printf@plt>
lea    -0x9c50(%rbp),%rdi
mov    -0x9c58(%rbp),%edx
mov    $0x2710,%esi
call   1030 <fibsrch@plt>
mov    %eax,-0x9c5c(%rbp)
mov    -0x9c5c(%rbp),%esi
lea    0xe56(%rip),%rdi
call   1040 <printf@plt>
movl   $0x2774,-0x9c58(%rbp)
mov    -0x9c58(%rbp),%esi
lea    0xe20(%rip),%rdi
call   1040 <printf@plt>
lea    -0x9c50(%rbp),%rdi
mov    -0x9c58(%rbp),%edx
mov    $0x2710,%esi
call   1030 <fibsrch@plt>
mov    %eax,-0x9c5c(%rbp)
mov    -0x9c5c(%rbp),%esi
lea    0xe0b(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x9c60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x9c40,%rsp
movaps 0xecd(%rip),%xmm0
movaps 0xed6(%rip),%xmm1
mov    $0xc,%eax
pcmpeqd %xmm8,%xmm8
movdqa 0xed3(%rip),%xmm9
movdqa 0xedb(%rip),%xmm4
movdqa 0xee3(%rip),%xmm5
movdqa 0xeeb(%rip),%xmm6
cs nopw 0x0(%rax,%rax,1)
nop
movaps %xmm1,%xmm7
shufps $0x88,%xmm0,%xmm7
movaps %xmm7,%xmm2
psubd  %xmm8,%xmm2
movaps %xmm7,%xmm3
paddd  %xmm9,%xmm3
movdqa %xmm2,-0x30(%rsp,%rax,4)
movdqa %xmm3,-0x20(%rsp,%rax,4)
movaps %xmm7,%xmm2
paddd  %xmm4,%xmm2
paddd  %xmm5,%xmm7
movdqa %xmm2,-0x10(%rsp,%rax,4)
movdqa %xmm7,(%rsp,%rax,4)
paddq  %xmm6,%xmm1
paddq  %xmm6,%xmm0
add    $0x10,%rax
cmp    $0x271c,%rax
jne    1170 <main+0x50>
lea    0xe9c(%rip),%r14
mov    %r14,%rdi
mov    $0x1f35,%esi
call   1040 <printf@plt>
mov    %rsp,%r15
mov    %r15,%rdi
mov    $0x2710,%esi
mov    $0x1f35,%edx
call   1030 <fibsrch@plt>
lea    0xe8d(%rip),%rbx
mov    %rbx,%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    %r14,%rdi
mov    $0x2774,%esi
call   1040 <printf@plt>
mov    %r15,%rdi
mov    $0x2710,%esi
mov    $0x2774,%edx
call   1030 <fibsrch@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x9c40,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [26 x i8] c"fib search iterative: %d\0A\00"
@.str.1 = [8 x i8] c"hit %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [10000 x i32]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
br label %10
10: ; preds = %19, %2
%11 = load i32, i32* %7
%12 = icmp slt i32 %11, 10000
br i1 %12, label %13, label %22
13: ; preds = %10
%14 = load i32, i32* %7
%15 = add nsw i32 %14, 1
%16 = load i32, i32* %7
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [10000 x i32], [10000 x i32]* %6, i64 0, i64 %17
store i32 %15, i32* %18
br label %19
19: ; preds = %13
%20 = load i32, i32* %7
%21 = add nsw i32 %20, 1
store i32 %21, i32* %7
br label %10
22: ; preds = %10
store i32 7989, i32* %8
%23 = load i32, i32* %8
%24 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %23)
%25 = getelementptr inbounds [10000 x i32], [10000 x i32]* %6, i64 0, i64 0
%26 = load i32, i32* %8
%27 = call i32 @fibsrch(i32* %25, i32 10000, i32 %26)
store i32 %27, i32* %9
%28 = load i32, i32* %9
%29 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %28)
store i32 10100, i32* %8
%30 = load i32, i32* %8
%31 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %30)
%32 = getelementptr inbounds [10000 x i32], [10000 x i32]* %6, i64 0, i64 0
%33 = load i32, i32* %8
%34 = call i32 @fibsrch(i32* %32, i32 10000, i32 %33)
store i32 %34, i32* %9
%35 = load i32, i32* %9
%36 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %35)
ret i32 0
}

LLVM IR (-O2):
@.str = [26 x i8] c"fib search iterative: %d\0A\00"
@.str.1 = [8 x i8] c"hit %d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [10000 x i32]
%4 = bitcast [10000 x i32]* %3 to i8*
br label %5
5: ; preds = %5, %2
%6 = phi i64 [ 0, %2 ], [ %26, %5 ]
%7 = phi <4 x i64> [ <i64 0, i64 1, i64 2, i64 3>, %2 ], [ %27, %5 ]
%8 = getelementptr inbounds [10000 x i32], [10000 x i32]* %3, i64 0, i64 %6
%9 = trunc <4 x i64> %7 to <4 x i32>
%10 = add <4 x i32> %9, <i32 1, i32 1, i32 1, i32 1>
%11 = trunc <4 x i64> %7 to <4 x i32>
%12 = add <4 x i32> %11, <i32 5, i32 5, i32 5, i32 5>
%13 = bitcast i32* %8 to <4 x i32>*
store <4 x i32> %10, <4 x i32>* %13
%14 = getelementptr inbounds i32, i32* %8, i64 4
%15 = bitcast i32* %14 to <4 x i32>*
store <4 x i32> %12, <4 x i32>* %15
%16 = or i64 %6, 8
%17 = add <4 x i64> %7, <i64 8, i64 8, i64 8, i64 8>
%18 = getelementptr inbounds [10000 x i32], [10000 x i32]* %3, i64 0, i64 %16
%19 = trunc <4 x i64> %17 to <4 x i32>
%20 = add <4 x i32> %19, <i32 1, i32 1, i32 1, i32 1>
%21 = trunc <4 x i64> %17 to <4 x i32>
%22 = add <4 x i32> %21, <i32 5, i32 5, i32 5, i32 5>
%23 = bitcast i32* %18 to <4 x i32>*
store <4 x i32> %20, <4 x i32>* %23
%24 = getelementptr inbounds i32, i32* %18, i64 4
%25 = bitcast i32* %24 to <4 x i32>*
store <4 x i32> %22, <4 x i32>* %25
%26 = add nuw nsw i64 %6, 16
%27 = add <4 x i64> %7, <i64 16, i64 16, i64 16, i64 16>
%28 = icmp eq i64 %26, 10000
br i1 %28, label %29, label %5
29: ; preds = %5
%30 = tail call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 7989)
%31 = getelementptr inbounds [10000 x i32], [10000 x i32]* %3, i64 0, i64 0
%32 = call i32 @fibsrch(i32* %31, i32 10000, i32 7989)
%33 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %32)
%34 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 10100)
%35 = call i32 @fibsrch(i32* %31, i32 10000, i32 10100)
%36 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %35)
ret i32 0
}