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

/* Variables and functions */
int SQLITE_ROW;
int /*<<< orphan*/ printf(char *, ...);
int sql_step(int /*<<< orphan*/ *, int /*<<< orphan*/);
int sqlite3_column_count(int /*<<< orphan*/ *);
char *sqlite3_column_name(int /*<<< orphan*/ *, int /*<<< orphan*/);
scalar_t__ sqlite3_column_text(int /*<<< orphan*/ *, int /*<<< orphan*/);
int stmt_stdout(sqlite3_stmt *stmt, int *rowcount) {
  int ccount;
  int rcount = 0;
  int rc;
  if (stmt == 0 || (ccount = sqlite3_column_count(stmt)) == 0) {
    return sql_step(stmt, 0);
  }
  int i = 0;
  do {
    printf("%s", sqlite3_column_name(stmt, i++));
    if (i < ccount)
      printf("\t");
  } while (i < ccount);
  printf("\n");
  while ((rc = sql_step(stmt, 0)) == SQLITE_ROW) {
    i = 0;
    rcount++;
    do {
      printf("%s", (char *)sqlite3_column_text(stmt, i++));
      if (i < ccount)
        printf("\t");
    } while (i < ccount);
    printf("\n");
  }
  if (rowcount != NULL)
    *rowcount = rcount;
  return rc;
}


x86 assembly (clang, -O0):
<stmt_stdout>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1187 <stmt_stdout+0x37>
mov    -0x10(%rbp),%rdi
call   1050 <sqlite3_column_count@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jne    119a <stmt_stdout+0x4a>
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
call   1070 <sql_step@plt>
mov    %eax,-0x4(%rbp)
jmp    12a9 <stmt_stdout+0x159>
movl   $0x0,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%esi
mov    %esi,%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
call   1030 <sqlite3_column_name@plt>
mov    %rax,%rsi
lea    0xe41(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11e0 <stmt_stdout+0x90>
lea    0xe2a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11e5 <stmt_stdout+0x95>
mov    -0x28(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jl     11a1 <stmt_stdout+0x51>
lea    0xe0d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
call   1070 <sql_step@plt>
mov    %eax,-0x24(%rbp)
mov    0x2dcc(%rip),%rcx
cmp    (%rcx),%eax
jne    128f <stmt_stdout+0x13f>
movl   $0x0,-0x28(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%esi
mov    %esi,%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
call   1060 <sqlite3_column_text@plt>
mov    %rax,%rsi
lea    0xdb6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    126b <stmt_stdout+0x11b>
lea    0xd9f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1270 <stmt_stdout+0x120>
mov    -0x28(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jl     122c <stmt_stdout+0xdc>
lea    0xd82(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11ff <stmt_stdout+0xaf>
cmpq   $0x0,-0x18(%rbp)
je     12a3 <stmt_stdout+0x153>
mov    -0x20(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stmt_stdout>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
test   %rdi,%rdi
je     12af <stmt_stdout+0x14f>
mov    %rsi,%rbp
mov    %rbx,%rdi
call   1060 <sqlite3_column_count@plt>
test   %eax,%eax
je     12af <stmt_stdout+0x14f>
mov    %eax,%r12d
mov    %rbp,(%rsp)
xor    %r13d,%r13d
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <sqlite3_column_name@plt>
lea    0xe5b(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
cmp    $0x2,%r12d
jl     11fd <stmt_stdout+0x9d>
mov    $0x1,%ebp
lea    0xe3f(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    $0x9,%edi
call   1030 <putchar@plt>
lea    0x1(%rbp),%r14d
mov    %rbx,%rdi
mov    %ebp,%esi
call   1040 <sqlite3_column_name@plt>
mov    %r15,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14d,%ebp
cmp    %r14d,%r12d
jne    11d0 <stmt_stdout+0x70>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %rbx,%rdi
xor    %esi,%esi
call   1080 <sql_step@plt>
mov    0x2dc8(%rip),%rcx
cmp    (%rcx),%eax
jne    12c7 <stmt_stdout+0x167>
lea    0xdd9(%rip),%r15
xor    %r13d,%r13d
jmp    1253 <stmt_stdout+0xf3>
nopl   0x0(%rax)
add    $0x1,%r13d
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %rbx,%rdi
xor    %esi,%esi
call   1080 <sql_step@plt>
mov    0x2d91(%rip),%rcx
cmp    (%rcx),%eax
jne    12c7 <stmt_stdout+0x167>
mov    %rbx,%rdi
xor    %esi,%esi
call   1070 <sqlite3_column_text@plt>
mov    %r15,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
cmp    $0x2,%r12d
jl     1230 <stmt_stdout+0xd0>
mov    $0x1,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
mov    $0x9,%edi
call   1030 <putchar@plt>
lea    0x1(%rbp),%r14d
mov    %rbx,%rdi
mov    %ebp,%esi
call   1070 <sqlite3_column_text@plt>
mov    %r15,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14d,%ebp
cmp    %r14d,%r12d
jne    1280 <stmt_stdout+0x120>
jmp    1230 <stmt_stdout+0xd0>
mov    %rbx,%rdi
xor    %esi,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1080 <sql_step@plt>
mov    (%rsp),%rcx
test   %rcx,%rcx
je     12d3 <stmt_stdout+0x173>
mov    %r13d,(%rcx)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@.str.1 = [2 x i8] c"\09\00"
@.str.2 = [2 x i8] c"\0A\00"
@SQLITE_ROW = global i32 0
define i32 @stmt_stdout(i32* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32* %0, i32** %4
store i32* %1, i32** %5
store i32 0, i32* %7
%10 = load i32*, i32** %4
%11 = icmp eq i32* %10, null
br i1 %11, label %16, label %12
12: ; preds = %2
%13 = load i32*, i32** %4
%14 = call i32 @sqlite3_column_count(i32* %13)
store i32 %14, i32* %6
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %12, %2
%17 = load i32*, i32** %4
%18 = call i32 @sql_step(i32* %17, i32 0)
store i32 %18, i32* %3
br label %73
19: ; preds = %12
store i32 0, i32* %9
br label %20
20: ; preds = %32, %19
%21 = load i32*, i32** %4
%22 = load i32, i32* %9
%23 = add nsw i32 %22, 1
store i32 %23, i32* %9
%24 = call i8* @sqlite3_column_name(i32* %21, i32 %22)
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %24)
%26 = load i32, i32* %9
%27 = load i32, i32* %6
%28 = icmp slt i32 %26, %27
br i1 %28, label %29, label %31
29: ; preds = %20
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %31
31: ; preds = %29, %20
br label %32
32: ; preds = %31
%33 = load i32, i32* %9
%34 = load i32, i32* %6
%35 = icmp slt i32 %33, %34
br i1 %35, label %20, label %36
36: ; preds = %32
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %38
38: ; preds = %63, %36
%39 = load i32*, i32** %4
%40 = call i32 @sql_step(i32* %39, i32 0)
store i32 %40, i32* %8
%41 = load i32, i32* @SQLITE_ROW
%42 = icmp eq i32 %40, %41
br i1 %42, label %43, label %65
43: ; preds = %38
store i32 0, i32* %9
%44 = load i32, i32* %7
%45 = add nsw i32 %44, 1
store i32 %45, i32* %7
br label %46
46: ; preds = %59, %43
%47 = load i32*, i32** %4
%48 = load i32, i32* %9
%49 = add nsw i32 %48, 1
store i32 %49, i32* %9
%50 = call i64 @sqlite3_column_text(i32* %47, i32 %48)
%51 = inttoptr i64 %50 to i8*
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %51)
%53 = load i32, i32* %9
%54 = load i32, i32* %6
%55 = icmp slt i32 %53, %54
br i1 %55, label %56, label %58
56: ; preds = %46
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %58
58: ; preds = %56, %46
br label %59
59: ; preds = %58
%60 = load i32, i32* %9
%61 = load i32, i32* %6
%62 = icmp slt i32 %60, %61
br i1 %62, label %46, label %63
63: ; preds = %59
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %38
65: ; preds = %38
%66 = load i32*, i32** %5
%67 = icmp ne i32* %66, null
br i1 %67, label %68, label %71
68: ; preds = %65
%69 = load i32, i32* %7
%70 = load i32*, i32** %5
store i32 %69, i32* %70
br label %71
71: ; preds = %68, %65
%72 = load i32, i32* %8
store i32 %72, i32* %3
br label %73
73: ; preds = %71, %16
%74 = load i32, i32* %3
ret i32 %74
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@SQLITE_ROW = global i32 0
define i32 @stmt_stdout(i32* %0, i32* writeonly %1) {
%3 = icmp eq i32* %0, null
br i1 %3, label %11, label %4
4: ; preds = %2
%5 = tail call i32 @sqlite3_column_count(i32* %0)
%6 = icmp eq i32 %5, 0
br i1 %6, label %11, label %7
7: ; preds = %4
%8 = tail call i8* @sqlite3_column_name(i32* %0, i32 0)
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = icmp sgt i32 %5, 1
br i1 %10, label %13, label %20
11: ; preds = %4, %2
%12 = tail call i32 @sql_step(i32* %0, i32 0)
br label %49
13: ; preds = %7, %13
%14 = phi i32 [ %16, %13 ], [ 1, %7 ]
%15 = tail call i32 @putchar(i32 9)
%16 = add nuw nsw i32 %14, 1
%17 = tail call i8* @sqlite3_column_name(i32* %0, i32 %14)
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = icmp eq i32 %16, %5
br i1 %19, label %20, label %13
20: ; preds = %13, %7
%21 = tail call i32 @putchar(i32 10)
%22 = tail call i32 @sql_step(i32* %0, i32 0)
%23 = load i32, i32* @SQLITE_ROW
%24 = icmp eq i32 %22, %23
br i1 %24, label %25, label %44
25: ; preds = %20, %39
%26 = phi i32 [ %27, %39 ], [ 0, %20 ]
%27 = add nuw nsw i32 %26, 1
%28 = tail call i64 @sqlite3_column_text(i32* %0, i32 0)
%29 = inttoptr i64 %28 to i8*
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %29)
br i1 %10, label %31, label %39
31: ; preds = %25, %31
%32 = phi i32 [ %34, %31 ], [ 1, %25 ]
%33 = tail call i32 @putchar(i32 9)
%34 = add nuw nsw i32 %32, 1
%35 = tail call i64 @sqlite3_column_text(i32* %0, i32 %32)
%36 = inttoptr i64 %35 to i8*
%37 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %36)
%38 = icmp eq i32 %34, %5
br i1 %38, label %39, label %31
39: ; preds = %31, %25
%40 = tail call i32 @putchar(i32 10)
%41 = tail call i32 @sql_step(i32* %0, i32 0)
%42 = load i32, i32* @SQLITE_ROW
%43 = icmp eq i32 %41, %42
br i1 %43, label %25, label %44
44: ; preds = %39, %20
%45 = phi i32 [ 0, %20 ], [ %27, %39 ]
%46 = phi i32 [ %22, %20 ], [ %41, %39 ]
%47 = icmp eq i32* %1, null
br i1 %47, label %49, label %48
48: ; preds = %44
store i32 %45, i32* %1
br label %49
49: ; preds = %44, %48, %11
%50 = phi i32 [ %12, %11 ], [ %46, %48 ], [ %46, %44 ]
ret i32 %50
}