#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 SQLITE_OK;
int /*<<< orphan*/ printf(char *, char const *, ...);
int sqlite3_exec(int /*<<< orphan*/ *, char const *, int /*<<< orphan*/ *,
                 int /*<<< orphan*/ *, char **);
int exec_SQL(sqlite3 *db, const char *sql) {
  char *errmsg = NULL;
  int rc = sqlite3_exec(db, sql, NULL, NULL, &errmsg);
  if (rc != SQLITE_OK) {
    printf("execute sql \"%s\" error:%s\n", sql, errmsg);
    return -1;
  } else {
    printf("execute sql \"%s\" success\n", sql);
    return 0;
  }
  return 0;
}


x86 assembly (clang, -O0):
<exec_SQL>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x20(%rbp),%r8
mov    %rcx,%rdx
call   1030 <sqlite3_exec@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    0x2e8b(%rip),%rcx
cmp    (%rcx),%eax
je     1187 <exec_SQL+0x67>
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
lea    0xe8c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a0 <exec_SQL+0x80>
mov    -0x18(%rbp),%rsi
lea    0xe89(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<exec_SQL>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
movq   $0x0,(%rsp)
xor    %r14d,%r14d
mov    %rsp,%r8
xor    %edx,%edx
xor    %ecx,%ecx
call   1030 <sqlite3_exec@plt>
mov    0x2ea3(%rip),%rcx
cmp    (%rcx),%eax
jne    115c <exec_SQL+0x3c>
lea    0xecb(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1177 <exec_SQL+0x57>
mov    (%rsp),%rdx
lea    0xe99(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@SQLITE_OK = global i32 0
@.str = [27 x i8] c"execute sql \22%s\22 error:%s\0A\00"
@.str.1 = [26 x i8] c"execute sql \22%s\22 success\0A\00"
define i32 @exec_SQL(i32* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
store i32* %0, i32** %4
store i8* %1, i8** %5
store i8* null, i8** %6
%8 = load i32*, i32** %4
%9 = load i8*, i8** %5
%10 = call i32 @sqlite3_exec(i32* %8, i8* %9, i32* null, i32* null, i8** %6)
store i32 %10, i32* %7
%11 = load i32, i32* %7
%12 = load i32, i32* @SQLITE_OK
%13 = icmp ne i32 %11, %12
br i1 %13, label %14, label %18
14: ; preds = %2
%15 = load i8*, i8** %5
%16 = load i8*, i8** %6
%17 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %15, i8* %16)
store i32 -1, i32* %3
br label %21
18: ; preds = %2
%19 = load i8*, i8** %5
%20 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %19)
store i32 0, i32* %3
br label %21
21: ; preds = %18, %14
%22 = load i32, i32* %3
ret i32 %22
}

LLVM IR (-O2):
@SQLITE_OK = global i32 0
@.str = [27 x i8] c"execute sql \22%s\22 error:%s\0A\00"
@.str.1 = [26 x i8] c"execute sql \22%s\22 success\0A\00"
define i32 @exec_SQL(i32* %0, i8* %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%5 = call i32 @sqlite3_exec(i32* %0, i8* %1, i32* null, i32* null, i8** %3)
%6 = load i32, i32* @SQLITE_OK
%7 = icmp eq i32 %5, %6
br i1 %7, label %11, label %8
8: ; preds = %2
%9 = load i8*, i8** %3
%10 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %1, i8* %9)
br label %13
11: ; preds = %2
%12 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %1)
br label %13
13: ; preds = %11, %8
%14 = phi i32 [ -1, %8 ], [ 0, %11 ]
ret i32 %14
}