#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*/ S_IRWXU;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ fscanf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ mkdir(char *, int /*<<< orphan*/);
int database_number() {
  FILE *fp;
  mkdir("Database", S_IRWXU);
  fp = fopen("Database/database.txt", "r");
  int i;
  char choices[128];
  if (fp == NULL) {
    fp = fopen("Database/database.txt", "w");
    fclose(fp);
    return 0;
  }
  fp = fopen("Database/database.txt", "r");
  i = 0;
  while (fscanf(fp, " %[^\n]s", choices) != EOF) {
    i++;
  }
  return i;
  fclose(fp);
}


x86 assembly (clang, -O0):
<database_number>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    0x2e96(%rip),%rax
mov    (%rax),%esi
lea    0xea5(%rip),%rdi
call   1030 <mkdir@plt>
lea    0xea2(%rip),%rdi
lea    0xeb1(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11ae <database_number+0x6e>
lea    0xe80(%rip),%rdi
lea    0xe91(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
jmp    1207 <database_number+0xc7>
lea    0xe54(%rip),%rdi
lea    0xe63(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0xa0(%rbp),%rdx
lea    0xe45(%rip),%rsi
call   1050 <fscanf@plt>
mov    0x2df6(%rip),%rcx
cmp    (%rcx),%rax
je     1201 <database_number+0xc1>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11cc <database_number+0x8c>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<database_number>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x80,%rsp
mov    0x2e91(%rip),%rax
mov    (%rax),%esi
lea    0xea0(%rip),%rdi
call   1030 <mkdir@plt>
lea    0xe9d(%rip),%rdi
lea    0xeac(%rip),%rsi
call   1060 <fopen@plt>
lea    0xe8a(%rip),%rdi
test   %rax,%rax
je     11c9 <database_number+0x89>
lea    0xe94(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%r14
mov    $0xffffffff,%ebx
lea    0xe84(%rip),%r15
mov    %rsp,%r12
mov    0x2e37(%rip),%r13
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1050 <fscanf@plt>
add    $0x1,%ebx
cmp    0x0(%r13),%rax
jne    11b0 <database_number+0x70>
jmp    11df <database_number+0x9f>
lea    0xe51(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rdi
call   1040 <fclose@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x80,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

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