#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 */
struct game {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, int *, ...);
int /*<<< orphan*/ query1(int /*<<< orphan*/ *, struct game **, int *, char *);
int /*<<< orphan*/ query2(int /*<<< orphan*/ *, struct game **, int *, char *);
void queryImport(struct game **cabinet, int *sizePtr) {
  FILE *ifpQuery, *ofp;
  ifpQuery = fopen("query.txt", "r");
  ofp = fopen("queryresults.out", "w");
  int queryAmount = 0, i, command;
  char nameGame[30];
  fscanf(ifpQuery, "%d", &queryAmount);
  for (i = 0; i < queryAmount; i++) {
    fscanf(ifpQuery, "%d %s", &command, &nameGame);
    switch (command) {
    case 1:
      query1(ofp, cabinet, sizePtr, nameGame);
      break;
    case 2:
      query2(ofp, cabinet, sizePtr, nameGame);
      break;
    }
  }
  fclose(ifpQuery);
  fclose(ofp);
}


x86 assembly (clang, -O0):
<queryImport>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe99(%rip),%rdi
lea    0xe9c(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
lea    0xe8e(%rip),%rdi
lea    0xe98(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe7f(%rip),%rsi
lea    -0x24(%rbp),%rdx
mov    $0x0,%al
call   1040 <fscanf@plt>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    123f <queryImport+0xef>
mov    -0x18(%rbp),%rdi
lea    0xe59(%rip),%rsi
xor    %eax,%eax
lea    -0x2c(%rbp),%rdx
lea    -0x50(%rbp),%rcx
call   1040 <fscanf@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x54(%rbp)
sub    $0x1,%eax
je     11fd <queryImport+0xad>
jmp    11ec <queryImport+0x9c>
mov    -0x54(%rbp),%eax
sub    $0x2,%eax
je     1217 <queryImport+0xc7>
jmp    122c <queryImport+0xdc>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
lea    -0x50(%rbp),%rcx
call   1070 <query1@plt>
jmp    122c <queryImport+0xdc>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
lea    -0x50(%rbp),%rcx
call   1050 <query2@plt>
jmp    1231 <queryImport+0xe1>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11b2 <queryImport+0x62>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<queryImport>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rsi,0x18(%rsp)
mov    %rdi,0x10(%rsp)
lea    0xe91(%rip),%rdi
lea    0xe94(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
lea    0xe87(%rip),%rdi
lea    0xe91(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%r12
movl   $0x0,0x8(%rsp)
lea    0xe7c(%rip),%rsi
lea    0x8(%rsp),%rdx
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <fscanf@plt>
cmpl   $0x0,0x8(%rsp)
jle    1228 <queryImport+0xd8>
lea    0xe62(%rip),%r13
lea    0xc(%rsp),%rbp
lea    0x20(%rsp),%r14
xor    %r15d,%r15d
jmp    11f0 <queryImport+0xa0>
nop
mov    %r12,%rdi
mov    0x10(%rsp),%rsi
mov    0x18(%rsp),%rdx
mov    %r14,%rcx
call   1050 <query2@plt>
add    $0x1,%r15d
cmp    0x8(%rsp),%r15d
jge    1228 <queryImport+0xd8>
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %rbp,%rdx
mov    %r14,%rcx
xor    %eax,%eax
call   1040 <fscanf@plt>
mov    0xc(%rsp),%eax
cmp    $0x2,%eax
je     11d0 <queryImport+0x80>
cmp    $0x1,%eax
jne    11e5 <queryImport+0x95>
mov    %r12,%rdi
mov    0x10(%rsp),%rsi
mov    0x18(%rsp),%rdx
mov    %r14,%rcx
call   1070 <query1@plt>
jmp    11e5 <queryImport+0x95>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %r12,%rdi
call   1030 <fclose@plt>
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.game = type { i32 }
@.str = [10 x i8] c"query.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [17 x i8] c"queryresults.out\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [3 x i8] c"%d\00"
@.str.5 = [6 x i8] c"%d %s\00"
define void @queryImport(%struct.game** %0, i32* %1) {
%3 = alloca %struct.game**
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca [30 x i8]
store %struct.game** %0, %struct.game*** %3
store i32* %1, i32** %4
%11 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %11, i32** %5
%12 = call i32* @fopen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %12, i32** %6
store i32 0, i32* %7
%13 = load i32*, i32** %5
%14 = call i32 (i32*, i8*, i32*, ...) @fscanf(i32* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %7)
store i32 0, i32* %8
br label %15
15: ; preds = %36, %2
%16 = load i32, i32* %8
%17 = load i32, i32* %7
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %39
19: ; preds = %15
%20 = load i32*, i32** %5
%21 = call i32 (i32*, i8*, i32*, ...) @fscanf(i32* %20, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32* %9, [30 x i8]* %10)
%22 = load i32, i32* %9
switch i32 %22, label %35 [
i32 1, label %23
i32 2, label %29
]
23: ; preds = %19
%24 = load i32*, i32** %6
%25 = load %struct.game**, %struct.game*** %3
%26 = load i32*, i32** %4
%27 = getelementptr inbounds [30 x i8], [30 x i8]* %10, i64 0, i64 0
%28 = call i32 @query1(i32* %24, %struct.game** %25, i32* %26, i8* %27)
br label %35
29: ; preds = %19
%30 = load i32*, i32** %6
%31 = load %struct.game**, %struct.game*** %3
%32 = load i32*, i32** %4
%33 = getelementptr inbounds [30 x i8], [30 x i8]* %10, i64 0, i64 0
%34 = call i32 @query2(i32* %30, %struct.game** %31, i32* %32, i8* %33)
br label %35
35: ; preds = %19, %29, %23
br label %36
36: ; preds = %35
%37 = load i32, i32* %8
%38 = add nsw i32 %37, 1
store i32 %38, i32* %8
br label %15
39: ; preds = %15
%40 = load i32*, i32** %5
%41 = call i32 @fclose(i32* %40)
%42 = load i32*, i32** %6
%43 = call i32 @fclose(i32* %42)
ret void
}

LLVM IR (-O2):
%struct.game = type { i32 }
@.str = [10 x i8] c"query.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [17 x i8] c"queryresults.out\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [3 x i8] c"%d\00"
@.str.5 = [6 x i8] c"%d %s\00"
define void @queryImport(%struct.game** %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca [30 x i8]
%6 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%7 = tail call i32* @fopen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%8 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%9 = bitcast i32* %4 to i8*
%10 = getelementptr inbounds [30 x i8], [30 x i8]* %5, i64 0, i64 0
%11 = call i32 (i32*, i8*, i32*, ...) @fscanf(i32* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %3)
%12 = load i32, i32* %3
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %26
14: ; preds = %2, %22
%15 = phi i32 [ %23, %22 ], [ 0, %2 ]
%16 = call i32 (i32*, i8*, i32*, ...) @fscanf(i32* %6, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32* %4, [30 x i8]* %5)
%17 = load i32, i32* %4
switch i32 %17, label %22 [
i32 1, label %18
i32 2, label %20
]
18: ; preds = %14
%19 = call i32 @query1(i32* %7, %struct.game** %0, i32* %1, i8* %10)
br label %22
20: ; preds = %14
%21 = call i32 @query2(i32* %7, %struct.game** %0, i32* %1, i8* %10)
br label %22
22: ; preds = %18, %20, %14
%23 = add nuw nsw i32 %15, 1
%24 = load i32, i32* %3
%25 = icmp slt i32 %23, %24
br i1 %25, label %14, label %26
26: ; preds = %22, %2
%27 = call i32 @fclose(i32* %6)
%28 = call i32 @fclose(i32* %7)
ret void
}