#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 strlen(char *);
scalar_t__ strncmp(char *, char *, int);
int find_tok(int argc, char **argv, char *to_find) {
  int len = strlen(to_find);
  for (int i = 0; i < argc; i++) {
    int ll = strlen(argv[i]);
    if (ll >= len) {
      if (strncmp(argv[i], to_find, len) == 0)
        return i;
    }
  }
  return -1;
}


x86 assembly (clang, -O0):
<find_tok>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11b7 <find_tok+0x97>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jl     11a4 <find_tok+0x84>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    119f <find_tok+0x7f>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11be <find_tok+0x9e>
jmp    11a4 <find_tok+0x84>
jmp    11a9 <find_tok+0x89>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1146 <find_tok+0x26>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_tok>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rsi,%r13
mov    %edi,%r12d
mov    %rdx,%rdi
call   1040 <strlen@plt>
mov    $0xffffffff,%r14d
test   %r12d,%r12d
jle    117e <find_tok+0x5e>
mov    %eax,%ebx
mov    %r12d,%r12d
xor    %ebp,%ebp
jmp    1159 <find_tok+0x39>
add    $0x1,%rbp
cmp    %rbp,%r12
je     117e <find_tok+0x5e>
mov    0x0(%r13,%rbp,8),%rdi
call   1040 <strlen@plt>
cmp    %ebx,%eax
jl     1150 <find_tok+0x30>
mov    0x0(%r13,%rbp,8),%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    1150 <find_tok+0x30>
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 @find_tok(i32 %0, i8** %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 %0, i32* %5
store i8** %1, i8*** %6
store i8* %2, i8** %7
%11 = load i8*, i8** %7
%12 = call i32 @strlen(i8* %11)
store i32 %12, i32* %8
store i32 0, i32* %9
br label %13
13: ; preds = %41, %3
%14 = load i32, i32* %9
%15 = load i32, i32* %5
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %44
17: ; preds = %13
%18 = load i8**, i8*** %6
%19 = load i32, i32* %9
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8*, i8** %18, i64 %20
%22 = load i8*, i8** %21
%23 = call i32 @strlen(i8* %22)
store i32 %23, i32* %10
%24 = load i32, i32* %10
%25 = load i32, i32* %8
%26 = icmp sge i32 %24, %25
br i1 %26, label %27, label %40
27: ; preds = %17
%28 = load i8**, i8*** %6
%29 = load i32, i32* %9
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8*, i8** %28, i64 %30
%32 = load i8*, i8** %31
%33 = load i8*, i8** %7
%34 = load i32, i32* %8
%35 = call i64 @strncmp(i8* %32, i8* %33, i32 %34)
%36 = icmp eq i64 %35, 0
br i1 %36, label %37, label %39
37: ; preds = %27
%38 = load i32, i32* %9
store i32 %38, i32* %4
br label %45
39: ; preds = %27
br label %40
40: ; preds = %39, %17
br label %41
41: ; preds = %40
%42 = load i32, i32* %9
%43 = add nsw i32 %42, 1
store i32 %43, i32* %9
br label %13
44: ; preds = %13
store i32 -1, i32* %4
br label %45
45: ; preds = %44, %37
%46 = load i32, i32* %4
ret i32 %46
}

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