int Array_linear_search(int *arr, int len, int item) {
  assert(arr);
  assert(len > 0);
  int i = 0;
  for (i = 0; i < len; i++)
    if (arr[i] == item)
      return i;
  return -1;
  ;
}


x86 assembly (clang, -O0):
<Array_linear_search>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x0,%al
call   1030 <assert@plt>
cmpl   $0x0,-0x14(%rbp)
setg   %al
and    $0x1,%al
movzbl %al,%edi
mov    $0x0,%al
call   1030 <assert@plt>
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    118c <Array_linear_search+0x7c>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
cmp    -0x18(%rbp),%eax
jne    1179 <Array_linear_search+0x69>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1193 <Array_linear_search+0x83>
jmp    117e <Array_linear_search+0x6e>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    114e <Array_linear_search+0x3e>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Array_linear_search>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebp
mov    %esi,%r14d
mov    %rdi,%rbx
xor    %eax,%eax
call   1030 <assert@plt>
xor    %edi,%edi
test   %r14d,%r14d
setg   %dil
xor    %eax,%eax
call   1030 <assert@plt>
mov    $0xffffffff,%eax
test   %r14d,%r14d
jle    1162 <Array_linear_search+0x52>
mov    %r14d,%edx
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
cmp    %ebp,(%rbx,%rcx,4)
je     1160 <Array_linear_search+0x50>
add    $0x1,%rcx
cmp    %rcx,%rdx
jne    1150 <Array_linear_search+0x40>
jmp    1162 <Array_linear_search+0x52>
mov    %ecx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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