#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fail(char *);
int fscanf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ strcmp(char *, char *);
void findtoken(char *buf, char *token, FILE *ifp) {
  for (;;) {
    if (fscanf(ifp, "%s", buf) != 1)
      fail("Cannot find token in checkpoint file!");
    if (!token[0] || !strcmp(buf, token))
      break;
  }
}


x86 assembly (clang, -O0):
<findtoken>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xead(%rip),%rsi
call   1040 <fscanf@plt>
cmp    $0x1,%eax
je     116d <findtoken+0x3d>
lea    0xe9b(%rip),%rdi
call   1030 <fail@plt>
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     1190 <findtoken+0x60>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    1195 <findtoken+0x65>
jmp    119a <findtoken+0x6a>
jmp    1144 <findtoken+0x14>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<findtoken>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
lea    0xeb7(%rip),%r12
lea    0xeb3(%rip),%r13
mov    %r14,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1040 <fscanf@plt>
cmp    $0x1,%eax
je     116b <findtoken+0x3b>
mov    %r13,%rdi
call   1030 <fail@plt>
cmpb   $0x0,(%r15)
je     1180 <findtoken+0x50>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <strcmp@plt>
test   %eax,%eax
jne    1150 <findtoken+0x20>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@.str.1 = [38 x i8] c"Cannot find token in checkpoint file!\00"
define void @findtoken(i8* %0, i8* %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32* %2, i32** %6
br label %7
7: ; preds = %25, %3
%8 = load i32*, i32** %6
%9 = load i8*, i8** %4
%10 = call i32 @fscanf(i32* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = icmp ne i32 %10, 1
br i1 %11, label %12, label %14
12: ; preds = %7
%13 = call i32 @fail(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0))
br label %14
14: ; preds = %12, %7
%15 = load i8*, i8** %5
%16 = getelementptr inbounds i8, i8* %15, i64 0
%17 = load i8, i8* %16
%18 = icmp ne i8 %17, 0
br i1 %18, label %19, label %24
19: ; preds = %14
%20 = load i8*, i8** %4
%21 = load i8*, i8** %5
%22 = call i32 @strcmp(i8* %20, i8* %21)
%23 = icmp ne i32 %22, 0
br i1 %23, label %25, label %24
24: ; preds = %19, %14
br label %26
25: ; preds = %19
br label %7
26: ; preds = %24
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@.str.1 = [38 x i8] c"Cannot find token in checkpoint file!\00"
define void @findtoken(i8* %0, i8* nocapture %1, i32* nocapture %2) {
br label %4
4: ; preds = %12, %3
%5 = tail call i32 @fscanf(i32* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %0)
%6 = icmp eq i32 %5, 1
br i1 %6, label %9, label %7
7: ; preds = %4
%8 = tail call i32 @fail(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0))
br label %9
9: ; preds = %7, %4
%10 = load i8, i8* %1
%11 = icmp eq i8 %10, 0
br i1 %11, label %15, label %12
12: ; preds = %9
%13 = tail call i32 @strcmp(i8* dereferenceable(1) %0, i8* %1)
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %4
15: ; preds = %9, %12
ret void
}