#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 */
scalar_t__ db_file_exists(char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ free(char *);
char *read_path_from_lockfile();
int /*<<< orphan*/ stderr;
bool open_db_exist(const char *message) {
  char *old = NULL;
  old = read_path_from_lockfile();
  if (old != NULL) {
    if (db_file_exists(old)) {
      fprintf(stderr, "An open database exists. To improve security only one\n"
                      "passphrase database can be open at once.\n");
      fprintf(stderr,
              "Close %s first before %s another"
              " database.\n",
              old, message);
      free(old);
      return true;
    }
    free(old);
  }
  return false;
}


x86 assembly (clang, -O0):
<open_db_exist>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    $0x0,%al
call   1060 <read_path_from_lockfile@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11d1 <open_db_exist+0x91>
mov    -0x18(%rbp),%rdi
call   1040 <db_file_exists@plt>
cmp    $0x0,%rax
je     11c8 <open_db_exist+0x88>
mov    0x2e5c(%rip),%rax
mov    (%rax),%edi
lea    0xe73(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2e45(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xeb4(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
jmp    11d8 <open_db_exist+0x98>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_db_exist>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
xor    %ebp,%ebp
xor    %eax,%eax
call   1060 <read_path_from_lockfile@plt>
test   %rax,%rax
je     11a5 <open_db_exist+0x65>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <db_file_exists@plt>
test   %rax,%rax
je     119b <open_db_exist+0x5b>
mov    0x2e74(%rip),%rbp
mov    0x0(%rbp),%edi
lea    0xe8a(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x0(%rbp),%edi
lea    0xed9(%rip),%rsi
mov    %rbx,%rdx
mov    %r14,%rcx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%ebp
jmp    119d <open_db_exist+0x5d>
xor    %ebp,%ebp
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [96 x i8] c"An open database exists. To improve security only one\0Apassphrase database can be open at once.\0A\00"
@.str.1 = [44 x i8] c"Close %s first before %s another database.\0A\00"
define i32 @open_db_exist(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
store i8* null, i8** %4
%5 = call i8* (...) @read_path_from_lockfile()
store i8* %5, i8** %4
%6 = load i8*, i8** %4
%7 = icmp ne i8* %6, null
br i1 %7, label %8, label %24
8: ; preds = %1
%9 = load i8*, i8** %4
%10 = call i64 @db_file_exists(i8* %9)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %21
12: ; preds = %8
%13 = load i32, i32* @stderr
%14 = call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([96 x i8], [96 x i8]* @.str, i64 0, i64 0))
%15 = load i32, i32* @stderr
%16 = load i8*, i8** %4
%17 = load i8*, i8** %3
%18 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), i8* %16, i8* %17)
%19 = load i8*, i8** %4
%20 = call i32 @free(i8* %19)
store i32 1, i32* %2
br label %25
21: ; preds = %8
%22 = load i8*, i8** %4
%23 = call i32 @free(i8* %22)
br label %24
24: ; preds = %21, %1
store i32 0, i32* %2
br label %25
25: ; preds = %24, %12
%26 = load i32, i32* %2
ret i32 %26
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [96 x i8] c"An open database exists. To improve security only one\0Apassphrase database can be open at once.\0A\00"
@.str.1 = [44 x i8] c"Close %s first before %s another database.\0A\00"
define i32 @open_db_exist(i8* %0) {
%2 = tail call i8* (...) @read_path_from_lockfile()
%3 = icmp eq i8* %2, null
br i1 %3, label %15, label %4
4: ; preds = %1
%5 = tail call i64 @db_file_exists(i8* %2)
%6 = icmp eq i64 %5, 0
br i1 %6, label %12, label %7
7: ; preds = %4
%8 = load i32, i32* @stderr
%9 = tail call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([96 x i8], [96 x i8]* @.str, i64 0, i64 0))
%10 = load i32, i32* @stderr
%11 = tail call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), i8* %2, i8* %0)
br label %12
12: ; preds = %4, %7
%13 = phi i32 [ 1, %7 ], [ 0, %4 ]
%14 = tail call i32 @free(i8* %2)
br label %15
15: ; preds = %12, %1
%16 = phi i32 [ 0, %1 ], [ %13, %12 ]
ret i32 %16
}