#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;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int SQLITE_OK;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/);
int /*<<< orphan*/ sqlite3_close(int /*<<< orphan*/ *);
char *sqlite3_errmsg(int /*<<< orphan*/ *);
int /*<<< orphan*/ sqlite3_free(char *);
int /*<<< orphan*/ sqlite3_free_table(char **);
int sqlite3_get_table(int /*<<< orphan*/ *, char *, char ***, int *, int *,
                      char **);
scalar_t__ sqlite3_open(char *, int /*<<< orphan*/ **);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int main(int argc, char *argv[]) {
  sqlite3 *db = NULL;
  char **result = NULL;
  char *sql_query = NULL;
  char *err = NULL;
  int rc = 0;
  int i, j, nrows, ncols;
  if (argc != 2) {
    fprintf(stderr, "Usage: %s <database>\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  if (sqlite3_open(argv[1], &db)) {
    fprintf(stderr, "Err. can't create database: %s\n", sqlite3_errmsg(db));
    exit(EXIT_FAILURE);
  }
  sql_query = "SELECT * from song ORDER by id";
  rc = sqlite3_get_table(db, sql_query, &result, &nrows, &ncols, &err);
  if (rc != SQLITE_OK) {
    fprintf(stderr, "Err. can'texecute sql query: \'%s\'\n", err);
    sqlite3_free(err);
  }
  for (i = 0; i < nrows; i++) {
    for (j = 0; j < ncols; j++) {
      fprintf(stdout, "%2s, ", result[(i + 1) * ncols + j]);
    }
    fputc('\n', stdout);
  }
  sqlite3_free_table(result);
  sqlite3_close(db);
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1201 <main+0x71>
mov    0x2dfa(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe12(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2dd6(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x18(%rbp),%rsi
call   1030 <sqlite3_open@plt>
cmp    $0x0,%rax
je     1251 <main+0xc1>
mov    0x2db5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x48(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <sqlite3_errmsg@plt>
mov    -0x48(%rbp),%edi
mov    %rax,%rdx
lea    0xdd8(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2d86(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
lea    0xdde(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
lea    -0x20(%rbp),%rdx
lea    -0x40(%rbp),%rcx
lea    -0x44(%rbp),%r8
lea    -0x30(%rbp),%r9
call   1060 <sqlite3_get_table@plt>
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
mov    0x2d62(%rip),%rcx
cmp    (%rcx),%eax
je     12b0 <main+0x120>
mov    0x2d43(%rip),%rax
mov    (%rax),%edi
mov    -0x30(%rbp),%rdx
lea    0xdb3(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x30(%rbp),%rdi
call   10a0 <sqlite3_free@plt>
movl   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0x40(%rbp),%eax
jge    1332 <main+0x1a2>
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x44(%rbp),%eax
jge    1311 <main+0x181>
mov    0x2ceb(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rax
mov    -0x38(%rbp),%ecx
add    $0x1,%ecx
imul   -0x44(%rbp),%ecx
add    -0x3c(%rbp),%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xd7a(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    12ca <main+0x13a>
mov    0x2cb0(%rip),%rax
mov    (%rax),%esi
mov    $0xa,%edi
call   1040 <fputc@plt>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    12b7 <main+0x127>
mov    -0x20(%rbp),%rdi
call   1090 <sqlite3_free_table@plt>
mov    -0x18(%rbp),%rdi
call   1080 <sqlite3_close@plt>
mov    0x2c75(%rip),%rax
mov    (%rax),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
movq   $0x0,0x8(%rsp)
movq   $0x0,0x18(%rsp)
movq   $0x0,0x10(%rsp)
cmp    $0x2,%edi
jne    12d4 <main+0x144>
mov    0x8(%rsi),%rdi
lea    0x8(%rsp),%rsi
call   1030 <sqlite3_open@plt>
test   %rax,%rax
jne    12e9 <main+0x159>
mov    0x8(%rsp),%rdi
lea    0xe53(%rip),%rsi
lea    0x18(%rsp),%rdx
lea    0x4(%rsp),%rcx
mov    %rsp,%r8
lea    0x10(%rsp),%r9
call   1060 <sqlite3_get_table@plt>
mov    0x2de7(%rip),%rcx
cmp    (%rcx),%eax
je     1229 <main+0x99>
mov    0x2dcc(%rip),%rax
mov    (%rax),%edi
mov    0x10(%rsp),%rdx
lea    0xe3b(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x10(%rsp),%rdi
call   10a0 <sqlite3_free@plt>
cmpl   $0x0,0x4(%rsp)
jle    12aa <main+0x11a>
xor    %r14d,%r14d
mov    $0x1,%ebp
mov    0x2d89(%rip),%r12
lea    0xe32(%rip),%r15
jmp    1268 <main+0xd8>
nopl   0x0(%rax,%rax,1)
mov    (%r12),%esi
mov    $0xa,%edi
call   1040 <fputc@plt>
add    $0x1,%ebp
cmp    0x4(%rsp),%r14d
jge    12aa <main+0x11a>
mov    (%rsp),%eax
add    $0x1,%r14d
test   %eax,%eax
jle    1250 <main+0xc0>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%r12),%edi
mov    0x18(%rsp),%rcx
imul   %ebp,%eax
cltq
add    %rbx,%rax
mov    (%rcx,%rax,8),%rdx
mov    %r15,%rsi
call   1070 <fprintf@plt>
mov    (%rsp),%eax
add    $0x1,%rbx
cmp    %eax,%ebx
jl     1280 <main+0xf0>
jmp    1250 <main+0xc0>
mov    0x18(%rsp),%rdi
call   1090 <sqlite3_free_table@plt>
mov    0x8(%rsp),%rdi
call   1080 <sqlite3_close@plt>
mov    0x2cfb(%rip),%rax
mov    (%rax),%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2cfd(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xd19(%rip),%rsi
jmp    1308 <main+0x178>
mov    0x2ce8(%rip),%rax
mov    (%rax),%ebx
mov    0x8(%rsp),%rdi
call   1050 <sqlite3_errmsg@plt>
lea    0xd13(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1070 <fprintf@plt>
mov    0x2cbc(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [22 x i8] c"Usage: %s <database>\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [32 x i8] c"Err. can't create database: %s\0A\00"
@.str.2 = [31 x i8] c"SELECT * from song ORDER by id\00"
@SQLITE_OK = global i32 0
@.str.3 = [35 x i8] c"Err. can'texecute sql query: '%s'\0A\00"
@stdout = global i32 0
@.str.4 = [6 x i8] c"%2s, \00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i8**
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32* null, i32** %6
store i8** null, i8*** %7
store i8* null, i8** %8
store i8* null, i8** %9
store i32 0, i32* %10
%15 = load i32, i32* %4
%16 = icmp ne i32 %15, 2
br i1 %16, label %17, label %25
17: ; preds = %2
%18 = load i32, i32* @stderr
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 0
%21 = load i8*, i8** %20
%22 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %21)
%23 = load i32, i32* @EXIT_FAILURE
%24 = call i32 @exit(i32 %23)
unreachable
25: ; preds = %2
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = call i64 @sqlite3_open(i8* %28, i32** %6)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %38
31: ; preds = %25
%32 = load i32, i32* @stderr
%33 = load i32*, i32** %6
%34 = call i8* @sqlite3_errmsg(i32* %33)
%35 = call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* %34)
%36 = load i32, i32* @EXIT_FAILURE
%37 = call i32 @exit(i32 %36)
unreachable
38: ; preds = %25
store i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i8** %8
%39 = load i32*, i32** %6
%40 = load i8*, i8** %8
%41 = call i32 @sqlite3_get_table(i32* %39, i8* %40, i8*** %7, i32* %13, i32* %14, i8** %9)
store i32 %41, i32* %10
%42 = load i32, i32* %10
%43 = load i32, i32* @SQLITE_OK
%44 = icmp ne i32 %42, %43
br i1 %44, label %45, label %51
45: ; preds = %38
%46 = load i32, i32* @stderr
%47 = load i8*, i8** %9
%48 = call i32 @fprintf(i32 %46, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i8* %47)
%49 = load i8*, i8** %9
%50 = call i32 @sqlite3_free(i8* %49)
br label %51
51: ; preds = %45, %38
store i32 0, i32* %11
br label %52
52: ; preds = %80, %51
%53 = load i32, i32* %11
%54 = load i32, i32* %13
%55 = icmp slt i32 %53, %54
br i1 %55, label %56, label %83
56: ; preds = %52
store i32 0, i32* %12
br label %57
57: ; preds = %74, %56
%58 = load i32, i32* %12
%59 = load i32, i32* %14
%60 = icmp slt i32 %58, %59
br i1 %60, label %61, label %77
61: ; preds = %57
%62 = load i32, i32* @stdout
%63 = load i8**, i8*** %7
%64 = load i32, i32* %11
%65 = add nsw i32 %64, 1
%66 = load i32, i32* %14
%67 = mul nsw i32 %65, %66
%68 = load i32, i32* %12
%69 = add nsw i32 %67, %68
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds i8*, i8** %63, i64 %70
%72 = load i8*, i8** %71
%73 = call i32 @fprintf(i32 %62, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %72)
br label %74
74: ; preds = %61
%75 = load i32, i32* %12
%76 = add nsw i32 %75, 1
store i32 %76, i32* %12
br label %57
77: ; preds = %57
%78 = load i32, i32* @stdout
%79 = call i32 @fputc(i8 signext 10, i32 %78)
br label %80
80: ; preds = %77
%81 = load i32, i32* %11
%82 = add nsw i32 %81, 1
store i32 %82, i32* %11
br label %52
83: ; preds = %52
%84 = load i8**, i8*** %7
%85 = call i32 @sqlite3_free_table(i8** %84)
%86 = load i32*, i32** %6
%87 = call i32 @sqlite3_close(i32* %86)
%88 = load i32, i32* @EXIT_SUCCESS
ret i32 %88
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [22 x i8] c"Usage: %s <database>\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [32 x i8] c"Err. can't create database: %s\0A\00"
@.str.2 = [31 x i8] c"SELECT * from song ORDER by id\00"
@SQLITE_OK = global i32 0
@.str.3 = [35 x i8] c"Err. can'texecute sql query: '%s'\0A\00"
@stdout = global i32 0
@.str.4 = [6 x i8] c"%2s, \00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32*
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = bitcast i32** %3 to i8*
store i32* null, i32** %3
%9 = bitcast i8*** %4 to i8*
store i8** null, i8*** %4
%10 = bitcast i8** %5 to i8*
store i8* null, i8** %5
%11 = bitcast i32* %6 to i8*
%12 = bitcast i32* %7 to i8*
%13 = icmp eq i32 %0, 2
br i1 %13, label %20, label %14
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = load i8*, i8** %1
%17 = tail call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = load i32, i32* @EXIT_FAILURE
%19 = tail call i32 @exit(i32 %18)
unreachable
20: ; preds = %2
%21 = getelementptr inbounds i8*, i8** %1, i64 1
%22 = load i8*, i8** %21
%23 = call i64 @sqlite3_open(i8* %22, i32** %3)
%24 = icmp eq i64 %23, 0
br i1 %24, label %32, label %25
25: ; preds = %20
%26 = load i32, i32* @stderr
%27 = load i32*, i32** %3
%28 = call i8* @sqlite3_errmsg(i32* %27)
%29 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* %28)
%30 = load i32, i32* @EXIT_FAILURE
%31 = call i32 @exit(i32 %30)
unreachable
32: ; preds = %20
%33 = load i32*, i32** %3
%34 = call i32 @sqlite3_get_table(i32* %33, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i8*** %4, i32* %6, i32* %7, i8** %5)
%35 = load i32, i32* @SQLITE_OK
%36 = icmp eq i32 %34, %35
br i1 %36, label %43, label %37
37: ; preds = %32
%38 = load i32, i32* @stderr
%39 = load i8*, i8** %5
%40 = call i32 @fprintf(i32 %38, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i8* %39)
%41 = load i8*, i8** %5
%42 = call i32 @sqlite3_free(i8* %41)
br label %43
43: ; preds = %37, %32
%44 = load i32, i32* %6
%45 = icmp sgt i32 %44, 0
br i1 %45, label %46, label %70
46: ; preds = %43, %65
%47 = phi i32 [ %50, %65 ], [ 0, %43 ]
%48 = load i32, i32* %7
%49 = icmp sgt i32 %48, 0
%50 = add nuw nsw i32 %47, 1
br i1 %49, label %51, label %65
51: ; preds = %46, %51
%52 = phi i32 [ %63, %51 ], [ %48, %46 ]
%53 = phi i32 [ %62, %51 ], [ 0, %46 ]
%54 = load i32, i32* @stdout
%55 = load i8**, i8*** %4
%56 = mul nsw i32 %52, %50
%57 = add nsw i32 %56, %53
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i8*, i8** %55, i64 %58
%60 = load i8*, i8** %59
%61 = call i32 @fprintf(i32 %54, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %60)
%62 = add nuw nsw i32 %53, 1
%63 = load i32, i32* %7
%64 = icmp slt i32 %62, %63
br i1 %64, label %51, label %65
65: ; preds = %51, %46
%66 = load i32, i32* @stdout
%67 = call i32 @fputc(i8 signext 10, i32 %66)
%68 = load i32, i32* %6
%69 = icmp slt i32 %50, %68
br i1 %69, label %46, label %70
70: ; preds = %65, %43
%71 = load i8**, i8*** %4
%72 = call i32 @sqlite3_free_table(i8** %71)
%73 = load i32*, i32** %3
%74 = call i32 @sqlite3_close(i32* %73)
%75 = load i32, i32* @EXIT_SUCCESS
ret i32 %75
}