#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 glinearSearch(void *array, size_t elemSize, int len, void *key,
                  int (*cmp)(void *a, void *b)) {
  for (int i = 0; i < len; i++) {
    void *currentElem = array + (elemSize + i);
    if (cmp(currentElem, key) == 0)
      return i;
  }
  return -1;
}


x86 assembly (clang, -O0):
<glinearSearch>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1179 <glinearSearch+0x79>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
movslq -0x34(%rbp),%rdx
add    %rdx,%rcx
add    %rcx,%rax
mov    %rax,-0x40(%rbp)
mov    -0x30(%rbp),%rax
mov    -0x40(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   *%rax
cmp    $0x0,%eax
jne    1166 <glinearSearch+0x66>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1180 <glinearSearch+0x80>
jmp    116b <glinearSearch+0x6b>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1122 <glinearSearch+0x22>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<glinearSearch>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0xffffffff,%r14d
test   %edx,%edx
jle    114c <glinearSearch+0x4c>
mov    %r8,%r15
mov    %rcx,%r12
mov    %rdi,%rbx
mov    %edx,%r13d
add    %rsi,%rbx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
lea    (%rbx,%rbp,1),%rdi
mov    %r12,%rsi
call   *%r15
test   %eax,%eax
je     1149 <glinearSearch+0x49>
add    $0x1,%rbp
cmp    %rbp,%r13
jne    1130 <glinearSearch+0x30>
jmp    114c <glinearSearch+0x4c>
mov    %ebp,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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