#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 /*<<< orphan*/ sprintf(char *, char *, char *);
char *sqlite3_column_text(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 /*<<< orphan*/ strcpy(char *, char *);
int sqlite_get_parent(sqlite3 *database, const char *child, char **parent) {
  int rc;
  char cmd[50 + 2 * PATH_MAX];
  sqlite3_stmt *stmt;
  char temp[PATH_MAX];
  char *child_s = malloc(2 * PATH_MAX * sizeof(char));
  rc = sqlite_sanatize(child, child_s);
  snprintf(cmd, 50 + 2 * PATH_MAX, "SELECT Parent 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:
        *parent = malloc(PATH_MAX * sizeof(char));
        sprintf(temp, "%s", sqlite3_column_text(stmt, 0));
        strcpy(*parent, temp);
        break;
      }
    }
  }
  sqlite3_finalize(stmt);
  free(child_s);
  return 0;
}


x86 assembly (clang, -O0):
<sqlite_get_parent>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    0x2e05(%rip),%rax
mov    (%rax),%edx
mov    %edx,%ecx
lea    0x32(%rcx,%rcx,1),%ecx
mov    %rsp,%rdx
mov    %rdx,-0x28(%rbp)
mov    %rcx,%rsi
add    $0xf,%rsi
and    $0xfffffffffffffff0,%rsi
mov    %rsp,%rdx
sub    %rsi,%rdx
mov    %rdx,-0x50(%rbp)
mov    %rdx,%rsp
mov    %rcx,-0x30(%rbp)
mov    (%rax),%eax
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x58(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x40(%rbp)
mov    0x2db5(%rip),%rax
mov    (%rax),%eax
shl    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x48(%rbp),%rsi
call   10b0 <sqlite_sanatize@plt>
mov    -0x50(%rbp),%rdi
mov    %eax,-0x1c(%rbp)
mov    0x2d84(%rip),%rax
mov    (%rax),%esi
shl    $0x1,%esi
add    $0x32,%esi
mov    -0x48(%rbp),%r8
lea    0xd81(%rip),%rdx
lea    0xda1(%rip),%rcx
call   1050 <snprintf@plt>
mov    -0x50(%rbp),%rsi
mov    -0x8(%rbp),%rdi
mov    0x2d56(%rip),%rax
mov    (%rax),%eax
shl    $0x1,%eax
add    $0x32,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edx
lea    -0x38(%rbp),%rcx
xor    %r8d,%r8d
call   10c0 <sqlite3_prepare@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    0x2d1d(%rip),%rcx
cmp    (%rcx),%eax
je     1302 <sqlite_get_parent+0x132>
mov    0x2cfe(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x60(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x5c(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <sqlite3_errmsg@plt>
mov    -0x60(%rbp),%edi
mov    -0x5c(%rbp),%edx
mov    %rax,%rcx
lea    0xd35(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
jmp    1409 <sqlite_get_parent+0x239>
jmp    1307 <sqlite_get_parent+0x137>
mov    -0x38(%rbp),%rdi
call   1070 <sqlite3_step@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2cae(%rip),%rcx
cmp    (%rcx),%eax
je     1404 <sqlite_get_parent+0x234>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x64(%rbp)
sub    $0x80,%eax
je     13b2 <sqlite_get_parent+0x1e2>
jmp    1338 <sqlite_get_parent+0x168>
mov    -0x64(%rbp),%eax
sub    $0x81,%eax
je     1384 <sqlite_get_parent+0x1b4>
jmp    134b <sqlite_get_parent+0x17b>
mov    -0x64(%rbp),%eax
sub    $0x82,%eax
jne    13ff <sqlite_get_parent+0x22f>
jmp    135e <sqlite_get_parent+0x18e>
mov    0x2c6b(%rip),%rax
mov    (%rax),%edi
lea    0xcd0(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10f0 <sleep@plt>
jmp    13ff <sqlite_get_parent+0x22f>
mov    0x2c45(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x68(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <sqlite3_errmsg@plt>
mov    -0x68(%rbp),%edi
mov    %rax,%rdx
lea    0xcae(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
jmp    13ff <sqlite_get_parent+0x22f>
mov    0x2c37(%rip),%rax
movslq (%rax),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   10a0 <malloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x38(%rbp),%rdi
xor    %esi,%esi
call   1090 <sqlite3_column_text@plt>
mov    -0x58(%rbp),%rdi
mov    %rax,%rdx
lea    0xc7a(%rip),%rsi
call   10e0 <sprintf@plt>
mov    -0x58(%rbp),%rsi
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   1040 <strcpy@plt>
jmp    1307 <sqlite_get_parent+0x137>
jmp    1409 <sqlite_get_parent+0x239>
mov    -0x38(%rbp),%rdi
call   10d0 <sqlite3_finalize@plt>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
xor    %eax,%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sqlite_get_parent>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdx,-0x40(%rbp)
mov    %rsi,%r15
mov    %rdi,-0x38(%rbp)
mov    0x2e0d(%rip),%r14
mov    (%r14),%eax
lea    (%rax,%rax,1),%edi
lea    (%rax,%rax,1),%ecx
add    $0x32,%ecx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rbx
sub    %rcx,%rbx
mov    %rbx,%rsp
mov    %rsp,%r13
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r13
mov    %r13,%rsp
call   10a0 <malloc@plt>
mov    %rax,%r12
mov    %r15,%rdi
mov    %rax,%rsi
call   10b0 <sqlite_sanatize@plt>
mov    (%r14),%eax
lea    (%rax,%rax,1),%esi
add    $0x32,%esi
lea    0xdcc(%rip),%rdx
lea    0xdec(%rip),%rcx
mov    %rbx,%rdi
mov    %r12,-0x48(%rbp)
mov    %r12,%r8
call   1050 <snprintf@plt>
mov    (%r14),%eax
lea    (%rax,%rax,1),%edx
add    $0x32,%edx
lea    -0x30(%rbp),%rcx
mov    -0x38(%rbp),%rdi
mov    %rbx,%rsi
xor    %r8d,%r8d
call   10c0 <sqlite3_prepare@plt>
mov    %eax,%ebx
mov    0x2d71(%rip),%rax
cmp    (%rax),%ebx
jne    1349 <sqlite_get_parent+0x189>
mov    -0x30(%rbp),%rdi
call   1070 <sqlite3_step@plt>
mov    0x2d41(%rip),%r15
cmp    (%r15),%eax
mov    -0x40(%rbp),%r12
je     1372 <sqlite_get_parent+0x1b2>
mov    0x2d35(%rip),%rbx
jmp    12d2 <sqlite_get_parent+0x112>
nopl   (%rax)
mov    (%rbx),%r14d
mov    -0x38(%rbp),%rdi
call   1060 <sqlite3_errmsg@plt>
mov    %r14d,%edi
lea    0xd9e(%rip),%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    -0x30(%rbp),%rdi
call   1070 <sqlite3_step@plt>
cmp    (%r15),%eax
je     1372 <sqlite_get_parent+0x1b2>
cmp    $0x80,%eax
je     1310 <sqlite_get_parent+0x150>
cmp    $0x81,%eax
je     12a0 <sqlite_get_parent+0xe0>
cmp    $0x82,%eax
jne    12c0 <sqlite_get_parent+0x100>
mov    (%rbx),%edi
lea    0xd4e(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10e0 <sleep@plt>
jmp    12c0 <sqlite_get_parent+0x100>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    0x2cd9(%rip),%rax
mov    (%rax),%edi
call   10a0 <malloc@plt>
mov    %rax,(%r12)
mov    -0x30(%rbp),%rdi
xor    %esi,%esi
call   1090 <sqlite3_column_text@plt>
mov    %r13,%rdi
mov    %rax,%rsi
call   1040 <strcpy@plt>
mov    (%r12),%rdi
mov    %r13,%rsi
call   1040 <strcpy@plt>
jmp    12c0 <sqlite_get_parent+0x100>
mov    0x2c80(%rip),%rax
mov    (%rax),%r15d
mov    -0x38(%rbp),%rdi
call   1060 <sqlite3_errmsg@plt>
lea    0xcc8(%rip),%rsi
mov    %r15d,%edi
mov    %ebx,%edx
mov    %rax,%rcx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    -0x30(%rbp),%rdi
call   10d0 <sqlite3_finalize@plt>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%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 = [39 x i8] c"SELECT Parent 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"
@.str.5 = [3 x i8] c"%s\00"
define i32 @sqlite_get_parent(i32* %0, i8* %1, i8** %2) {
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i8**
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i32*
%11 = alloca i64
%12 = alloca i8*
store i32* %0, i32** %4
store i8* %1, i8** %5
store i8** %2, i8*** %6
%13 = load i32, i32* @PATH_MAX
%14 = mul nsw i32 2, %13
%15 = add nsw i32 50, %14
%16 = zext i32 %15 to i64
%17 = call i8* @llvm.stacksave()
store i8* %17, i8** %8
%18 = alloca i8, i64 %16
store i64 %16, i64* %9
%19 = load i32, i32* @PATH_MAX
%20 = zext i32 %19 to i64
%21 = alloca i8, i64 %20
store i64 %20, i64* %11
%22 = load i32, i32* @PATH_MAX
%23 = mul nsw i32 2, %22
%24 = sext i32 %23 to i64
%25 = mul i64 %24, 1
%26 = trunc i64 %25 to i32
%27 = call i8* @malloc(i32 %26)
store i8* %27, i8** %12
%28 = load i8*, i8** %5
%29 = load i8*, i8** %12
%30 = call i32 @sqlite_sanatize(i8* %28, i8* %29)
store i32 %30, i32* %7
%31 = load i32, i32* @PATH_MAX
%32 = mul nsw i32 2, %31
%33 = add nsw i32 50, %32
%34 = load i8*, i8** %12
%35 = call i32 @snprintf(i8* %18, i32 %33, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %34)
%36 = load i32*, i32** %4
%37 = load i32, i32* @PATH_MAX
%38 = mul nsw i32 2, %37
%39 = add nsw i32 50, %38
%40 = sext i32 %39 to i64
%41 = mul i64 %40, 1
%42 = trunc i64 %41 to i32
%43 = call i32 @sqlite3_prepare(i32* %36, i8* %18, i32 %42, i32** %10, i32 0)
store i32 %43, i32* %7
%44 = load i32, i32* %7
%45 = load i32, i32* @SQLITE_OK
%46 = icmp ne i32 %44, %45
br i1 %46, label %47, label %53
47: ; preds = %3
%48 = load i32, i32* @stderr
%49 = load i32, i32* %7
%50 = load i32*, i32** %4
%51 = call i8* @sqlite3_errmsg(i32* %50)
%52 = call i32 (i32, i8*, ...) @fprintf(i32 %48, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %49, i8* %51)
br label %85
53: ; preds = %3
br label %54
54: ; preds = %83, %53
%55 = load i32*, i32** %10
%56 = call i32 @sqlite3_step(i32* %55)
store i32 %56, i32* %7
%57 = load i32, i32* @SQLITE_DONE
%58 = icmp ne i32 %56, %57
br i1 %58, label %59, label %84
59: ; preds = %54
%60 = load i32, i32* %7
switch i32 %60, label %83 [
i32 130, label %61
i32 129, label %65
i32 128, label %70
]
61: ; preds = %59
%62 = load i32, i32* @stderr
%63 = call i32 (i32, i8*, ...) @fprintf(i32 %62, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
%64 = call i32 @sleep(i32 1)
br label %83
65: ; preds = %59
%66 = load i32, i32* @stderr
%67 = load i32*, i32** %4
%68 = call i8* @sqlite3_errmsg(i32* %67)
%69 = call i32 (i32, i8*, ...) @fprintf(i32 %66, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i8* %68)
br label %83
70: ; preds = %59
%71 = load i32, i32* @PATH_MAX
%72 = sext i32 %71 to i64
%73 = mul i64 %72, 1
%74 = trunc i64 %73 to i32
%75 = call i8* @malloc(i32 %74)
%76 = load i8**, i8*** %6
store i8* %75, i8** %76
%77 = load i32*, i32** %10
%78 = call i8* @sqlite3_column_text(i32* %77, i32 0)
%79 = call i32 @sprintf(i8* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %78)
%80 = load i8**, i8*** %6
%81 = load i8*, i8** %80
%82 = call i32 @strcpy(i8* %81, i8* %21)
br label %83
83: ; preds = %59, %70, %65, %61
br label %54
84: ; preds = %54
br label %85
85: ; preds = %84, %47
%86 = load i32*, i32** %10
%87 = call i32 @sqlite3_finalize(i32* %86)
%88 = load i8*, i8** %12
%89 = call i32 @free(i8* %88)
%90 = load i8*, i8** %8
ret i32 0
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@.str = [39 x i8] c"SELECT Parent 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_parent(i32* %0, i8* %1, i8** nocapture %2) {
%4 = alloca i32*
%5 = load i32, i32* @PATH_MAX
%6 = shl nsw i32 %5, 1
%7 = add nsw i32 %6, 50
%8 = zext i32 %7 to i64
%9 = alloca i8, i64 %8
%10 = bitcast i32** %4 to i8*
%11 = zext i32 %5 to i64
%12 = alloca i8, i64 %11
%13 = tail call i8* @malloc(i32 %6)
%14 = tail call i32 @sqlite_sanatize(i8* %1, i8* %13)
%15 = load i32, i32* @PATH_MAX
%16 = shl nsw i32 %15, 1
%17 = add nsw i32 %16, 50
%18 = call i32 @snprintf(i8* %9, i32 %17, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %13)
%19 = load i32, i32* @PATH_MAX
%20 = shl nsw i32 %19, 1
%21 = add nsw i32 %20, 50
%22 = call i32 @sqlite3_prepare(i32* %0, i8* %9, i32 %21, i32** %4, i32 0)
%23 = load i32, i32* @SQLITE_OK
%24 = icmp eq i32 %22, %23
br i1 %24, label %25, label %30
25: ; preds = %3
%26 = load i32*, i32** %4
%27 = call i32 @sqlite3_step(i32* %26)
%28 = load i32, i32* @SQLITE_DONE
%29 = icmp eq i32 %27, %28
br i1 %29, label %57, label %34
30: ; preds = %3
%31 = load i32, i32* @stderr
%32 = call i8* @sqlite3_errmsg(i32* %0)
%33 = call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %22, i8* %32)
br label %57
34: ; preds = %25, %52
%35 = phi i32 [ %54, %52 ], [ %27, %25 ]
switch i32 %35, label %52 [
i32 130, label %36
i32 129, label %40
i32 128, label %44
]
36: ; preds = %34
%37 = load i32, i32* @stderr
%38 = call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
%39 = call i32 @sleep(i32 1)
br label %52
40: ; preds = %34
%41 = load i32, i32* @stderr
%42 = call i8* @sqlite3_errmsg(i32* %0)
%43 = call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i8* %42)
br label %52
44: ; preds = %34
%45 = load i32, i32* @PATH_MAX
%46 = call i8* @malloc(i32 %45)
store i8* %46, i8** %2
%47 = load i32*, i32** %4
%48 = call i8* @sqlite3_column_text(i32* %47, i32 0)
%49 = call i8* bitcast (i32 (i8*, i8*)* @strcpy to i8* (i8*, i8*)*)(i8* %12, i8* %48)
%50 = load i8*, i8** %2
%51 = call i32 @strcpy(i8* %50, i8* %12)
br label %52
52: ; preds = %34, %44, %40, %36
%53 = load i32*, i32** %4
%54 = call i32 @sqlite3_step(i32* %53)
%55 = load i32, i32* @SQLITE_DONE
%56 = icmp eq i32 %54, %55
br i1 %56, label %57, label %34
57: ; preds = %52, %25, %30
%58 = load i32*, i32** %4
%59 = call i32 @sqlite3_finalize(i32* %58)
%60 = call i32 @free(i8* %13)
ret i32 0
}