#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 /*<<< orphan*/ strcmp(char const *, char const *);
int trace_reg(const char *needle, const char **haystack, size_t size) {
  int i;
  for (i = 0; i < size; i++) {
    if (!strcmp(needle, haystack[i]))
      return i;
  }
  return -1;
}


x86 assembly (clang, -O0):
<trace_reg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movslq -0x24(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    1175 <trace_reg+0x65>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%eax
jne    1162 <trace_reg+0x52>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    117c <trace_reg+0x6c>
jmp    1167 <trace_reg+0x57>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    112b <trace_reg+0x1b>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<trace_reg>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    $0xffffffff,%r14d
test   %rdx,%rdx
je     114e <trace_reg+0x3e>
mov    %rdx,%rbx
mov    %rsi,%r15
mov    %rdi,%r12
xor    %ebp,%ebp
xchg   %ax,%ax
mov    (%r15,%rbp,8),%rsi
mov    %r12,%rdi
call   1030 <strcmp@plt>
test   %eax,%eax
je     114b <trace_reg+0x3b>
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    1130 <trace_reg+0x20>
jmp    114e <trace_reg+0x3e>
mov    %ebp,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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