#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 */
typedef int time_t;

/* Variables and functions */
int db_close();
int db_data(char *);
int db_get(char *, char **);
int /*<<< orphan*/ db_kill(char *);
int db_open();
int /*<<< orphan*/ db_set(char *, char *);
int db_version(char **);
int /*<<< orphan*/ gtmdata_version(char **);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sprintf(char *, char *, long);
int time(int /*<<< orphan*/ *);
int main(int argc, char **argv) {
  int status;
  long i;
  char lib_version[((1024 * 1024) + 1)];
  char ret_get[((1024 * 1024) + 1)];
  char ret_ver[((1024 * 1024) + 1)];
  char set_sub[((1024 * 1024) + 1)];
  time_t start_time, end_time, elapsed;
  long nodes_per_second;
  (void)gtmdata_version(&lib_version);
  (void)printf("%s\n\n", lib_version);
  (void)printf("db_open():\n");
  status = db_open();
  (void)printf("db_get():\t");
  status = db_get("^TT(\"ACCT\",1000)", &ret_get);
  (void)printf("%s\n", ret_get);
  (void)printf("db_version():\t");
  status = db_version(&ret_ver);
  (void)printf("%s\n", ret_ver);
  (void)printf("db_set():\t1,000,000 nodes in ");
  start_time = time(NULL);
  for (i = 1; i < 1000000; i++) {
    (void)sprintf(set_sub, "^KBBMCITS(%d)", i);
    (void)db_set(set_sub, "test");
  }
  end_time = time(NULL);
  elapsed = end_time - start_time;
  nodes_per_second = 1000000 / elapsed;
  (void)printf("%d seconds (%d nodes/second)\n", elapsed, nodes_per_second);
  (void)printf("db_kill():\n");
  (void)db_kill("^KBBMCITS");
  (void)printf("db_data():\t");
  (void)db_set("^KBBMCITS", "a");
  (void)db_set("^KBBMCITS(1)", "b");
  (void)printf("^KBBMCITS = %d ^KBBMCITS(1) = %d\n", db_data("^KBBMCITS"),
               db_data("^KBBMCITS(1)"));
  (void)printf("db_close():\n");
  status = db_close();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x400080,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x100030(%rbp),%rdi
call   1090 <gtmdata_version@plt>
lea    -0x100030(%rbp),%rsi
lea    0xe1d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe14(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   10a0 <db_open@plt>
mov    %eax,-0x14(%rbp)
lea    0xe08(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x200040(%rbp),%rsi
lea    0xdfe(%rip),%rdi
call   1070 <db_get@plt>
mov    %eax,-0x14(%rbp)
lea    -0x200040(%rbp),%rsi
lea    0xdf9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xdef(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x300050(%rbp),%rdi
call   10d0 <db_version@plt>
mov    %eax,-0x14(%rbp)
lea    -0x300050(%rbp),%rsi
lea    0xdc7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xdcc(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1080 <time@plt>
mov    %eax,-0x400064(%rbp)
movq   $0x1,-0x20(%rbp)
cmpq   $0xf4240,-0x20(%rbp)
jge    12db <main+0x12b>
lea    -0x400060(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xdac(%rip),%rsi
call   10c0 <sprintf@plt>
lea    -0x400060(%rbp),%rdi
lea    0xda7(%rip),%rsi
call   1050 <db_set@plt>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1292 <main+0xe2>
xor    %eax,%eax
mov    %eax,%edi
call   1080 <time@plt>
mov    %eax,-0x400068(%rbp)
mov    -0x400068(%rbp),%eax
sub    -0x400064(%rbp),%eax
mov    %eax,-0x40006c(%rbp)
mov    $0xf4240,%eax
cltd
idivl  -0x40006c(%rbp)
cltq
mov    %rax,-0x400078(%rbp)
mov    -0x40006c(%rbp),%esi
mov    -0x400078(%rbp),%rdx
lea    0xd4c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xd5c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xd5a(%rip),%rdi
call   10b0 <db_kill@plt>
lea    0xd58(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xd40(%rip),%rdi
lea    0xd4f(%rip),%rsi
call   1050 <db_set@plt>
lea    0xd45(%rip),%rdi
lea    0xd4b(%rip),%rsi
call   1050 <db_set@plt>
lea    0xd1a(%rip),%rdi
call   1030 <db_data@plt>
mov    %eax,-0x40007c(%rbp)
lea    0xd20(%rip),%rdi
call   1030 <db_data@plt>
mov    -0x40007c(%rbp),%esi
mov    %eax,%edx
lea    0xd1b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xd2f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1060 <db_close@plt>
mov    %eax,-0x14(%rbp)
xor    %eax,%eax
add    $0x400080,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x400040,%rsp
lea    0x300030(%rsp),%rbx
mov    %rbx,%rdi
call   10a0 <gtmdata_version@plt>
lea    0xe1a(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xed1(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   10b0 <db_open@plt>
lea    0xdfb(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xdf8(%rip),%rdi
lea    0x200020(%rsp),%rbx
mov    %rbx,%rsi
call   1080 <db_get@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
lea    0xdea(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x100010(%rsp),%rbx
mov    %rbx,%rdi
call   10e0 <db_version@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
lea    0xdd3(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %edi,%edi
call   1090 <time@plt>
mov    %eax,%r14d
mov    $0x1,%ebx
lea    0xdd4(%rip),%r15
mov    %rsp,%rbp
lea    0xdd8(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbp,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   10d0 <sprintf@plt>
mov    %rbp,%rdi
mov    %r12,%rsi
call   1060 <db_set@plt>
add    $0x1,%rbx
cmp    $0xf4240,%rbx
jne    1290 <main+0xd0>
xor    %edi,%edi
call   1090 <time@plt>
mov    %eax,%esi
sub    %r14d,%esi
mov    $0xf4240,%eax
xor    %edx,%edx
idiv   %esi
movslq %eax,%rdx
lea    0xd8c(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xdf0(%rip),%rdi
call   1030 <puts@plt>
lea    0xd90(%rip),%rbx
mov    %rbx,%rdi
call   10c0 <db_kill@plt>
lea    0xd8b(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xd89(%rip),%rsi
mov    %rbx,%rdi
call   1060 <db_set@plt>
lea    0xd7c(%rip),%rbp
lea    0xd82(%rip),%rsi
mov    %rbp,%rdi
call   1060 <db_set@plt>
mov    %rbx,%rdi
call   1040 <db_data@plt>
mov    %eax,%ebx
mov    %rbp,%rdi
call   1040 <db_data@plt>
lea    0xd63(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xd89(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1070 <db_close@plt>
xor    %eax,%eax
add    $0x400040,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%s\0A\0A\00"
@.str.1 = [12 x i8] c"db_open():\0A\00"
@.str.2 = [11 x i8] c"db_get():\09\00"
@.str.3 = [17 x i8] c"^TT(\22ACCT\22,1000)\00"
@.str.4 = [4 x i8] c"%s\0A\00"
@.str.5 = [15 x i8] c"db_version():\09\00"
@.str.6 = [30 x i8] c"db_set():\091,000,000 nodes in \00"
@.str.7 = [14 x i8] c"^KBBMCITS(%d)\00"
@.str.8 = [5 x i8] c"test\00"
@.str.9 = [30 x i8] c"%d seconds (%d nodes/second)\0A\00"
@.str.10 = [12 x i8] c"db_kill():\0A\00"
@.str.11 = [10 x i8] c"^KBBMCITS\00"
@.str.12 = [12 x i8] c"db_data():\09\00"
@.str.13 = [2 x i8] c"a\00"
@.str.14 = [13 x i8] c"^KBBMCITS(1)\00"
@.str.15 = [2 x i8] c"b\00"
@.str.16 = [34 x i8] c"^KBBMCITS = %d ^KBBMCITS(1) = %d\0A\00"
@.str.17 = [13 x i8] c"db_close():\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i64
%8 = alloca [1048577 x i8]
%9 = alloca [1048577 x i8]
%10 = alloca [1048577 x i8]
%11 = alloca [1048577 x i8]
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%16 = bitcast [1048577 x i8]* %8 to i8**
%17 = call i32 @gtmdata_version(i8** %16)
%18 = getelementptr inbounds [1048577 x i8], [1048577 x i8]* %8, i64 0, i64 0
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %18)
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%21 = call i32 (...) @db_open()
store i32 %21, i32* %6
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%23 = bitcast [1048577 x i8]* %9 to i8**
%24 = call i32 @db_get(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i8** %23)
store i32 %24, i32* %6
%25 = getelementptr inbounds [1048577 x i8], [1048577 x i8]* %9, i64 0, i64 0
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %25)
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
%28 = bitcast [1048577 x i8]* %10 to i8**
%29 = call i32 @db_version(i8** %28)
store i32 %29, i32* %6
%30 = getelementptr inbounds [1048577 x i8], [1048577 x i8]* %10, i64 0, i64 0
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %30)
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.6, i64 0, i64 0))
%33 = call i32 @time(i32* null)
store i32 %33, i32* %12
store i64 1, i64* %7
br label %34
34: ; preds = %43, %2
%35 = load i64, i64* %7
%36 = icmp slt i64 %35, 1000000
br i1 %36, label %37, label %46
37: ; preds = %34
%38 = getelementptr inbounds [1048577 x i8], [1048577 x i8]* %11, i64 0, i64 0
%39 = load i64, i64* %7
%40 = call i32 @sprintf(i8* %38, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0), i64 %39)
%41 = getelementptr inbounds [1048577 x i8], [1048577 x i8]* %11, i64 0, i64 0
%42 = call i32 @db_set(i8* %41, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
br label %43
43: ; preds = %37
%44 = load i64, i64* %7
%45 = add nsw i64 %44, 1
store i64 %45, i64* %7
br label %34
46: ; preds = %34
%47 = call i32 @time(i32* null)
store i32 %47, i32* %13
%48 = load i32, i32* %13
%49 = load i32, i32* %12
%50 = sub nsw i32 %48, %49
store i32 %50, i32* %14
%51 = load i32, i32* %14
%52 = sdiv i32 1000000, %51
%53 = sext i32 %52 to i64
store i64 %53, i64* %15
%54 = load i32, i32* %14
%55 = load i64, i64* %15
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.9, i64 0, i64 0), i32 %54, i64 %55)
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.10, i64 0, i64 0))
%58 = call i32 @db_kill(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.11, i64 0, i64 0))
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.12, i64 0, i64 0))
%60 = call i32 @db_set(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.13, i64 0, i64 0))
%61 = call i32 @db_set(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.14, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.15, i64 0, i64 0))
%62 = call i32 @db_data(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.11, i64 0, i64 0))
%63 = call i32 @db_data(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.14, i64 0, i64 0))
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.16, i64 0, i64 0), i32 %62, i32 %63)
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.17, i64 0, i64 0))
%66 = call i32 (...) @db_close()
store i32 %66, i32* %6
ret i32 0
}

LLVM IR (-O2):
@.str = [5 x i8] c"%s\0A\0A\00"
@.str.2 = [11 x i8] c"db_get():\09\00"
@.str.3 = [17 x i8] c"^TT(\22ACCT\22,1000)\00"
@.str.5 = [15 x i8] c"db_version():\09\00"
@.str.6 = [30 x i8] c"db_set():\091,000,000 nodes in \00"
@.str.7 = [14 x i8] c"^KBBMCITS(%d)\00"
@.str.8 = [5 x i8] c"test\00"
@.str.9 = [30 x i8] c"%d seconds (%d nodes/second)\0A\00"
@.str.11 = [10 x i8] c"^KBBMCITS\00"
@.str.12 = [12 x i8] c"db_data():\09\00"
@.str.13 = [2 x i8] c"a\00"
@.str.14 = [13 x i8] c"^KBBMCITS(1)\00"
@.str.15 = [2 x i8] c"b\00"
@.str.16 = [34 x i8] c"^KBBMCITS = %d ^KBBMCITS(1) = %d\0A\00"
@str = [11 x i8] c"db_open():\00"
@str.18 = [11 x i8] c"db_kill():\00"
@str.19 = [12 x i8] c"db_close():\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [1048577 x i8]
%4 = alloca [1048577 x i8]
%5 = alloca [1048577 x i8]
%6 = alloca [1048577 x i8]
%7 = getelementptr inbounds [1048577 x i8], [1048577 x i8]* %3, i64 0, i64 0
%8 = getelementptr inbounds [1048577 x i8], [1048577 x i8]* %4, i64 0, i64 0
%9 = getelementptr inbounds [1048577 x i8], [1048577 x i8]* %5, i64 0, i64 0
%10 = getelementptr inbounds [1048577 x i8], [1048577 x i8]* %6, i64 0, i64 0
%11 = bitcast [1048577 x i8]* %3 to i8**
%12 = call i32 @gtmdata_version(i8** %11)
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %7)
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str, i64 0, i64 0))
%15 = call i32 (...) @db_open()
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%17 = bitcast [1048577 x i8]* %4 to i8**
%18 = call i32 @db_get(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i8** %17)
%19 = call i32 @puts(i8* %8)
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
%21 = bitcast [1048577 x i8]* %5 to i8**
%22 = call i32 @db_version(i8** %21)
%23 = call i32 @puts(i8* %9)
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.6, i64 0, i64 0))
%25 = call i32 @time(i32* null)
br label %26
26: ; preds = %2, %26
%27 = phi i64 [ 1, %2 ], [ %30, %26 ]
%28 = call i32 @sprintf(i8* %10, i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0), i64 %27)
%29 = call i32 @db_set(i8* %10, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
%30 = add nuw nsw i64 %27, 1
%31 = icmp eq i64 %30, 1000000
br i1 %31, label %32, label %26
32: ; preds = %26
%33 = call i32 @time(i32* null)
%34 = sub nsw i32 %33, %25
%35 = sdiv i32 1000000, %34
%36 = sext i32 %35 to i64
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.9, i64 0, i64 0), i32 %34, i64 %36)
%38 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.18, i64 0, i64 0))
%39 = call i32 @db_kill(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.11, i64 0, i64 0))
%40 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.12, i64 0, i64 0))
%41 = call i32 @db_set(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.13, i64 0, i64 0))
%42 = call i32 @db_set(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.14, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.15, i64 0, i64 0))
%43 = call i32 @db_data(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.11, i64 0, i64 0))
%44 = call i32 @db_data(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.14, i64 0, i64 0))
%45 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.16, i64 0, i64 0), i32 %43, i32 %44)
%46 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.19, i64 0, i64 0))
%47 = call i32 (...) @db_close()
ret i32 0
}