#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__ calloc(int, int);
scalar_t__ get_token(int, char *, int);
int strlen(char const *);
scalar_t__ strncmp(char *, char const *, int);
int find_token(int fd, const char *token) {
  int tmp_len = strlen(token);
  char *tmp_token = (char *)calloc(tmp_len, 1);
  if (!tmp_token) {
    return -1;
  }
  while (strncmp(tmp_token, token, tmp_len) != 0) {
    if (get_token(fd, tmp_token, tmp_len) <= 0) {
      return -1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<find_token>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1183 <find_token+0x43>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d3 <find_token+0x93>
jmp    1188 <find_token+0x48>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     11cc <find_token+0x8c>
mov    -0x8(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1060 <get_token@plt>
cmp    $0x0,%rax
jg     11c7 <find_token+0x87>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d3 <find_token+0x93>
jmp    1188 <find_token+0x48>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_token>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r12
mov    %edi,%r15d
mov    %rsi,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    %eax,%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    $0xffffffff,%r14d
test   %rax,%rax
je     11a9 <find_token+0x69>
mov    %rax,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %ebp,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     11a6 <find_token+0x66>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1060 <get_token@plt>
test   %rax,%rax
jg     1180 <find_token+0x40>
jmp    11a9 <find_token+0x69>
xor    %r14d,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @find_token(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
store i32 %0, i32* %4
store i8* %1, i8** %5
%8 = load i8*, i8** %5
%9 = call i32 @strlen(i8* %8)
store i32 %9, i32* %6
%10 = load i32, i32* %6
%11 = call i64 @calloc(i32 %10, i32 1)
%12 = inttoptr i64 %11 to i8*
store i8* %12, i8** %7
%13 = load i8*, i8** %7
%14 = icmp ne i8* %13, null
br i1 %14, label %16, label %15
15: ; preds = %2
store i32 -1, i32* %3
br label %32
16: ; preds = %2
br label %17
17: ; preds = %30, %16
%18 = load i8*, i8** %7
%19 = load i8*, i8** %5
%20 = load i32, i32* %6
%21 = call i64 @strncmp(i8* %18, i8* %19, i32 %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %31
23: ; preds = %17
%24 = load i32, i32* %4
%25 = load i8*, i8** %7
%26 = load i32, i32* %6
%27 = call i64 @get_token(i32 %24, i8* %25, i32 %26)
%28 = icmp sle i64 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %23
store i32 -1, i32* %3
br label %32
30: ; preds = %23
br label %17
31: ; preds = %17
store i32 0, i32* %3
br label %32
32: ; preds = %31, %29, %15
%33 = load i32, i32* %3
ret i32 %33
}

LLVM IR (-O2):
define i32 @find_token(i32 %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %1)
%4 = tail call i64 @calloc(i32 %3, i32 1)
%5 = inttoptr i64 %4 to i8*
%6 = icmp eq i64 %4, 0
br i1 %6, label %13, label %7
7: ; preds = %2, %10
%8 = tail call i64 @strncmp(i8* %5, i8* %1, i32 %3)
%9 = icmp eq i64 %8, 0
br i1 %9, label %13, label %10
10: ; preds = %7
%11 = tail call i64 @get_token(i32 %0, i8* %5, i32 %3)
%12 = icmp slt i64 %11, 1
br i1 %12, label %13, label %7
13: ; preds = %7, %10, %2
%14 = phi i32 [ -1, %2 ], [ 0, %7 ], [ -1, %10 ]
ret i32 %14
}