#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 */
int EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
int fscanf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ remove(char *);
int /*<<< orphan*/ rename(char *, char *);
int new_database(char *name) {
  FILE *fp, *gp;
  char database[128];
  int d;
  fp = fopen("Database/database.txt", "r");
  gp = fopen("Database/.database_temp.txt", "w");
  fprintf(gp, "%s\n", name);
  while ((d = fscanf(fp, " %[^\n]s", database)) && d != EOF) {
    fprintf(gp, "%s\n", database);
  }
  fclose(fp);
  fclose(gp);
  remove("Database/database.txt");
  rename("Database/.database_temp.txt", "Database/database.txt");
  return 1;
}


x86 assembly (clang, -O0):
<new_database>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xe8a(%rip),%rdi
lea    0xe99(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
lea    0xe8b(%rip),%rdi
lea    0xea0(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe8a(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x10(%rbp),%rdi
lea    -0xa0(%rbp),%rdx
lea    0xe77(%rip),%rsi
call   1050 <fscanf@plt>
mov    %eax,%ecx
mov    %ecx,-0xa4(%rbp)
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0xa5(%rbp)
je     11f9 <new_database+0x99>
mov    -0xa4(%rbp),%eax
mov    0x2dfa(%rip),%rcx
cmp    (%rcx),%eax
setne  %al
mov    %al,-0xa5(%rbp)
mov    -0xa5(%rbp),%al
test   $0x1,%al
jne    120c <new_database+0xac>
jmp    1228 <new_database+0xc8>
mov    -0x18(%rbp),%rdi
lea    -0xa0(%rbp),%rdx
lea    0xe18(%rip),%rsi
call   1060 <fprintf@plt>
jmp    11b1 <new_database+0x51>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
lea    0xdbf(%rip),%rdi
call   1030 <remove@plt>
lea    0xdcb(%rip),%rdi
lea    0xdac(%rip),%rsi
call   1080 <rename@plt>
mov    $0x1,%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<new_database>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x88,%rsp
mov    %rdi,%rbx
lea    0xe85(%rip),%rdi
lea    0xe94(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r14
lea    0xe87(%rip),%rdi
lea    0xe9c(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r12
lea    0xe8f(%rip),%rsi
mov    %rax,%rdi
mov    %rbx,%rdx
call   1060 <fprintf@plt>
lea    0xe81(%rip),%rsi
mov    %rsp,%rdx
mov    %r14,%rdi
call   1050 <fscanf@plt>
test   %eax,%eax
je     1215 <new_database+0xb5>
mov    0x2e19(%rip),%rbp
cmp    0x0(%rbp),%eax
je     1215 <new_database+0xb5>
lea    0xe5b(%rip),%r15
mov    %rsp,%rbx
lea    0xe55(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r12,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1060 <fprintf@plt>
mov    %r14,%rdi
mov    %r13,%rsi
mov    %rbx,%rdx
call   1050 <fscanf@plt>
test   %eax,%eax
je     1215 <new_database+0xb5>
cmp    0x0(%rbp),%eax
jne    11f0 <new_database+0x90>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %r12,%rdi
call   1040 <fclose@plt>
lea    0xdd4(%rip),%rbx
mov    %rbx,%rdi
call   1030 <remove@plt>
lea    0xddd(%rip),%rdi
mov    %rbx,%rsi
call   1080 <rename@plt>
mov    $0x1,%eax
add    $0x88,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [22 x i8] c"Database/database.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [28 x i8] c"Database/.database_temp.txt\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [4 x i8] c"%s\0A\00"
@.str.5 = [8 x i8] c" %[^\0A]s\00"
@EOF = global i32 0
define i32 @new_database(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca [128 x i8]
%6 = alloca i32
store i8* %0, i8** %2
%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** %3
%8 = call i32* @fopen(i8* getelementptr inbounds ([28 x i8], [28 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* %8, i32** %4
%9 = load i32*, i32** %4
%10 = load i8*, i8** %2
%11 = call i32 @fprintf(i32* %9, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %10)
br label %12
12: ; preds = %23, %1
%13 = load i32*, i32** %3
%14 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%15 = call i32 @fscanf(i32* %13, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8* %14)
store i32 %15, i32* %6
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %12
%18 = load i32, i32* %6
%19 = load i32, i32* @EOF
%20 = icmp ne i32 %18, %19
br label %21
21: ; preds = %17, %12
%22 = phi i1 [ false, %12 ], [ %20, %17 ]
br i1 %22, label %23, label %27
23: ; preds = %21
%24 = load i32*, i32** %4
%25 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%26 = call i32 @fprintf(i32* %24, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %25)
br label %12
27: ; preds = %21
%28 = load i32*, i32** %3
%29 = call i32 @fclose(i32* %28)
%30 = load i32*, i32** %4
%31 = call i32 @fclose(i32* %30)
%32 = call i32 @remove(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%33 = call i32 @rename(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
ret i32 1
}

LLVM IR (-O2):
@.str = [22 x i8] c"Database/database.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [28 x i8] c"Database/.database_temp.txt\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [4 x i8] c"%s\0A\00"
@.str.5 = [8 x i8] c" %[^\0A]s\00"
@EOF = global i32 0
define i32 @new_database(i8* %0) {
%2 = alloca [128 x i8]
%3 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%4 = 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))
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%6 = tail call i32 @fprintf(i32* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %0)
%7 = call i32 @fscanf(i32* %4, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8* %3)
%8 = icmp ne i32 %7, 0
%9 = load i32, i32* @EOF
%10 = icmp ne i32 %7, %9
%11 = select i1 %8, i1 %10, i1 false
br i1 %11, label %12, label %19
12: ; preds = %1, %12
%13 = call i32 @fprintf(i32* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %3)
%14 = call i32 @fscanf(i32* %4, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8* %3)
%15 = icmp ne i32 %14, 0
%16 = load i32, i32* @EOF
%17 = icmp ne i32 %14, %16
%18 = select i1 %15, i1 %17, i1 false
br i1 %18, label %12, label %19
19: ; preds = %12, %1
%20 = call i32 @fclose(i32* %4)
%21 = call i32 @fclose(i32* %5)
%22 = call i32 @remove(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%23 = call i32 @rename(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
ret i32 1
}