#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 */
scalar_t__ strcmp(char const *, char const *);
int searchKeyTable(const char *table[], const int size, const char *key,
                   int *pos) {
  if (table == NULL || key == NULL || pos == NULL) {
    return -1;
  }
  int i = 0;
  int tmp = -1;
  for (i = 0; i < size; i++) {
    if (strcmp(table[i], key) == 0) {
      tmp = i;
      break;
    }
  }
  if (tmp != -1) {
    *pos = tmp + 1;
  } else {
    return -2;
  }
  return 0;
}


x86 assembly (clang, -O0):
<searchKeyTable>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1148 <searchKeyTable+0x38>
cmpq   $0x0,-0x20(%rbp)
je     1148 <searchKeyTable+0x38>
cmpq   $0x0,-0x28(%rbp)
jne    1154 <searchKeyTable+0x44>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e0 <searchKeyTable+0xd0>
movl   $0x0,-0x2c(%rbp)
movl   $0xffffffff,-0x30(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11b2 <searchKeyTable+0xa2>
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
jne    119f <searchKeyTable+0x8f>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x30(%rbp)
jmp    11b2 <searchKeyTable+0xa2>
jmp    11a4 <searchKeyTable+0x94>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1169 <searchKeyTable+0x59>
cmpl   $0xffffffff,-0x30(%rbp)
je     11cd <searchKeyTable+0xbd>
mov    -0x30(%rbp),%ecx
add    $0x1,%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
jmp    11d9 <searchKeyTable+0xc9>
movl   $0xfffffffe,-0x4(%rbp)
jmp    11e0 <searchKeyTable+0xd0>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<searchKeyTable>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0xffffffff,%r15d
test   %rdi,%rdi
je     1176 <searchKeyTable+0x66>
mov    %rdx,%r12
test   %rdx,%rdx
je     1176 <searchKeyTable+0x66>
mov    %rcx,%r14
test   %rcx,%rcx
je     1176 <searchKeyTable+0x66>
mov    $0xfffffffe,%r15d
test   %esi,%esi
jle    1176 <searchKeyTable+0x66>
mov    %rdi,%rbp
mov    %esi,%r13d
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    0x0(%rbp,%rbx,8),%rdi
mov    %r12,%rsi
call   1030 <strcmp@plt>
test   %rax,%rax
je     116d <searchKeyTable+0x5d>
add    $0x1,%rbx
cmp    %rbx,%r13
jne    1150 <searchKeyTable+0x40>
jmp    1176 <searchKeyTable+0x66>
add    $0x1,%ebx
mov    %ebx,(%r14)
xor    %r15d,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @searchKeyTable(i8** %0, i32 %1, i8* %2, i32* %3) {
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i32
store i8** %0, i8*** %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i32* %3, i32** %9
%12 = load i8**, i8*** %6
%13 = icmp eq i8** %12, null
br i1 %13, label %20, label %14
14: ; preds = %4
%15 = load i8*, i8** %8
%16 = icmp eq i8* %15, null
br i1 %16, label %20, label %17
17: ; preds = %14
%18 = load i32*, i32** %9
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %21
20: ; preds = %17, %14, %4
store i32 -1, i32* %5
br label %50
21: ; preds = %17
store i32 0, i32* %10
store i32 -1, i32* %11
store i32 0, i32* %10
br label %22
22: ; preds = %38, %21
%23 = load i32, i32* %10
%24 = load i32, i32* %7
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %41
26: ; preds = %22
%27 = load i8**, i8*** %6
%28 = load i32, i32* %10
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8*, i8** %27, i64 %29
%31 = load i8*, i8** %30
%32 = load i8*, i8** %8
%33 = call i64 @strcmp(i8* %31, i8* %32)
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %26
%36 = load i32, i32* %10
store i32 %36, i32* %11
br label %41
37: ; preds = %26
br label %38
38: ; preds = %37
%39 = load i32, i32* %10
%40 = add nsw i32 %39, 1
store i32 %40, i32* %10
br label %22
41: ; preds = %35, %22
%42 = load i32, i32* %11
%43 = icmp ne i32 %42, -1
br i1 %43, label %44, label %48
44: ; preds = %41
%45 = load i32, i32* %11
%46 = add nsw i32 %45, 1
%47 = load i32*, i32** %9
store i32 %46, i32* %47
br label %49
48: ; preds = %41
store i32 -2, i32* %5
br label %50
49: ; preds = %44
store i32 0, i32* %5
br label %50
50: ; preds = %49, %48, %20
%51 = load i32, i32* %5
ret i32 %51
}

LLVM IR (-O2):
define i32 @searchKeyTable(i8** %0, i32 %1, i8* %2, i32* writeonly %3) {
%5 = icmp eq i8** %0, null
%6 = icmp eq i8* %2, null
%7 = or i1 %5, %6
%8 = icmp eq i32* %3, null
%9 = or i1 %7, %8
br i1 %9, label %26, label %10
10: ; preds = %4
%11 = icmp sgt i32 %1, 0
br i1 %11, label %12, label %26
12: ; preds = %10
%13 = zext i32 %1 to i64
br label %14
14: ; preds = %12, %20
%15 = phi i64 [ 0, %12 ], [ %21, %20 ]
%16 = getelementptr inbounds i8*, i8** %0, i64 %15
%17 = load i8*, i8** %16
%18 = tail call i64 @strcmp(i8* %17, i8* %2)
%19 = icmp eq i64 %18, 0
br i1 %19, label %23, label %20
20: ; preds = %14
%21 = add nuw nsw i64 %15, 1
%22 = icmp eq i64 %21, %13
br i1 %22, label %26, label %14
23: ; preds = %14
%24 = trunc i64 %15 to i32
%25 = add nuw nsw i32 %24, 1
store i32 %25, i32* %3
br label %26
26: ; preds = %20, %10, %23, %4
%27 = phi i32 [ -1, %4 ], [ 0, %23 ], [ -2, %10 ], [ -2, %20 ]
ret i32 %27
}