#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*/ db_file_exists(char *);
int /*<<< orphan*/ db_remove_lockfile();
int /*<<< orphan*/ encrypt_file(char *, char const *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ free(char *);
char *read_path_from_lockfile();
int /*<<< orphan*/ stderr;
void db_close(const char *passphrase) {
  char *path = NULL;
  path = read_path_from_lockfile();
  if (path == NULL) {
    fprintf(stderr, "Failed to read the database path.\n");
    return;
  }
  if (!db_file_exists(path)) {
    fprintf(stderr, "%s: does not exists\n", path);
    free(path);
    return;
  }
  if (!encrypt_file(path, passphrase)) {
    fprintf(stderr, "Encryption failed\n");
    free(path);
    return;
  }
  db_remove_lockfile();
  free(path);
}


x86 assembly (clang, -O0):
<db_close>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    $0x0,%al
call   1080 <read_path_from_lockfile@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11a6 <db_close+0x46>
mov    0x2e4f(%rip),%rax
mov    (%rax),%edi
lea    0xe66(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    122c <db_close+0xcc>
mov    -0x10(%rbp),%rdi
call   1040 <db_file_exists@plt>
cmp    $0x0,%eax
jne    11e1 <db_close+0x81>
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe57(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
jmp    122c <db_close+0xcc>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1070 <encrypt_file@plt>
cmp    $0x0,%eax
jne    121c <db_close+0xbc>
mov    0x2de2(%rip),%rax
mov    (%rax),%edi
lea    0xe31(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
jmp    122c <db_close+0xcc>
mov    $0x0,%al
call   1050 <db_remove_lockfile@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<db_close>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %eax,%eax
call   1080 <read_path_from_lockfile@plt>
test   %rax,%rax
je     119a <db_close+0x3a>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <db_file_exists@plt>
test   %eax,%eax
je     11b8 <db_close+0x58>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1070 <encrypt_file@plt>
test   %eax,%eax
je     11d4 <db_close+0x74>
xor    %eax,%eax
call   1050 <db_remove_lockfile@plt>
jmp    11eb <db_close+0x8b>
mov    0x2e3f(%rip),%rax
mov    (%rax),%edi
lea    0xe56(%rip),%rsi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1060 <fprintf@plt>
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
lea    0xe5b(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    11eb <db_close+0x8b>
mov    0x2e05(%rip),%rax
mov    (%rax),%edi
lea    0xe54(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <free@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [35 x i8] c"Failed to read the database path.\0A\00"
@.str.1 = [21 x i8] c"%s: does not exists\0A\00"
@.str.2 = [19 x i8] c"Encryption failed\0A\00"
define void @db_close(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
store i8* %0, i8** %2
store i8* null, i8** %3
%4 = call i8* (...) @read_path_from_lockfile()
store i8* %4, i8** %3
%5 = load i8*, i8** %3
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %10
7: ; preds = %1
%8 = load i32, i32* @stderr
%9 = call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
br label %34
10: ; preds = %1
%11 = load i8*, i8** %3
%12 = call i32 @db_file_exists(i8* %11)
%13 = icmp ne i32 %12, 0
br i1 %13, label %20, label %14
14: ; preds = %10
%15 = load i32, i32* @stderr
%16 = load i8*, i8** %3
%17 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %16)
%18 = load i8*, i8** %3
%19 = call i32 @free(i8* %18)
br label %34
20: ; preds = %10
%21 = load i8*, i8** %3
%22 = load i8*, i8** %2
%23 = call i32 @encrypt_file(i8* %21, i8* %22)
%24 = icmp ne i32 %23, 0
br i1 %24, label %30, label %25
25: ; preds = %20
%26 = load i32, i32* @stderr
%27 = call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%28 = load i8*, i8** %3
%29 = call i32 @free(i8* %28)
br label %34
30: ; preds = %20
%31 = call i32 (...) @db_remove_lockfile()
%32 = load i8*, i8** %3
%33 = call i32 @free(i8* %32)
br label %34
34: ; preds = %30, %25, %14, %7
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [35 x i8] c"Failed to read the database path.\0A\00"
@.str.1 = [21 x i8] c"%s: does not exists\0A\00"
@.str.2 = [19 x i8] c"Encryption failed\0A\00"
define void @db_close(i8* %0) {
%2 = tail call i8* (...) @read_path_from_lockfile()
%3 = icmp eq i8* %2, null
br i1 %3, label %4, label %7
4: ; preds = %1
%5 = load i32, i32* @stderr
%6 = tail call i32 (i32, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
br label %24
7: ; preds = %1
%8 = tail call i32 @db_file_exists(i8* %2)
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %7
%11 = load i32, i32* @stderr
%12 = tail call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %2)
%13 = tail call i32 @free(i8* %2)
br label %24
14: ; preds = %7
%15 = tail call i32 @encrypt_file(i8* %2, i8* %0)
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %14
%18 = load i32, i32* @stderr
%19 = tail call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%20 = tail call i32 @free(i8* %2)
br label %24
21: ; preds = %14
%22 = tail call i32 (...) @db_remove_lockfile()
%23 = tail call i32 @free(i8* %2)
br label %24
24: ; preds = %21, %17, %10, %4
ret void
}