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

/* Variables and functions */
char *cw_strtok(char *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgetpos(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fsetpos(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int /*<<< orphan*/ strcmp(char *, char *);
int cw_file_find_game(char *game_id, FILE *file) {
  char buf[1024], *tok, *game;
  fpos_t filepos;
  rewind(file);
  while (!feof(file)) {
    fgetpos(file, &filepos);
    if (fgets(buf, 1023, file) == NULL) {
      return 0;
    }
    tok = cw_strtok(buf);
    game = cw_strtok(NULL);
    if (tok && !strcmp(tok, "id") && game && !strcmp(game, game_id)) {
      fsetpos(file, &filepos);
      return 1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<cw_file_find_game>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <rewind@plt>
mov    -0x18(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11aa <cw_file_find_game+0x3a>
jmp    127a <cw_file_find_game+0x10a>
mov    -0x18(%rbp),%rdi
lea    -0x434(%rbp),%rsi
call   1030 <fgetpos@plt>
lea    -0x420(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x3ff,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
jne    11e5 <cw_file_find_game+0x75>
movl   $0x0,-0x4(%rbp)
jmp    1281 <cw_file_find_game+0x111>
lea    -0x420(%rbp),%rdi
call   1080 <cw_strtok@plt>
mov    %rax,-0x428(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1080 <cw_strtok@plt>
mov    %rax,-0x430(%rbp)
cmpq   $0x0,-0x428(%rbp)
je     1275 <cw_file_find_game+0x105>
mov    -0x428(%rbp),%rdi
lea    0xddc(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    1275 <cw_file_find_game+0x105>
cmpq   $0x0,-0x430(%rbp)
je     1275 <cw_file_find_game+0x105>
mov    -0x430(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    1275 <cw_file_find_game+0x105>
mov    -0x18(%rbp),%rdi
lea    -0x434(%rbp),%rsi
call   1090 <fsetpos@plt>
movl   $0x1,-0x4(%rbp)
jmp    1281 <cw_file_find_game+0x111>
jmp    118c <cw_file_find_game+0x1c>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cw_file_find_game>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x418,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
call   1040 <rewind@plt>
mov    %rbx,%rdi
call   1070 <feof@plt>
xor    %ecx,%ecx
test   %eax,%eax
jne    1233 <cw_file_find_game+0xc3>
lea    0xc(%rsp),%r12
lea    0x10(%rsp),%r13
jmp    11bc <cw_file_find_game+0x4c>
nopl   (%rax)
mov    %rbx,%rdi
call   1070 <feof@plt>
test   %eax,%eax
jne    1231 <cw_file_find_game+0xc1>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1030 <fgetpos@plt>
mov    %r13,%rdi
mov    $0x3ff,%esi
mov    %rbx,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     1231 <cw_file_find_game+0xc1>
mov    %r13,%rdi
call   1080 <cw_strtok@plt>
mov    %rax,%r15
xor    %edi,%edi
call   1080 <cw_strtok@plt>
test   %r15,%r15
je     11b0 <cw_file_find_game+0x40>
mov    %rax,%rbp
mov    %r15,%rdi
lea    0xe00(%rip),%rsi
call   1060 <strcmp@plt>
test   %eax,%eax
jne    11b0 <cw_file_find_game+0x40>
test   %rbp,%rbp
je     11b0 <cw_file_find_game+0x40>
mov    %rbp,%rdi
mov    %r14,%rsi
call   1060 <strcmp@plt>
test   %eax,%eax
jne    11b0 <cw_file_find_game+0x40>
lea    0xc(%rsp),%rsi
mov    %rbx,%rdi
call   1090 <fsetpos@plt>
mov    $0x1,%ecx
jmp    1233 <cw_file_find_game+0xc3>
xor    %ecx,%ecx
mov    %ecx,%eax
add    $0x418,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"id\00"
define i32 @cw_file_find_game(i8* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca [1024 x i8]
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
store i8* %0, i8** %4
store i32* %1, i32** %5
%10 = load i32*, i32** %5
%11 = call i32 @rewind(i32* %10)
br label %12
12: ; preds = %46, %2
%13 = load i32*, i32** %5
%14 = call i32 @feof(i32* %13)
%15 = icmp ne i32 %14, 0
%16 = xor i1 %15, true
br i1 %16, label %17, label %47
17: ; preds = %12
%18 = load i32*, i32** %5
%19 = call i32 @fgetpos(i32* %18, i32* %9)
%20 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%21 = load i32*, i32** %5
%22 = call i32* @fgets(i8* %20, i32 1023, i32* %21)
%23 = icmp eq i32* %22, null
br i1 %23, label %24, label %25
24: ; preds = %17
store i32 0, i32* %3
br label %48
25: ; preds = %17
%26 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%27 = call i8* @cw_strtok(i8* %26)
store i8* %27, i8** %7
%28 = call i8* @cw_strtok(i8* null)
store i8* %28, i8** %8
%29 = load i8*, i8** %7
%30 = icmp ne i8* %29, null
br i1 %30, label %31, label %46
31: ; preds = %25
%32 = load i8*, i8** %7
%33 = call i32 @strcmp(i8* %32, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%34 = icmp ne i32 %33, 0
br i1 %34, label %46, label %35
35: ; preds = %31
%36 = load i8*, i8** %8
%37 = icmp ne i8* %36, null
br i1 %37, label %38, label %46
38: ; preds = %35
%39 = load i8*, i8** %8
%40 = load i8*, i8** %4
%41 = call i32 @strcmp(i8* %39, i8* %40)
%42 = icmp ne i32 %41, 0
br i1 %42, label %46, label %43
43: ; preds = %38
%44 = load i32*, i32** %5
%45 = call i32 @fsetpos(i32* %44, i32* %9)
store i32 1, i32* %3
br label %48
46: ; preds = %38, %35, %31, %25
br label %12
47: ; preds = %12
store i32 0, i32* %3
br label %48
48: ; preds = %47, %43, %24
%49 = load i32, i32* %3
ret i32 %49
}

LLVM IR (-O2):
@.str = [3 x i8] c"id\00"
define i32 @cw_file_find_game(i8* nocapture %0, i32* nocapture %1) {
%3 = alloca [1024 x i8]
%4 = alloca i32
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = bitcast i32* %4 to i8*
%7 = tail call i32 @rewind(i32* %1)
%8 = call i32 @feof(i32* %1)
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %31
10: ; preds = %2, %28
%11 = call i32 @fgetpos(i32* %1, i32* %4)
%12 = call i32* @fgets(i8* %5, i32 1023, i32* %1)
%13 = icmp eq i32* %12, null
br i1 %13, label %31, label %14
14: ; preds = %10
%15 = call i8* @cw_strtok(i8* %5)
%16 = call i8* @cw_strtok(i8* null)
%17 = icmp eq i8* %15, null
br i1 %17, label %28, label %18
18: ; preds = %14
%19 = call i32 @strcmp(i8* %15, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%20 = icmp eq i32 %19, 0
%21 = icmp ne i8* %16, null
%22 = select i1 %20, i1 %21, i1 false
br i1 %22, label %23, label %28
23: ; preds = %18
%24 = call i32 @strcmp(i8* %16, i8* dereferenceable(1) %0)
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %23
%27 = call i32 @fsetpos(i32* %1, i32* %4)
br label %31
28: ; preds = %23, %18, %14
%29 = call i32 @feof(i32* %1)
%30 = icmp eq i32 %29, 0
br i1 %30, label %10, label %31
31: ; preds = %10, %28, %2, %26
%32 = phi i32 [ 1, %26 ], [ 0, %2 ], [ 0, %28 ], [ 0, %10 ]
ret i32 %32
}