#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 */
struct btree {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ btree_creat(struct btree *, char *, char *);
int /*<<< orphan*/ btree_open(struct btree *, char *, char *);
scalar_t__ file_exists(char *);
int /*<<< orphan*/ sprintf(char *, char *, char const *, char *);
int btree_init(struct btree *btree, const char *dbname, int isbgsync) {
  char idx[256] = {0};
  char db[256] = {0};
  sprintf(idx, "%s%s", dbname, ".idx");
  sprintf(db, "%s%s", dbname, ".db");
  if (file_exists(idx))
    btree_open(btree, idx, db);
  else
    btree_creat(btree, idx, db);
}


x86 assembly (clang, -O0):
<btree_init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
lea    -0x120(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1050 <memset@plt>
lea    -0x220(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1050 <memset@plt>
lea    -0x120(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe62(%rip),%rsi
lea    0xe60(%rip),%rcx
call   1060 <sprintf@plt>
lea    -0x220(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe44(%rip),%rsi
lea    0xe47(%rip),%rcx
call   1060 <sprintf@plt>
lea    -0x120(%rbp),%rdi
call   1030 <file_exists@plt>
cmp    $0x0,%rax
je     11fa <btree_init+0xaa>
mov    -0x10(%rbp),%rdi
lea    -0x120(%rbp),%rsi
lea    -0x220(%rbp),%rdx
call   1070 <btree_open@plt>
jmp    1211 <btree_init+0xc1>
mov    -0x10(%rbp),%rdi
lea    -0x120(%rbp),%rsi
lea    -0x220(%rbp),%rdx
call   1040 <btree_creat@plt>
mov    -0x4(%rbp),%eax
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<btree_init>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x208,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
xorps  %xmm0,%xmm0
movaps %xmm0,0x1f0(%rsp)
movaps %xmm0,0x1e0(%rsp)
movaps %xmm0,0x1d0(%rsp)
movaps %xmm0,0x1c0(%rsp)
movaps %xmm0,0x1b0(%rsp)
movaps %xmm0,0x1a0(%rsp)
movaps %xmm0,0x190(%rsp)
movaps %xmm0,0x180(%rsp)
movaps %xmm0,0x170(%rsp)
movaps %xmm0,0x160(%rsp)
movaps %xmm0,0x150(%rsp)
movaps %xmm0,0x140(%rsp)
movaps %xmm0,0x130(%rsp)
movaps %xmm0,0x120(%rsp)
movaps %xmm0,0x110(%rsp)
movaps %xmm0,0x100(%rsp)
movaps %xmm0,0xf0(%rsp)
movaps %xmm0,0xe0(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
lea    0xdbb(%rip),%r15
lea    0xdb9(%rip),%rcx
lea    0x100(%rsp),%r12
mov    %r12,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1050 <sprintf@plt>
lea    0xda1(%rip),%rcx
mov    %rsp,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1050 <sprintf@plt>
mov    %r12,%rdi
call   1030 <file_exists@plt>
lea    0x100(%rsp),%rsi
mov    %rsp,%rdx
mov    %r14,%rdi
test   %rax,%rax
je     1299 <btree_init+0x159>
call   1060 <btree_open@plt>
jmp    129e <btree_init+0x15e>
call   1040 <btree_creat@plt>
add    $0x208,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.btree = type { i32 }
@.str = [5 x i8] c"%s%s\00"
@.str.1 = [5 x i8] c".idx\00"
@.str.2 = [4 x i8] c".db\00"
define i32 @btree_init(%struct.btree* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca %struct.btree*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca [256 x i8]
%9 = alloca [256 x i8]
store %struct.btree* %0, %struct.btree** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%10 = bitcast [256 x i8]* %8 to i8*
%11 = bitcast [256 x i8]* %9 to i8*
%12 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%13 = load i8*, i8** %6
%14 = call i32 @sprintf(i8* %12, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %13, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%15 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%16 = load i8*, i8** %6
%17 = call i32 @sprintf(i8* %15, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %16, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%18 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%19 = call i64 @file_exists(i8* %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %26
21: ; preds = %3
%22 = load %struct.btree*, %struct.btree** %5
%23 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%24 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%25 = call i32 @btree_open(%struct.btree* %22, i8* %23, i8* %24)
br label %31
26: ; preds = %3
%27 = load %struct.btree*, %struct.btree** %5
%28 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%29 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%30 = call i32 @btree_creat(%struct.btree* %27, i8* %28, i8* %29)
br label %31
31: ; preds = %26, %21
%32 = load i32, i32* %4
ret i32 %32
}

LLVM IR (-O2):
%struct.btree = type { i32 }
@.str = [5 x i8] c"%s%s\00"
@.str.1 = [5 x i8] c".idx\00"
@.str.2 = [4 x i8] c".db\00"
define i32 @btree_init(%struct.btree* %0, i8* %1, i32 %2) {
%4 = alloca [256 x i8]
%5 = alloca [256 x i8]
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%8 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%9 = call i32 @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%10 = call i64 @file_exists(i8* %6)
%11 = icmp eq i64 %10, 0
br i1 %11, label %14, label %12
12: ; preds = %3
%13 = call i32 @btree_open(%struct.btree* %0, i8* %6, i8* %7)
br label %16
14: ; preds = %3
%15 = call i32 @btree_creat(%struct.btree* %0, i8* %6, i8* %7)
br label %16
16: ; preds = %14, %12
ret i32 undef
}