#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*/ create_lockfile(char const *);
int /*<<< orphan*/ db_file_exists(char const *);
int /*<<< orphan*/ decrypt_file(char const *, char const *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ stderr;
bool db_open(const char *path, const char *passphrase) {
  if (!db_file_exists(path)) {
    fprintf(stderr, "%s: does not exists\n", path);
    return false;
  }
  if (!decrypt_file(path, passphrase)) {
    fprintf(stderr, "Decryption failed\n");
    return false;
  }
  create_lockfile(path);
  return true;
}


x86 assembly (clang, -O0):
<db_open>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <db_file_exists@plt>
cmp    $0x0,%eax
jne    1189 <db_open+0x49>
mov    0x2e77(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe8a(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11d2 <db_open+0x92>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <decrypt_file@plt>
cmp    $0x0,%eax
jne    11c2 <db_open+0x82>
mov    0x2e3a(%rip),%rax
mov    (%rax),%edi
lea    0xe66(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11d2 <db_open+0x92>
mov    -0x10(%rbp),%rdi
call   1060 <create_lockfile@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<db_open>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbp
mov    %rdi,%rbx
call   1040 <db_file_exists@plt>
test   %eax,%eax
je     1170 <db_open+0x30>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1030 <decrypt_file@plt>
test   %eax,%eax
je     118e <db_open+0x4e>
mov    %rbx,%rdi
call   1060 <create_lockfile@plt>
mov    $0x1,%ebp
jmp    11a7 <db_open+0x67>
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
lea    0xe80(%rip),%rsi
xor    %ebp,%ebp
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    11a7 <db_open+0x67>
mov    0x2e4b(%rip),%rax
mov    (%rax),%edi
lea    0xe77(%rip),%rsi
xor    %ebp,%ebp
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [21 x i8] c"%s: does not exists\0A\00"
@.str.1 = [19 x i8] c"Decryption failed\0A\00"
define i32 @db_open(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%6 = load i8*, i8** %4
%7 = call i32 @db_file_exists(i8* %6)
%8 = icmp ne i32 %7, 0
br i1 %8, label %13, label %9
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = load i8*, i8** %4
%12 = call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %11)
store i32 0, i32* %3
br label %24
13: ; preds = %2
%14 = load i8*, i8** %4
%15 = load i8*, i8** %5
%16 = call i32 @decrypt_file(i8* %14, i8* %15)
%17 = icmp ne i32 %16, 0
br i1 %17, label %21, label %18
18: ; preds = %13
%19 = load i32, i32* @stderr
%20 = call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %3
br label %24
21: ; preds = %13
%22 = load i8*, i8** %4
%23 = call i32 @create_lockfile(i8* %22)
store i32 1, i32* %3
br label %24
24: ; preds = %21, %18, %9
%25 = load i32, i32* %3
ret i32 %25
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [21 x i8] c"%s: does not exists\0A\00"
@.str.1 = [19 x i8] c"Decryption failed\0A\00"
define i32 @db_open(i8* %0, i8* %1) {
%3 = tail call i32 @db_file_exists(i8* %0)
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = tail call i32 (i32, i8*, ...) @fprintf(i32 %6, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %16
8: ; preds = %2
%9 = tail call i32 @decrypt_file(i8* %0, i8* %1)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %8
%12 = load i32, i32* @stderr
%13 = tail call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
br label %16
14: ; preds = %8
%15 = tail call i32 @create_lockfile(i8* %0)
br label %16
16: ; preds = %14, %11, %5
%17 = phi i32 [ 1, %14 ], [ 0, %11 ], [ 0, %5 ]
ret i32 %17
}