#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 *, char *);
int findkey(char *str, char *key, int size) {
  int i;
  for (i = 0; key[0]; i++, key += size)
    if (!strcmp(str, key))
      return i;
  return (-1);
}


x86 assembly (clang, -O0):
<findkey>:
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    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
je     117c <findkey+0x6c>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%eax
jne    1158 <findkey+0x48>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1183 <findkey+0x73>
jmp    115d <findkey+0x4d>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%ecx
mov    -0x18(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
jmp    112a <findkey+0x1a>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<findkey>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    $0xffffffff,%r14d
cmpb   $0x0,(%rsi)
je     1154 <findkey+0x44>
mov    %rsi,%rbp
mov    %rdi,%r15
movslq %edx,%r12
xor    %ebx,%ebx
xchg   %ax,%ax
mov    %r15,%rdi
mov    %rbp,%rsi
call   1030 <strcmp@plt>
test   %eax,%eax
je     1151 <findkey+0x41>
add    $0x1,%ebx
cmpb   $0x0,0x0(%rbp,%r12,1)
lea    0x0(%rbp,%r12,1),%rbp
jne    1130 <findkey+0x20>
jmp    1154 <findkey+0x44>
mov    %ebx,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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