#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 */

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ clear_all();
int /*<<< orphan*/ close(int);
int errno;
int open(char const *, int /*<<< orphan*/);
int read_database(int);
int smaunch_fs_has_database();
int smaunch_fs_load_database(const char *path) {
  int result, file;
  assert(path != NULL);
  clear_all();
  file = open(path, O_RDONLY);
  if (file < 0)
    return -errno;
  result = read_database(file);
  close(file);
  assert(result <= 0);
  assert(smaunch_fs_has_database() == !result);
  return result;
}


x86 assembly (clang, -O0):
<smaunch_fs_load_database>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    $0x0,%al
call   1030 <clear_all@plt>
mov    -0x10(%rbp),%rdi
mov    0x2e58(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    11b7 <smaunch_fs_load_database+0x57>
xor    %eax,%eax
mov    0x2e2b(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    1207 <smaunch_fs_load_database+0xa7>
mov    -0x18(%rbp),%edi
call   1070 <read_database@plt>
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%edi
call   1040 <close@plt>
cmpl   $0x0,-0x14(%rbp)
setle  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    $0x0,%al
call   1080 <smaunch_fs_has_database@plt>
cmpl   $0x0,-0x14(%rbp)
setne  %cl
xor    $0xff,%cl
and    $0x1,%cl
movzbl %cl,%ecx
cmp    %ecx,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<smaunch_fs_load_database>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbp
xor    %edi,%edi
test   %rbp,%rbp
setne  %dil
call   1050 <assert@plt>
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <clear_all@plt>
mov    0x2e64(%rip),%rax
mov    (%rax),%esi
mov    %rbp,%rdi
call   1060 <open@plt>
test   %eax,%eax
js     11cd <smaunch_fs_load_database+0x6d>
mov    %eax,%ebp
mov    %eax,%edi
call   1070 <read_database@plt>
mov    %eax,%ebx
mov    %ebp,%edi
call   1040 <close@plt>
xor    %edi,%edi
xor    %ebp,%ebp
test   %ebx,%ebx
setle  %dil
sete   %bpl
call   1050 <assert@plt>
xor    %eax,%eax
call   1080 <smaunch_fs_has_database@plt>
xor    %edi,%edi
cmp    %ebp,%eax
sete   %dil
call   1050 <assert@plt>
jmp    11d6 <smaunch_fs_load_database+0x76>
mov    0x2e04(%rip),%rax
sub    (%rax),%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@O_RDONLY = global i32 0
@errno = global i32 0
define i32 @smaunch_fs_load_database(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = icmp ne i8* %6, null
%8 = zext i1 %7 to i32
%9 = call i32 @assert(i32 %8)
%10 = call i32 (...) @clear_all()
%11 = load i8*, i8** %3
%12 = load i32, i32* @O_RDONLY
%13 = call i32 @open(i8* %11, i32 %12)
store i32 %13, i32* %5
%14 = load i32, i32* %5
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %1
%17 = load i32, i32* @errno
%18 = sub nsw i32 0, %17
store i32 %18, i32* %2
br label %37
19: ; preds = %1
%20 = load i32, i32* %5
%21 = call i32 @read_database(i32 %20)
store i32 %21, i32* %4
%22 = load i32, i32* %5
%23 = call i32 @close(i32 %22)
%24 = load i32, i32* %4
%25 = icmp sle i32 %24, 0
%26 = zext i1 %25 to i32
%27 = call i32 @assert(i32 %26)
%28 = call i32 (...) @smaunch_fs_has_database()
%29 = load i32, i32* %4
%30 = icmp ne i32 %29, 0
%31 = xor i1 %30, true
%32 = zext i1 %31 to i32
%33 = icmp eq i32 %28, %32
%34 = zext i1 %33 to i32
%35 = call i32 @assert(i32 %34)
%36 = load i32, i32* %4
store i32 %36, i32* %2
br label %37
37: ; preds = %19, %16
%38 = load i32, i32* %2
ret i32 %38
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@errno = global i32 0
define i32 @smaunch_fs_load_database(i8* %0) {
%2 = icmp ne i8* %0, null
%3 = zext i1 %2 to i32
%4 = tail call i32 @assert(i32 %3)
%5 = tail call i32 (...) @clear_all()
%6 = load i32, i32* @O_RDONLY
%7 = tail call i32 @open(i8* %0, i32 %6)
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %1
%10 = load i32, i32* @errno
%11 = sub nsw i32 0, %10
br label %24
12: ; preds = %1
%13 = tail call i32 @read_database(i32 %7)
%14 = tail call i32 @close(i32 %7)
%15 = icmp slt i32 %13, 1
%16 = zext i1 %15 to i32
%17 = tail call i32 @assert(i32 %16)
%18 = tail call i32 (...) @smaunch_fs_has_database()
%19 = icmp eq i32 %13, 0
%20 = zext i1 %19 to i32
%21 = icmp eq i32 %18, %20
%22 = zext i1 %21 to i32
%23 = tail call i32 @assert(i32 %22)
br label %24
24: ; preds = %12, %9
%25 = phi i32 [ %11, %9 ], [ %13, %12 ]
ret i32 %25
}