#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 *fname) {
  char dbname[1024], idxname[1024];
  sprintf(idxname, "%s%s", fname, ".idx");
  sprintf(dbname, "%s%s", fname, ".db");
  if (file_exists(idxname))
    btree_open(btree, idxname, dbname);
  else
    btree_creat(btree, idxname, dbname);
}


x86 assembly (clang, -O0):
<btree_init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x820,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    -0x820(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe9b(%rip),%rsi
lea    0xe99(%rip),%rcx
call   1050 <sprintf@plt>
lea    -0x420(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe7d(%rip),%rsi
lea    0xe80(%rip),%rcx
call   1050 <sprintf@plt>
lea    -0x820(%rbp),%rdi
call   1030 <file_exists@plt>
cmp    $0x0,%rax
je     11c1 <btree_init+0x81>
mov    -0x10(%rbp),%rdi
lea    -0x820(%rbp),%rsi
lea    -0x420(%rbp),%rdx
call   1060 <btree_open@plt>
jmp    11d8 <btree_init+0x98>
mov    -0x10(%rbp),%rdi
lea    -0x820(%rbp),%rsi
lea    -0x420(%rbp),%rdx
call   1040 <btree_creat@plt>
mov    -0x4(%rbp),%eax
add    $0x820,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<btree_init>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x808,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0xea5(%rip),%r15
lea    0xea3(%rip),%rcx
mov    %rsp,%r12
mov    %r12,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1050 <sprintf@plt>
lea    0xe90(%rip),%rcx
lea    0x400(%rsp),%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1050 <sprintf@plt>
mov    %r12,%rdi
call   1030 <file_exists@plt>
mov    %rsp,%rsi
lea    0x400(%rsp),%rdx
mov    %r14,%rdi
test   %rax,%rax
je     11af <btree_init+0x6f>
call   1060 <btree_open@plt>
jmp    11b4 <btree_init+0x74>
call   1040 <btree_creat@plt>
add    $0x808,%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) {
%3 = alloca i32
%4 = alloca %struct.btree*
%5 = alloca i8*
%6 = alloca [1024 x i8]
%7 = alloca [1024 x i8]
store %struct.btree* %0, %struct.btree** %4
store i8* %1, i8** %5
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%9 = load i8*, i8** %5
%10 = call i32 @sprintf(i8* %8, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %9, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%12 = load i8*, i8** %5
%13 = call i32 @sprintf(i8* %11, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %12, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%15 = call i64 @file_exists(i8* %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %22
17: ; preds = %2
%18 = load %struct.btree*, %struct.btree** %4
%19 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%20 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%21 = call i32 @btree_open(%struct.btree* %18, i8* %19, i8* %20)
br label %27
22: ; preds = %2
%23 = load %struct.btree*, %struct.btree** %4
%24 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%25 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%26 = call i32 @btree_creat(%struct.btree* %23, i8* %24, i8* %25)
br label %27
27: ; preds = %22, %17
%28 = load i32, i32* %3
ret i32 %28
}

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) {
%3 = alloca [1024 x i8]
%4 = alloca [1024 x i8]
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%7 = 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))
%8 = call i32 @sprintf(i8* %5, 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))
%9 = call i64 @file_exists(i8* %6)
%10 = icmp eq i64 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %2
%12 = call i32 @btree_open(%struct.btree* %0, i8* %6, i8* %5)
br label %15
13: ; preds = %2
%14 = call i32 @btree_creat(%struct.btree* %0, i8* %6, i8* %5)
br label %15
15: ; preds = %13, %11
ret i32 undef
}