#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 */
scalar_t__ EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ fscanf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ printf(char *, int, int);
scalar_t__ strcmp(char *, char *);
void read_file() {
  FILE *pf;
  pf = fopen("./testfile", "r");
  char buff[32];
  int steer = 0;
  int associ = 0;
  while (EOF != fscanf(pf, "%s", buff)) {
    if (0 == strcmp(buff, "STEERED"))
      fscanf(pf, "%d", &steer);
    if (0 == strcmp(buff, "ASSOCIATED"))
      fscanf(pf, "%d", &associ);
  }
  fclose(pf);
  printf("steer %d, associa %d\n", steer, associ);
}


x86 assembly (clang, -O0):
<read_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
lea    0xea1(%rip),%rdi
lea    0xea5(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x8(%rbp)
movl   $0x0,-0x34(%rbp)
movl   $0x0,-0x38(%rbp)
mov    0x2e64(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x40(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x30(%rbp),%rdx
lea    0xe73(%rip),%rsi
mov    $0x0,%al
call   1050 <fscanf@plt>
mov    %rax,%rcx
mov    -0x40(%rbp),%rax
cmp    %rcx,%rax
je     121e <read_file+0xce>
lea    -0x30(%rbp),%rdi
lea    0xe54(%rip),%rsi
call   1060 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    11e5 <read_file+0x95>
mov    -0x8(%rbp),%rdi
lea    0xe3e(%rip),%rsi
lea    -0x34(%rbp),%rdx
mov    $0x0,%al
call   1050 <fscanf@plt>
lea    -0x30(%rbp),%rdi
lea    0xe2b(%rip),%rsi
call   1060 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    1219 <read_file+0xc9>
mov    -0x8(%rbp),%rdi
lea    0xe0a(%rip),%rsi
lea    -0x38(%rbp),%rdx
mov    $0x0,%al
call   1050 <fscanf@plt>
jmp    117d <read_file+0x2d>
mov    -0x8(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x34(%rbp),%esi
mov    -0x38(%rbp),%edx
lea    0xdf2(%rip),%rdi
call   1040 <printf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
lea    0xe9b(%rip),%rdi
lea    0xe9f(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r15
movl   $0x0,0xc(%rsp)
movl   $0x0,0x8(%rsp)
mov    0x2e5d(%rip),%rax
mov    (%rax),%rbx
lea    0xe78(%rip),%rsi
lea    0x10(%rsp),%rdx
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <fscanf@plt>
cmp    %rax,%rbx
jne    11d4 <read_file+0x84>
mov    %r15,%rdi
call   1030 <fclose@plt>
mov    0xc(%rsp),%esi
mov    0x8(%rsp),%edx
lea    0xe66(%rip),%rdi
call   1040 <printf@plt>
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe35(%rip),%r14
lea    0x10(%rsp),%rbx
lea    0xe34(%rip),%rbp
lea    0xe1f(%rip),%r13
jmp    120f <read_file+0xbf>
mov    0x2df1(%rip),%rax
mov    (%rax),%r12
mov    %r15,%rdi
mov    %r13,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <fscanf@plt>
cmp    %rax,%r12
je     11a9 <read_file+0x59>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
jne    1235 <read_file+0xe5>
mov    %r15,%rdi
lea    0xdef(%rip),%rsi
lea    0xc(%rsp),%rdx
xor    %eax,%eax
call   1050 <fscanf@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
jne    11f0 <read_file+0xa0>
mov    %r15,%rdi
lea    0xdc9(%rip),%rsi
lea    0x8(%rsp),%rdx
xor    %eax,%eax
call   1050 <fscanf@plt>
jmp    11f0 <read_file+0xa0>

LLVM IR (-O0):
@.str = [11 x i8] c"./testfile\00"
@.str.1 = [2 x i8] c"r\00"
@EOF = global i64 0
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [8 x i8] c"STEERED\00"
@.str.4 = [3 x i8] c"%d\00"
@.str.5 = [11 x i8] c"ASSOCIATED\00"
@.str.6 = [22 x i8] c"steer %d, associa %d\0A\00"
define void @read_file() {
%1 = alloca i32*
%2 = alloca [32 x i8]
%3 = alloca i32
%4 = alloca i32
%5 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %5, i32** %1
store i32 0, i32* %3
store i32 0, i32* %4
br label %6
6: ; preds = %26, %0
%7 = load i64, i64* @EOF
%8 = load i32*, i32** %1
%9 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%10 = call i64 (i32*, i8*, ...) @fscanf(i32* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %9)
%11 = icmp ne i64 %7, %10
br i1 %11, label %12, label %27
12: ; preds = %6
%13 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%14 = call i64 @strcmp(i8* %13, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%15 = icmp eq i64 0, %14
br i1 %15, label %16, label %19
16: ; preds = %12
%17 = load i32*, i32** %1
%18 = call i64 (i32*, i8*, ...) @fscanf(i32* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %3)
br label %19
19: ; preds = %16, %12
%20 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%21 = call i64 @strcmp(i8* %20, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
%22 = icmp eq i64 0, %21
br i1 %22, label %23, label %26
23: ; preds = %19
%24 = load i32*, i32** %1
%25 = call i64 (i32*, i8*, ...) @fscanf(i32* %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %4)
br label %26
26: ; preds = %23, %19
br label %6
27: ; preds = %6
%28 = load i32*, i32** %1
%29 = call i32 @fclose(i32* %28)
%30 = load i32, i32* %3
%31 = load i32, i32* %4
%32 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0), i32 %30, i32 %31)
ret void
}

LLVM IR (-O2):
@.str = [11 x i8] c"./testfile\00"
@.str.1 = [2 x i8] c"r\00"
@EOF = global i64 0
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [8 x i8] c"STEERED\00"
@.str.4 = [3 x i8] c"%d\00"
@.str.5 = [11 x i8] c"ASSOCIATED\00"
@.str.6 = [22 x i8] c"steer %d, associa %d\0A\00"
define void @read_file() {
%1 = alloca [32 x i8]
%2 = alloca i32
%3 = alloca i32
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = getelementptr inbounds [32 x i8], [32 x i8]* %1, i64 0, i64 0
%6 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%7 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%8 = load i64, i64* @EOF
%9 = call i64 (i32*, i8*, ...) @fscanf(i32* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %5)
%10 = icmp eq i64 %8, %9
br i1 %10, label %25, label %11
11: ; preds = %0, %21
%12 = call i64 @strcmp(i8* %5, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %11
%15 = call i64 (i32*, i8*, ...) @fscanf(i32* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %2)
br label %16
16: ; preds = %14, %11
%17 = call i64 @strcmp(i8* %5, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %16
%20 = call i64 (i32*, i8*, ...) @fscanf(i32* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %3)
br label %21
21: ; preds = %19, %16
%22 = load i64, i64* @EOF
%23 = call i64 (i32*, i8*, ...) @fscanf(i32* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %5)
%24 = icmp eq i64 %22, %23
br i1 %24, label %25, label %11
25: ; preds = %21, %0
%26 = call i32 @fclose(i32* %4)
%27 = load i32, i32* %2
%28 = load i32, i32* %3
%29 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0), i32 %27, i32 %28)
ret void
}