#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 /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fwrite(short *, int, int, int /*<<< orphan*/ *);
void init_db(char *nome) {
  FILE *f = fopen(nome, "r+b");
  short m = 0;
  if (!f) {
    f = fopen(nome, "w+b");
  }
  if (!feof(f)) {
    fwrite(&m, sizeof(short), 1, f);
  }
  fclose(f);
}


x86 assembly (clang, -O0):
<init_db>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xea9(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
movw   $0x0,-0x12(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1185 <init_db+0x45>
mov    -0x8(%rbp),%rdi
lea    0xe88(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <feof@plt>
cmp    $0x0,%eax
jne    11ae <init_db+0x6e>
mov    -0x10(%rbp),%rcx
lea    -0x12(%rbp),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
call   1060 <fwrite@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_db>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0xeb2(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%rbx
movw   $0x0,0x6(%rsp)
test   %rax,%rax
jne    1174 <init_db+0x34>
lea    0xe9b(%rip),%rsi
mov    %r14,%rdi
call   1050 <fopen@plt>
mov    %rax,%rbx
mov    %rbx,%rdi
call   1040 <feof@plt>
test   %eax,%eax
jne    1197 <init_db+0x57>
lea    0x6(%rsp),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1060 <fwrite@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <fclose@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"r+b\00"
@.str.1 = [4 x i8] c"w+b\00"
define void @init_db(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i16
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i32* %6, i32** %3
store i16 0, i16* %4
%7 = load i32*, i32** %3
%8 = icmp ne i32* %7, null
br i1 %8, label %12, label %9
9: ; preds = %1
%10 = load i8*, i8** %2
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
store i32* %11, i32** %3
br label %12
12: ; preds = %9, %1
%13 = load i32*, i32** %3
%14 = call i32 @feof(i32* %13)
%15 = icmp ne i32 %14, 0
br i1 %15, label %19, label %16
16: ; preds = %12
%17 = load i32*, i32** %3
%18 = call i32 @fwrite(i16* %4, i32 2, i32 1, i32* %17)
br label %19
19: ; preds = %16, %12
%20 = load i32*, i32** %3
%21 = call i32 @fclose(i32* %20)
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"r+b\00"
@.str.1 = [4 x i8] c"w+b\00"
define void @init_db(i8* nocapture %0) {
%2 = alloca i16
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%4 = bitcast i16* %2 to i8*
store i16 0, i16* %2
%5 = icmp eq i32* %3, null
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
br label %8
8: ; preds = %6, %1
%9 = phi i32* [ %3, %1 ], [ %7, %6 ]
%10 = tail call i32 @feof(i32* %9)
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %8
%13 = call i32 @fwrite(i16* %2, i32 2, i32 1, i32* %9)
br label %14
14: ; preds = %12, %8
%15 = tail call i32 @fclose(i32* %9)
ret void
}