#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 *, char *);
int findPosition(char *s, char **table, int size) {
  int i = 0;
  do {
    if (strcmp(s, table[i]) == 0)
      return i;
    i++;
  } while (i < size);
  return -1;
}


x86 assembly (clang, -O0):
<findPosition>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
jne    1154 <findPosition+0x44>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1170 <findPosition+0x60>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jl     112a <findPosition+0x1a>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<findPosition>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
cmp    $0x2,%edx
mov    $0x1,%r12d
cmovge %edx,%r12d
xor    %ebx,%ebx
nopl   (%rax)
mov    (%r14,%rbx,8),%rsi
mov    %r15,%rdi
call   1030 <strcmp@plt>
test   %rax,%rax
je     114f <findPosition+0x3f>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1130 <findPosition+0x20>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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