#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*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
long fread(char *, int, long, int /*<<< orphan*/ *);
scalar_t__ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/, int /*<<< orphan*/);
long ftell(int /*<<< orphan*/ *);
char *malloc(long);
int shittydb_get(char **val, const char *key) {
  FILE *file = fopen(key, "r");
  if (!file)
    return 1;
  if (fseek(file, 0, SEEK_END)) {
    fclose(file);
    return 1;
  };
  long off = ftell(file);
  if (off < 0) {
    fclose(file);
    return 1;
  };
  if (fseek(file, 0, SEEK_SET)) {
    fclose(file);
    return 1;
  };
  char *response = malloc(off + 1);
  if (!response) {
    fclose(file);
    return 1;
  };
  if (fread(response, sizeof(*response), off, file) != off) {
    fclose(file);
    return 1;
  };
  response[off] = '\0';
  fclose(file);
  *val = response;
  return 0;
}


x86 assembly (clang, -O0):
<shittydb_get>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe85(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    119b <shittydb_get+0x3b>
movl   $0x1,-0x4(%rbp)
jmp    12bb <shittydb_get+0x15b>
mov    -0x20(%rbp),%rdi
mov    0x2e42(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1070 <fseek@plt>
cmp    $0x0,%rax
je     11ce <shittydb_get+0x6e>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x1,-0x4(%rbp)
jmp    12bb <shittydb_get+0x15b>
mov    -0x20(%rbp),%rdi
call   1050 <ftell@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jge    11fb <shittydb_get+0x9b>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x1,-0x4(%rbp)
jmp    12bb <shittydb_get+0x15b>
mov    -0x20(%rbp),%rdi
mov    0x2dd2(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1070 <fseek@plt>
cmp    $0x0,%rax
je     122e <shittydb_get+0xce>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x1,-0x4(%rbp)
jmp    12bb <shittydb_get+0x15b>
mov    -0x28(%rbp),%rdi
add    $0x1,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    125f <shittydb_get+0xff>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x1,-0x4(%rbp)
jmp    12bb <shittydb_get+0x15b>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
cmp    -0x28(%rbp),%rax
je     1294 <shittydb_get+0x134>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x1,-0x4(%rbp)
jmp    12bb <shittydb_get+0x15b>
mov    -0x30(%rbp),%rax
mov    -0x28(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x30(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<shittydb_get>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%rax
mov    %rdi,%r14
lea    0xe8b(%rip),%rsi
mov    %rax,%rdi
call   1080 <fopen@plt>
mov    $0x1,%ebp
test   %rax,%rax
je     11aa <shittydb_get+0x4a>
mov    %rax,%rbx
mov    0x2e57(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1070 <fseek@plt>
test   %rax,%rax
je     11b5 <shittydb_get+0x55>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rbx,%rdi
call   1050 <ftell@plt>
test   %rax,%rax
js     11a2 <shittydb_get+0x42>
mov    %rax,%r15
mov    0x2e0c(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1070 <fseek@plt>
test   %rax,%rax
jne    11a2 <shittydb_get+0x42>
lea    0x1(%r15),%rdi
call   1060 <malloc@plt>
test   %rax,%rax
je     11a2 <shittydb_get+0x42>
mov    %rax,%r12
mov    $0x1,%ebp
mov    %rax,%rdi
mov    $0x1,%esi
mov    %r15,%rdx
mov    %rbx,%rcx
call   1030 <fread@plt>
cmp    %r15,%rax
jne    11a2 <shittydb_get+0x42>
movb   $0x0,(%r12,%r15,1)
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %r12,(%r14)
xor    %ebp,%ebp
jmp    11aa <shittydb_get+0x4a>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define i32 @shittydb_get(i8** %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i64
%8 = alloca i8*
store i8** %0, i8*** %4
store i8* %1, i8** %5
%9 = load i8*, i8** %5
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %6
%11 = load i32*, i32** %6
%12 = icmp ne i32* %11, null
br i1 %12, label %14, label %13
13: ; preds = %2
store i32 1, i32* %3
br label %65
14: ; preds = %2
%15 = load i32*, i32** %6
%16 = load i32, i32* @SEEK_END
%17 = call i64 @fseek(i32* %15, i32 0, i32 %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %14
%20 = load i32*, i32** %6
%21 = call i32 @fclose(i32* %20)
store i32 1, i32* %3
br label %65
22: ; preds = %14
%23 = load i32*, i32** %6
%24 = call i64 @ftell(i32* %23)
store i64 %24, i64* %7
%25 = load i64, i64* %7
%26 = icmp slt i64 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %22
%28 = load i32*, i32** %6
%29 = call i32 @fclose(i32* %28)
store i32 1, i32* %3
br label %65
30: ; preds = %22
%31 = load i32*, i32** %6
%32 = load i32, i32* @SEEK_SET
%33 = call i64 @fseek(i32* %31, i32 0, i32 %32)
%34 = icmp ne i64 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %30
%36 = load i32*, i32** %6
%37 = call i32 @fclose(i32* %36)
store i32 1, i32* %3
br label %65
38: ; preds = %30
%39 = load i64, i64* %7
%40 = add nsw i64 %39, 1
%41 = call i8* @malloc(i64 %40)
store i8* %41, i8** %8
%42 = load i8*, i8** %8
%43 = icmp ne i8* %42, null
br i1 %43, label %47, label %44
44: ; preds = %38
%45 = load i32*, i32** %6
%46 = call i32 @fclose(i32* %45)
store i32 1, i32* %3
br label %65
47: ; preds = %38
%48 = load i8*, i8** %8
%49 = load i64, i64* %7
%50 = load i32*, i32** %6
%51 = call i64 @fread(i8* %48, i32 1, i64 %49, i32* %50)
%52 = load i64, i64* %7
%53 = icmp ne i64 %51, %52
br i1 %53, label %54, label %57
54: ; preds = %47
%55 = load i32*, i32** %6
%56 = call i32 @fclose(i32* %55)
store i32 1, i32* %3
br label %65
57: ; preds = %47
%58 = load i8*, i8** %8
%59 = load i64, i64* %7
%60 = getelementptr inbounds i8, i8* %58, i64 %59
store i8 0, i8* %60
%61 = load i32*, i32** %6
%62 = call i32 @fclose(i32* %61)
%63 = load i8*, i8** %8
%64 = load i8**, i8*** %4
store i8* %63, i8** %64
store i32 0, i32* %3
br label %65
65: ; preds = %57, %54, %44, %35, %27, %19, %13
%66 = load i32, i32* %3
ret i32 %66
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define i32 @shittydb_get(i8** nocapture writeonly %0, i8* nocapture %1) {
%3 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %36, label %5
5: ; preds = %2
%6 = load i32, i32* @SEEK_END
%7 = tail call i64 @fseek(i32* %3, i32 0, i32 %6)
%8 = icmp eq i64 %7, 0
br i1 %8, label %11, label %9
9: ; preds = %5
%10 = tail call i32 @fclose(i32* %3)
br label %36
11: ; preds = %5
%12 = tail call i64 @ftell(i32* %3)
%13 = icmp slt i64 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %11
%15 = tail call i32 @fclose(i32* %3)
br label %36
16: ; preds = %11
%17 = load i32, i32* @SEEK_SET
%18 = tail call i64 @fseek(i32* %3, i32 0, i32 %17)
%19 = icmp eq i64 %18, 0
br i1 %19, label %22, label %20
20: ; preds = %16
%21 = tail call i32 @fclose(i32* %3)
br label %36
22: ; preds = %16
%23 = add nuw nsw i64 %12, 1
%24 = tail call i8* @malloc(i64 %23)
%25 = icmp eq i8* %24, null
br i1 %25, label %26, label %28
26: ; preds = %22
%27 = tail call i32 @fclose(i32* %3)
br label %36
28: ; preds = %22
%29 = tail call i64 @fread(i8* %24, i32 1, i64 %12, i32* %3)
%30 = icmp eq i64 %29, %12
br i1 %30, label %33, label %31
31: ; preds = %28
%32 = tail call i32 @fclose(i32* %3)
br label %36
33: ; preds = %28
%34 = getelementptr inbounds i8, i8* %24, i64 %12
store i8 0, i8* %34
%35 = tail call i32 @fclose(i32* %3)
store i8* %24, i8** %0
br label %36
36: ; preds = %14, %20, %33, %31, %26, %2, %9
%37 = phi i32 [ 1, %9 ], [ 1, %2 ], [ 1, %14 ], [ 1, %20 ], [ 1, %31 ], [ 0, %33 ], [ 1, %26 ]
ret i32 %37
}