#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 SQLITE_OK;
int SQLITE_ROW;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ sqlite3_bind_int(int /*<<< orphan*/ *, int, size_t);
scalar_t__ sqlite3_column_text(int /*<<< orphan*/ *, int);
char *sqlite3_errmsg(int /*<<< orphan*/ *);
int sqlite3_prepare_v2(int /*<<< orphan*/ *, char *, int, int /*<<< orphan*/ **,
                       int /*<<< orphan*/);
int sqlite3_step(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
char *strdup(char const *);
int strtol(char const *, char **, int);
int Get_Sub_Names(sqlite3 *db, sqlite3_stmt *stmt, char *sql_stmt,
                  char *names[], int *lengths, size_t maxLength) {
  int rv;
  rv = sqlite3_prepare_v2(db, sql_stmt, -1, &stmt, 0);
  if (rv != SQLITE_OK) {
    fprintf(stderr, "Preparation failed: %s\n", sqlite3_errmsg(db));
    return -1;
  }
  sqlite3_bind_int(stmt, 1, maxLength);
  int counter = 0;
  while ((rv = sqlite3_step(stmt)) == SQLITE_ROW) {
    lengths[counter] =
        strtol((const char *)sqlite3_column_text(stmt, 0), (char **)NULL, 10);
    names[counter++] = strdup((const char *)sqlite3_column_text(stmt, 1));
  }
  return 0;
}


x86 assembly (clang, -O0):
<Get_Sub_Names>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    %r9,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    $0xffffffff,%edx
lea    -0x18(%rbp),%rcx
xor    %r8d,%r8d
call   1090 <sqlite3_prepare_v2@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
mov    0x2e22(%rip),%rcx
cmp    (%rcx),%eax
je     1201 <Get_Sub_Names+0x81>
mov    0x2e03(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <sqlite3_errmsg@plt>
mov    -0x44(%rbp),%edi
mov    %rax,%rdx
lea    0xe10(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1299 <Get_Sub_Names+0x119>
mov    -0x18(%rbp),%rdi
mov    -0x38(%rbp),%rdx
mov    $0x1,%esi
call   1030 <sqlite3_bind_int@plt>
movl   $0x0,-0x40(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <sqlite3_step@plt>
mov    %eax,-0x3c(%rbp)
mov    0x2da3(%rip),%rcx
cmp    (%rcx),%eax
jne    1292 <Get_Sub_Names+0x112>
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
call   1080 <sqlite3_column_text@plt>
mov    %rax,%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1070 <strtol@plt>
mov    %eax,%edx
mov    -0x30(%rbp),%rax
movslq -0x40(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x18(%rbp),%rdi
mov    $0x1,%esi
call   1080 <sqlite3_column_text@plt>
mov    %rax,%rdi
call   10a0 <strdup@plt>
mov    %rax,%rdx
mov    -0x28(%rbp),%rax
mov    -0x40(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x40(%rbp)
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
jmp    121a <Get_Sub_Names+0x9a>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Get_Sub_Names>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9,%r12
mov    %r8,%r14
mov    %rcx,%rbp
mov    %rdi,%r13
mov    %rsi,(%rsp)
mov    %rsp,%rcx
xor    %r15d,%r15d
mov    %rdx,%rsi
mov    $0xffffffff,%edx
xor    %r8d,%r8d
call   1090 <sqlite3_prepare_v2@plt>
mov    0x2e30(%rip),%rcx
cmp    (%rcx),%eax
jne    123e <Get_Sub_Names+0xbe>
mov    (%rsp),%rdi
mov    $0x1,%esi
mov    %r12,%rdx
call   1030 <sqlite3_bind_int@plt>
mov    (%rsp),%rdi
call   1050 <sqlite3_step@plt>
mov    0x2def(%rip),%r12
cmp    (%r12),%eax
jne    1266 <Get_Sub_Names+0xe6>
xor    %r15d,%r15d
xor    %ebx,%ebx
mov    (%rsp),%rdi
xor    %esi,%esi
call   1080 <sqlite3_column_text@plt>
mov    %rax,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1070 <strtol@plt>
mov    %eax,(%r14,%rbx,1)
mov    (%rsp),%rdi
mov    $0x1,%esi
call   1080 <sqlite3_column_text@plt>
mov    %rax,%rdi
call   10a0 <strdup@plt>
mov    %rax,0x0(%rbp,%rbx,2)
mov    (%rsp),%rdi
call   1050 <sqlite3_step@plt>
add    $0x4,%rbx
cmp    (%r12),%eax
je     11f0 <Get_Sub_Names+0x70>
jmp    1266 <Get_Sub_Names+0xe6>
mov    0x2d93(%rip),%rax
mov    (%rax),%ebx
mov    %r13,%rdi
call   1040 <sqlite3_errmsg@plt>
lea    0xdaa(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1060 <fprintf@plt>
mov    $0xffffffff,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@SQLITE_OK = global i32 0
@stderr = global i32 0
@.str = [24 x i8] c"Preparation failed: %s\0A\00"
@SQLITE_ROW = global i32 0
define i32 @Get_Sub_Names(i32* %0, i32* %1, i8* %2, i8** %3, i32* %4, i64 %5) {
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i8*
%11 = alloca i8**
%12 = alloca i32*
%13 = alloca i64
%14 = alloca i32
%15 = alloca i32
store i32* %0, i32** %8
store i32* %1, i32** %9
store i8* %2, i8** %10
store i8** %3, i8*** %11
store i32* %4, i32** %12
store i64 %5, i64* %13
%16 = load i32*, i32** %8
%17 = load i8*, i8** %10
%18 = call i32 @sqlite3_prepare_v2(i32* %16, i8* %17, i32 -1, i32** %9, i32 0)
store i32 %18, i32* %14
%19 = load i32, i32* %14
%20 = load i32, i32* @SQLITE_OK
%21 = icmp ne i32 %19, %20
br i1 %21, label %22, label %27
22: ; preds = %6
%23 = load i32, i32* @stderr
%24 = load i32*, i32** %8
%25 = call i8* @sqlite3_errmsg(i32* %24)
%26 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %25)
store i32 -1, i32* %7
br label %55
27: ; preds = %6
%28 = load i32*, i32** %9
%29 = load i64, i64* %13
%30 = call i32 @sqlite3_bind_int(i32* %28, i32 1, i64 %29)
store i32 0, i32* %15
br label %31
31: ; preds = %36, %27
%32 = load i32*, i32** %9
%33 = call i32 @sqlite3_step(i32* %32)
store i32 %33, i32* %14
%34 = load i32, i32* @SQLITE_ROW
%35 = icmp eq i32 %33, %34
br i1 %35, label %36, label %54
36: ; preds = %31
%37 = load i32*, i32** %9
%38 = call i64 @sqlite3_column_text(i32* %37, i32 0)
%39 = inttoptr i64 %38 to i8*
%40 = call i32 @strtol(i8* %39, i8** null, i32 10)
%41 = load i32*, i32** %12
%42 = load i32, i32* %15
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i32, i32* %41, i64 %43
store i32 %40, i32* %44
%45 = load i32*, i32** %9
%46 = call i64 @sqlite3_column_text(i32* %45, i32 1)
%47 = inttoptr i64 %46 to i8*
%48 = call i8* @strdup(i8* %47)
%49 = load i8**, i8*** %11
%50 = load i32, i32* %15
%51 = add nsw i32 %50, 1
store i32 %51, i32* %15
%52 = sext i32 %50 to i64
%53 = getelementptr inbounds i8*, i8** %49, i64 %52
store i8* %48, i8** %53
br label %31
54: ; preds = %31
store i32 0, i32* %7
br label %55
55: ; preds = %54, %22
%56 = load i32, i32* %7
ret i32 %56
}

LLVM IR (-O2):
@SQLITE_OK = global i32 0
@stderr = global i32 0
@.str = [24 x i8] c"Preparation failed: %s\0A\00"
@SQLITE_ROW = global i32 0
define i32 @Get_Sub_Names(i32* %0, i32* %1, i8* %2, i8** nocapture writeonly %3, i32* nocapture writeonly %4, i64 %5) {
%7 = alloca i32*
store i32* %1, i32** %7
%8 = call i32 @sqlite3_prepare_v2(i32* %0, i8* %2, i32 -1, i32** %7, i32 0)
%9 = load i32, i32* @SQLITE_OK
%10 = icmp eq i32 %8, %9
br i1 %10, label %15, label %11
11: ; preds = %6
%12 = load i32, i32* @stderr
%13 = call i8* @sqlite3_errmsg(i32* %0)
%14 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %13)
br label %39
15: ; preds = %6
%16 = load i32*, i32** %7
%17 = call i32 @sqlite3_bind_int(i32* %16, i32 1, i64 %5)
%18 = load i32*, i32** %7
%19 = call i32 @sqlite3_step(i32* %18)
%20 = load i32, i32* @SQLITE_ROW
%21 = icmp eq i32 %19, %20
br i1 %21, label %22, label %39
22: ; preds = %15, %22
%23 = phi i64 [ %33, %22 ], [ 0, %15 ]
%24 = load i32*, i32** %7
%25 = call i64 @sqlite3_column_text(i32* %24, i32 0)
%26 = inttoptr i64 %25 to i8*
%27 = call i32 @strtol(i8* nocapture %26, i8** null, i32 10)
%28 = getelementptr inbounds i32, i32* %4, i64 %23
store i32 %27, i32* %28
%29 = load i32*, i32** %7
%30 = call i64 @sqlite3_column_text(i32* %29, i32 1)
%31 = inttoptr i64 %30 to i8*
%32 = call i8* @strdup(i8* %31)
%33 = add nuw i64 %23, 1
%34 = getelementptr inbounds i8*, i8** %3, i64 %23
store i8* %32, i8** %34
%35 = load i32*, i32** %7
%36 = call i32 @sqlite3_step(i32* %35)
%37 = load i32, i32* @SQLITE_ROW
%38 = icmp eq i32 %36, %37
br i1 %38, label %22, label %39
39: ; preds = %22, %15, %11
%40 = phi i32 [ -1, %11 ], [ 0, %15 ], [ 0, %22 ]
ret i32 %40
}