#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_first_game(FILE *file) {
  char buf[256], *tok;
  fpos_t filepos;
  rewind(file);
  while (!feof(file)) {
    fgetpos(file, &filepos);
    if (fgets(buf, 256, file) == NULL) {
      return 0;
    }
    tok = cw_strtok(buf);
    if (tok && !strcmp(tok, "id")) {
      fsetpos(file, &filepos);
      return 1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<cw_file_find_first_game>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <rewind@plt>
mov    -0x10(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11a6 <cw_file_find_first_game+0x36>
jmp    123f <cw_file_find_first_game+0xcf>
mov    -0x10(%rbp),%rdi
lea    -0x11c(%rbp),%rsi
call   1030 <fgetpos@plt>
lea    -0x110(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x100,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
jne    11e1 <cw_file_find_first_game+0x71>
movl   $0x0,-0x4(%rbp)
jmp    1246 <cw_file_find_first_game+0xd6>
lea    -0x110(%rbp),%rdi
call   1080 <cw_strtok@plt>
mov    %rax,-0x118(%rbp)
cmpq   $0x0,-0x118(%rbp)
je     123a <cw_file_find_first_game+0xca>
mov    -0x118(%rbp),%rdi
lea    0xdf0(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    123a <cw_file_find_first_game+0xca>
mov    -0x10(%rbp),%rdi
lea    -0x11c(%rbp),%rsi
call   1090 <fsetpos@plt>
movl   $0x1,-0x4(%rbp)
jmp    1246 <cw_file_find_first_game+0xd6>
jmp    1188 <cw_file_find_first_game+0x18>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cw_file_find_first_game>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x110,%rsp
mov    %rdi,%rbx
call   1040 <rewind@plt>
mov    %rbx,%rdi
call   1070 <feof@plt>
xor    %r14d,%r14d
test   %eax,%eax
je     11a9 <cw_file_find_first_game+0x39>
mov    %r14d,%eax
add    $0x110,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xc(%rsp),%r15
lea    0x10(%rsp),%rbp
lea    0xe46(%rip),%r12
jmp    11cc <cw_file_find_first_game+0x5c>
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1070 <feof@plt>
test   %eax,%eax
jne    1196 <cw_file_find_first_game+0x26>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <fgetpos@plt>
mov    %rbp,%rdi
mov    $0x100,%esi
mov    %rbx,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     1196 <cw_file_find_first_game+0x26>
mov    %rbp,%rdi
call   1080 <cw_strtok@plt>
test   %rax,%rax
je     11c0 <cw_file_find_first_game+0x50>
mov    %rax,%rdi
mov    %r12,%rsi
call   1060 <strcmp@plt>
test   %eax,%eax
jne    11c0 <cw_file_find_first_game+0x50>
lea    0xc(%rsp),%rsi
mov    %rbx,%rdi
call   1090 <fsetpos@plt>
mov    $0x1,%r14d
jmp    1196 <cw_file_find_first_game+0x26>

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

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