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


x86 assembly (clang, -O0):
<findnkey>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    117e <findnkey+0x6e>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%eax
jne    115a <findnkey+0x4a>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1185 <findnkey+0x75>
jmp    115f <findnkey+0x4f>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x1c(%rbp),%ecx
mov    -0x18(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
jmp    112d <findnkey+0x1d>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<findnkey>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0xffffffff,%r14d
test   %ecx,%ecx
jle    115f <findnkey+0x4f>
mov    %ecx,%r12d
mov    %rsi,%rbx
mov    %rdi,%r15
movslq %edx,%r13
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r15,%rdi
mov    %rbx,%rsi
call   1030 <strcmp@plt>
test   %eax,%eax
je     115c <findnkey+0x4c>
add    $0x1,%ebp
add    %r13,%rbx
cmp    %ebp,%r12d
jne    1140 <findnkey+0x30>
jmp    115f <findnkey+0x4f>
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 @findnkey(i8* %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i32 0, i32* %10
br label %11
11: ; preds = %23, %4
%12 = load i32, i32* %10
%13 = load i32, i32* %9
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %30
15: ; preds = %11
%16 = load i8*, i8** %6
%17 = load i8*, i8** %7
%18 = call i32 @strcmp(i8* %16, i8* %17)
%19 = icmp ne i32 %18, 0
br i1 %19, label %22, label %20
20: ; preds = %15
%21 = load i32, i32* %10
store i32 %21, i32* %5
br label %31
22: ; preds = %15
br label %23
23: ; preds = %22
%24 = load i32, i32* %10
%25 = add nsw i32 %24, 1
store i32 %25, i32* %10
%26 = load i32, i32* %8
%27 = load i8*, i8** %7
%28 = sext i32 %26 to i64
%29 = getelementptr inbounds i8, i8* %27, i64 %28
store i8* %29, i8** %7
br label %11
30: ; preds = %11
store i32 -1, i32* %5
br label %31
31: ; preds = %30, %20
%32 = load i32, i32* %5
ret i32 %32
}

LLVM IR (-O2):
define i32 @findnkey(i8* nocapture %0, i8* nocapture %1, i32 %2, i32 %3) {
%5 = icmp sgt i32 %3, 0
br i1 %5, label %6, label %17
6: ; preds = %4
%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* dereferenceable(1) %10)
%12 = icmp eq i32 %11, 0
br i1 %12, label %17, label %13
13: ; preds = %8
%14 = add nuw nsw i32 %9, 1
%15 = getelementptr inbounds i8, i8* %10, i64 %7
%16 = icmp eq i32 %14, %3
br i1 %16, label %17, label %8
17: ; preds = %8, %13, %4
%18 = phi i32 [ -1, %4 ], [ -1, %13 ], [ %9, %8 ]
ret i32 %18
}