#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 length(int *);
int search(int arr[], int value) {
  int len = length(arr), i;
  for (i = 0; i < len; i++)
    if (arr[i] == value)
      return i;
  return -1;
}


x86 assembly (clang, -O0):
<search>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <length@plt>
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1170 <search+0x60>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
cmp    -0x14(%rbp),%eax
jne    115d <search+0x4d>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1177 <search+0x67>
jmp    1162 <search+0x52>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1132 <search+0x22>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<search>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
call   1030 <length@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
test   %ecx,%ecx
jle    1142 <search+0x32>
mov    %ecx,%edx
xor    %ecx,%ecx
nopl   0x0(%rax)
cmp    %ebp,(%rbx,%rcx,4)
je     1140 <search+0x30>
add    $0x1,%rcx
cmp    %rcx,%rdx
jne    1130 <search+0x20>
jmp    1142 <search+0x32>
mov    %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @search(i32* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
%8 = load i32*, i32** %4
%9 = call i32 @length(i32* %8)
store i32 %9, i32* %6
store i32 0, i32* %7
br label %10
10: ; preds = %25, %2
%11 = load i32, i32* %7
%12 = load i32, i32* %6
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %28
14: ; preds = %10
%15 = load i32*, i32** %4
%16 = load i32, i32* %7
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i32, i32* %15, i64 %17
%19 = load i32, i32* %18
%20 = load i32, i32* %5
%21 = icmp eq i32 %19, %20
br i1 %21, label %22, label %24
22: ; preds = %14
%23 = load i32, i32* %7
store i32 %23, i32* %3
br label %29
24: ; preds = %14
br label %25
25: ; preds = %24
%26 = load i32, i32* %7
%27 = add nsw i32 %26, 1
store i32 %27, i32* %7
br label %10
28: ; preds = %10
store i32 -1, i32* %3
br label %29
29: ; preds = %28, %22
%30 = load i32, i32* %3
ret i32 %30
}

LLVM IR (-O2):
define i32 @search(i32* %0, i32 %1) {
%3 = tail call i32 @length(i32* %0)
%4 = icmp sgt i32 %3, 0
br i1 %4, label %5, label %17
5: ; preds = %2
%6 = zext i32 %3 to i64
br label %7
7: ; preds = %5, %12
%8 = phi i64 [ 0, %5 ], [ %13, %12 ]
%9 = getelementptr inbounds i32, i32* %0, i64 %8
%10 = load i32, i32* %9
%11 = icmp eq i32 %10, %1
br i1 %11, label %15, label %12
12: ; preds = %7
%13 = add nuw nsw i64 %8, 1
%14 = icmp eq i64 %13, %6
br i1 %14, label %17, label %7
15: ; preds = %7
%16 = trunc i64 %8 to i32
br label %17
17: ; preds = %12, %15, %2
%18 = phi i32 [ -1, %2 ], [ %16, %15 ], [ -1, %12 ]
ret i32 %18
}