#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 *, char *);
void get_database(int choice, char *choices) {
  FILE *fp;
  fp = fopen("Database/database.txt", "r");
  int i;
  i = 0;
  while (fscanf(fp, " %[^\n]s", choices) != EOF) {
    if (i == choice)
      break;
    i++;
  }
  fclose(fp);
}


x86 assembly (clang, -O0):
<get_database>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xeba(%rip),%rdi
lea    0xec9(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xeac(%rip),%rsi
call   1040 <fscanf@plt>
mov    0x2e70(%rip),%rcx
cmp    (%rcx),%rax
je     11a0 <get_database+0x70>
mov    -0x1c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jne    1192 <get_database+0x62>
jmp    11a0 <get_database+0x70>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    115d <get_database+0x2d>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_database>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %edi,%ebp
lea    0xebc(%rip),%rdi
lea    0xecb(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%rbx
lea    0xebe(%rip),%r15
mov    0x2e87(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1040 <fscanf@plt>
sub    $0x1,%ebp
setb   %cl
cmp    (%r12),%rax
je     118e <get_database+0x5e>
test   %cl,%cl
je     1170 <get_database+0x40>
mov    %rbx,%rdi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fclose@plt>

LLVM IR (-O0):
@.str = [22 x i8] c"Database/database.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [8 x i8] c" %[^\0A]s\00"
@EOF = global i64 0
define void @get_database(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
%7 = call i32* @fopen(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %7, i32** %5
store i32 0, i32* %6
br label %8
8: ; preds = %19, %2
%9 = load i32*, i32** %5
%10 = load i8*, i8** %4
%11 = call i64 @fscanf(i32* %9, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %10)
%12 = load i64, i64* @EOF
%13 = icmp ne i64 %11, %12
br i1 %13, label %14, label %22
14: ; preds = %8
%15 = load i32, i32* %6
%16 = load i32, i32* %3
%17 = icmp eq i32 %15, %16
br i1 %17, label %18, label %19
18: ; preds = %14
br label %22
19: ; preds = %14
%20 = load i32, i32* %6
%21 = add nsw i32 %20, 1
store i32 %21, i32* %6
br label %8
22: ; preds = %18, %8
%23 = load i32*, i32** %5
%24 = call i32 @fclose(i32* %23)
ret void
}

LLVM IR (-O2):
@.str = [22 x i8] c"Database/database.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [8 x i8] c" %[^\0A]s\00"
@EOF = global i64 0
define void @get_database(i32 %0, i8* %1) {
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %4
4: ; preds = %4, %2
%5 = phi i32 [ 0, %2 ], [ %11, %4 ]
%6 = tail call i64 @fscanf(i32* %3, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %1)
%7 = load i64, i64* @EOF
%8 = icmp eq i64 %6, %7
%9 = icmp eq i32 %5, %0
%10 = select i1 %8, i1 true, i1 %9
%11 = add nuw nsw i32 %5, 1
br i1 %10, label %12, label %4
12: ; preds = %4
%13 = tail call i32 @fclose(i32* %3)
ret void
}