#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 /*<<< orphan*/ sqlite3_stmt;
typedef int /*<<< orphan*/ sqlite3;

/* Variables and functions */
int PATH_MAX;
#define SQLITE_BUSY 130
int SQLITE_DONE;
#define SQLITE_ERROR 129
int SQLITE_OK;
#define SQLITE_ROW 128
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, char *);
int sqlite3_column_int(int /*<<< orphan*/ *, int /*<<< orphan*/);
char *sqlite3_errmsg(int /*<<< orphan*/ *);
int /*<<< orphan*/ sqlite3_finalize(int /*<<< orphan*/ *);
int sqlite3_prepare(int /*<<< orphan*/ *, char *, int, int /*<<< orphan*/ **,
                    int /*<<< orphan*/);
int sqlite3_step(int /*<<< orphan*/ *);
int sqlite_sanatize(char const *, char *);
int /*<<< orphan*/ stderr;
int sqlite_get_size(sqlite3 *database, const char *child) {
  int rc, retval;
  char cmd[50 + 2 * PATH_MAX];
  sqlite3_stmt *stmt;
  char *child_s = malloc(2 * PATH_MAX * sizeof(char));
  rc = sqlite_sanatize(child, child_s);
  snprintf(cmd, 50 + 2 * PATH_MAX, "SELECT Size FROM %s WHERE Child='%s'",
           "MAP", child_s);
  rc = sqlite3_prepare(database, cmd, (50 + 2 * PATH_MAX) * sizeof(char), &stmt,
                       0);
  if (rc != SQLITE_OK) {
    fprintf(stderr, "sql error #%d: %s\n", rc, sqlite3_errmsg(database));
  } else {
    while ((rc = sqlite3_step(stmt)) != SQLITE_DONE) {
      switch (rc) {
      case SQLITE_BUSY:
        fprintf(stderr, "busy, wait 1 seconds\n");
        sleep(1);
        break;
      case SQLITE_ERROR:
        fprintf(stderr, "step error: %s\n", sqlite3_errmsg(database));
        break;
      case SQLITE_ROW:
        retval = sqlite3_column_int(stmt, 0);
        break;
      }
    }
  }
  sqlite3_finalize(stmt);
  free(child_s);
  return retval;
}


x86 assembly (clang, -O0):
<sqlite_get_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e29(%rip),%rax
mov    (%rax),%ecx
mov    %ecx,%eax
lea    0x32(%rax,%rax,1),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
mov    0x2df7(%rip),%rax
mov    (%rax),%eax
shl    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1090 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   10a0 <sqlite_sanatize@plt>
mov    -0x40(%rbp),%rdi
mov    %eax,-0x14(%rbp)
mov    0x2dc6(%rip),%rax
mov    (%rax),%esi
shl    $0x1,%esi
add    $0x32,%esi
mov    -0x38(%rbp),%r8
lea    0xdc3(%rip),%rdx
lea    0xde1(%rip),%rcx
call   1040 <snprintf@plt>
mov    -0x40(%rbp),%rsi
mov    -0x8(%rbp),%rdi
mov    0x2d98(%rip),%rax
mov    (%rax),%eax
shl    $0x1,%eax
add    $0x32,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edx
lea    -0x30(%rbp),%rcx
xor    %r8d,%r8d
call   10b0 <sqlite3_prepare@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    0x2d5f(%rip),%rcx
cmp    (%rcx),%eax
je     12c0 <sqlite_get_size+0x110>
mov    0x2d40(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x48(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <sqlite3_errmsg@plt>
mov    -0x48(%rbp),%edi
mov    -0x44(%rbp),%edx
mov    %rax,%rcx
lea    0xd75(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
jmp    1388 <sqlite_get_size+0x1d8>
jmp    12c5 <sqlite_get_size+0x115>
mov    -0x30(%rbp),%rdi
call   1070 <sqlite3_step@plt>
mov    %eax,-0x14(%rbp)
mov    0x2cf0(%rip),%rcx
cmp    (%rcx),%eax
je     1383 <sqlite_get_size+0x1d3>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4c(%rbp)
sub    $0x80,%eax
je     1370 <sqlite_get_size+0x1c0>
jmp    12f6 <sqlite_get_size+0x146>
mov    -0x4c(%rbp),%eax
sub    $0x81,%eax
je     1342 <sqlite_get_size+0x192>
jmp    1309 <sqlite_get_size+0x159>
mov    -0x4c(%rbp),%eax
sub    $0x82,%eax
jne    137e <sqlite_get_size+0x1ce>
jmp    131c <sqlite_get_size+0x16c>
mov    0x2cad(%rip),%rax
mov    (%rax),%edi
lea    0xd10(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <sleep@plt>
jmp    137e <sqlite_get_size+0x1ce>
mov    0x2c87(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x50(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <sqlite3_errmsg@plt>
mov    -0x50(%rbp),%edi
mov    %rax,%rdx
lea    0xcee(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
jmp    137e <sqlite_get_size+0x1ce>
mov    -0x30(%rbp),%rdi
xor    %esi,%esi
call   1050 <sqlite3_column_int@plt>
mov    %eax,-0x18(%rbp)
jmp    12c5 <sqlite_get_size+0x115>
jmp    1388 <sqlite_get_size+0x1d8>
mov    -0x30(%rbp),%rdi
call   10c0 <sqlite3_finalize@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%eax
mov    -0x20(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sqlite_get_size>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r12
mov    %rdi,%r15
mov    0x2e22(%rip),%r13
mov    0x0(%r13),%eax
lea    (%rax,%rax,1),%ecx
add    $0x32,%ecx
mov    %eax,%edi
add    %eax,%edi
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rbx
sub    %rcx,%rbx
mov    %rbx,%rsp
call   1090 <malloc@plt>
mov    %rax,%r14
mov    %r12,%rdi
mov    %rax,%rsi
call   10a0 <sqlite_sanatize@plt>
mov    0x0(%r13),%eax
lea    (%rax,%rax,1),%esi
add    $0x32,%esi
lea    0xdef(%rip),%rdx
lea    0xe0d(%rip),%rcx
mov    %rbx,%rdi
mov    %r14,%r8
call   1040 <snprintf@plt>
mov    0x0(%r13),%eax
lea    (%rax,%rax,1),%edx
add    $0x32,%edx
lea    -0x30(%rbp),%rcx
mov    %r15,%rdi
mov    %rbx,%rsi
xor    %r8d,%r8d
call   10b0 <sqlite3_prepare@plt>
mov    %eax,%ebx
mov    0x2d98(%rip),%rax
cmp    (%rax),%ebx
mov    %r14,-0x38(%rbp)
jne    12f0 <sqlite_get_size+0x140>
mov    -0x30(%rbp),%rdi
call   1070 <sqlite3_step@plt>
mov    0x2d64(%rip),%r12
cmp    (%r12),%eax
je     1318 <sqlite_get_size+0x168>
mov    0x2d5b(%rip),%rbx
jmp    12ae <sqlite_get_size+0xfe>
nopw   0x0(%rax,%rax,1)
mov    (%rbx),%r13d
mov    %r15,%rdi
call   1060 <sqlite3_errmsg@plt>
mov    %r13d,%edi
lea    0xdbd(%rip),%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    -0x30(%rbp),%rdi
call   1070 <sqlite3_step@plt>
cmp    (%r12),%eax
je     1318 <sqlite_get_size+0x168>
cmp    $0x80,%eax
je     12e0 <sqlite_get_size+0x130>
cmp    $0x81,%eax
je     1280 <sqlite_get_size+0xd0>
cmp    $0x82,%eax
jne    129f <sqlite_get_size+0xef>
mov    (%rbx),%edi
lea    0xd70(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <sleep@plt>
jmp    129f <sqlite_get_size+0xef>
nop
mov    -0x30(%rbp),%rdi
xor    %esi,%esi
call   1050 <sqlite3_column_int@plt>
mov    %eax,%r14d
jmp    129f <sqlite_get_size+0xef>
mov    0x2cd9(%rip),%rax
mov    (%rax),%r12d
mov    %r15,%rdi
call   1060 <sqlite3_errmsg@plt>
lea    0xd20(%rip),%rsi
mov    %r12d,%edi
mov    %ebx,%edx
mov    %rax,%rcx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    -0x30(%rbp),%rdi
call   10c0 <sqlite3_finalize@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    %r14d,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@PATH_MAX = global i32 0
@.str = [37 x i8] c"SELECT Size FROM %s WHERE Child='%s'\00"
@.str.1 = [4 x i8] c"MAP\00"
@SQLITE_OK = global i32 0
@stderr = global i32 0
@.str.2 = [19 x i8] c"sql error #%d: %s\0A\00"
@SQLITE_DONE = global i32 0
@.str.3 = [22 x i8] c"busy, wait 1 seconds\0A\00"
@.str.4 = [16 x i8] c"step error: %s\0A\00"
define i32 @sqlite_get_size(i32* %0, i8* %1) {
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32*
%10 = alloca i8*
store i32* %0, i32** %3
store i8* %1, i8** %4
%11 = load i32, i32* @PATH_MAX
%12 = mul nsw i32 2, %11
%13 = add nsw i32 50, %12
%14 = zext i32 %13 to i64
%15 = call i8* @llvm.stacksave()
store i8* %15, i8** %7
%16 = alloca i8, i64 %14
store i64 %14, i64* %8
%17 = load i32, i32* @PATH_MAX
%18 = mul nsw i32 2, %17
%19 = sext i32 %18 to i64
%20 = mul i64 %19, 1
%21 = trunc i64 %20 to i32
%22 = call i8* @malloc(i32 %21)
store i8* %22, i8** %10
%23 = load i8*, i8** %4
%24 = load i8*, i8** %10
%25 = call i32 @sqlite_sanatize(i8* %23, i8* %24)
store i32 %25, i32* %5
%26 = load i32, i32* @PATH_MAX
%27 = mul nsw i32 2, %26
%28 = add nsw i32 50, %27
%29 = load i8*, i8** %10
%30 = call i32 @snprintf(i8* %16, i32 %28, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %29)
%31 = load i32*, i32** %3
%32 = load i32, i32* @PATH_MAX
%33 = mul nsw i32 2, %32
%34 = add nsw i32 50, %33
%35 = sext i32 %34 to i64
%36 = mul i64 %35, 1
%37 = trunc i64 %36 to i32
%38 = call i32 @sqlite3_prepare(i32* %31, i8* %16, i32 %37, i32** %9, i32 0)
store i32 %38, i32* %5
%39 = load i32, i32* %5
%40 = load i32, i32* @SQLITE_OK
%41 = icmp ne i32 %39, %40
br i1 %41, label %42, label %48
42: ; preds = %2
%43 = load i32, i32* @stderr
%44 = load i32, i32* %5
%45 = load i32*, i32** %3
%46 = call i8* @sqlite3_errmsg(i32* %45)
%47 = call i32 (i32, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %44, i8* %46)
br label %70
48: ; preds = %2
br label %49
49: ; preds = %68, %48
%50 = load i32*, i32** %9
%51 = call i32 @sqlite3_step(i32* %50)
store i32 %51, i32* %5
%52 = load i32, i32* @SQLITE_DONE
%53 = icmp ne i32 %51, %52
br i1 %53, label %54, label %69
54: ; preds = %49
%55 = load i32, i32* %5
switch i32 %55, label %68 [
i32 130, label %56
i32 129, label %60
i32 128, label %65
]
56: ; preds = %54
%57 = load i32, i32* @stderr
%58 = call i32 (i32, i8*, ...) @fprintf(i32 %57, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
%59 = call i32 @sleep(i32 1)
br label %68
60: ; preds = %54
%61 = load i32, i32* @stderr
%62 = load i32*, i32** %3
%63 = call i8* @sqlite3_errmsg(i32* %62)
%64 = call i32 (i32, i8*, ...) @fprintf(i32 %61, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i8* %63)
br label %68
65: ; preds = %54
%66 = load i32*, i32** %9
%67 = call i32 @sqlite3_column_int(i32* %66, i32 0)
store i32 %67, i32* %6
br label %68
68: ; preds = %54, %65, %60, %56
br label %49
69: ; preds = %49
br label %70
70: ; preds = %69, %42
%71 = load i32*, i32** %9
%72 = call i32 @sqlite3_finalize(i32* %71)
%73 = load i8*, i8** %10
%74 = call i32 @free(i8* %73)
%75 = load i32, i32* %6
%76 = load i8*, i8** %7
ret i32 %75
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@.str = [37 x i8] c"SELECT Size FROM %s WHERE Child='%s'\00"
@.str.1 = [4 x i8] c"MAP\00"
@SQLITE_OK = global i32 0
@stderr = global i32 0
@.str.2 = [19 x i8] c"sql error #%d: %s\0A\00"
@SQLITE_DONE = global i32 0
@.str.3 = [22 x i8] c"busy, wait 1 seconds\0A\00"
@.str.4 = [16 x i8] c"step error: %s\0A\00"
define i32 @sqlite_get_size(i32* %0, i8* %1) {
%3 = alloca i32*
%4 = load i32, i32* @PATH_MAX
%5 = shl nsw i32 %4, 1
%6 = add nsw i32 %5, 50
%7 = zext i32 %6 to i64
%8 = alloca i8, i64 %7
%9 = bitcast i32** %3 to i8*
%10 = tail call i8* @malloc(i32 %5)
%11 = tail call i32 @sqlite_sanatize(i8* %1, i8* %10)
%12 = load i32, i32* @PATH_MAX
%13 = shl nsw i32 %12, 1
%14 = add nsw i32 %13, 50
%15 = call i32 @snprintf(i8* %8, i32 %14, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %10)
%16 = load i32, i32* @PATH_MAX
%17 = shl nsw i32 %16, 1
%18 = add nsw i32 %17, 50
%19 = call i32 @sqlite3_prepare(i32* %0, i8* %8, i32 %18, i32** %3, i32 0)
%20 = load i32, i32* @SQLITE_OK
%21 = icmp eq i32 %19, %20
br i1 %21, label %22, label %27
22: ; preds = %2
%23 = load i32*, i32** %3
%24 = call i32 @sqlite3_step(i32* %23)
%25 = load i32, i32* @SQLITE_DONE
%26 = icmp eq i32 %24, %25
br i1 %26, label %51, label %31
27: ; preds = %2
%28 = load i32, i32* @stderr
%29 = call i8* @sqlite3_errmsg(i32* %0)
%30 = call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %19, i8* %29)
br label %51
31: ; preds = %22, %45
%32 = phi i32 [ %48, %45 ], [ %24, %22 ]
%33 = phi i32 [ %46, %45 ], [ undef, %22 ]
switch i32 %32, label %45 [
i32 130, label %34
i32 129, label %38
i32 128, label %42
]
34: ; preds = %31
%35 = load i32, i32* @stderr
%36 = call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
%37 = call i32 @sleep(i32 1)
br label %45
38: ; preds = %31
%39 = load i32, i32* @stderr
%40 = call i8* @sqlite3_errmsg(i32* %0)
%41 = call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i8* %40)
br label %45
42: ; preds = %31
%43 = load i32*, i32** %3
%44 = call i32 @sqlite3_column_int(i32* %43, i32 0)
br label %45
45: ; preds = %31, %42, %38, %34
%46 = phi i32 [ %33, %31 ], [ %44, %42 ], [ %33, %38 ], [ %33, %34 ]
%47 = load i32*, i32** %3
%48 = call i32 @sqlite3_step(i32* %47)
%49 = load i32, i32* @SQLITE_DONE
%50 = icmp eq i32 %48, %49
br i1 %50, label %51, label %31
51: ; preds = %45, %22, %27
%52 = phi i32 [ undef, %27 ], [ undef, %22 ], [ %46, %45 ]
%53 = load i32*, i32** %3
%54 = call i32 @sqlite3_finalize(i32* %53)
%55 = call i32 @free(i8* %10)
ret i32 %52
}