#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*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ sqlite3_close(int /*<<< orphan*/ *);
char *sqlite3_errmsg(int /*<<< orphan*/ *);
int /*<<< orphan*/ sqlite3_free(char *);
char *sqlite3_malloc(int);
int sqlite3_msize(char *);
int sqlite3_open(char *, int /*<<< orphan*/ **);
int /*<<< orphan*/ stderr;
void validCode() {
  sqlite3 *db;
  int rc = sqlite3_open("/db", &db);
  if (rc != SQLITE_OK) {
    fprintf(stderr, "Error opening sqlite3 db: %s\n", sqlite3_errmsg(db));
    sqlite3_close(db);
  } else {
    sqlite3_close(db);
  }
  {
    char *buf = sqlite3_malloc(10);
    printf("size: %ull\n", sqlite3_msize(buf));
    sqlite3_free(buf);
  }
}


x86 assembly (clang, -O0):
<validCode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xe71(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1030 <sqlite3_open@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    0x2e43(%rip),%rcx
cmp    (%rcx),%eax
je     11e2 <validCode+0x62>
mov    0x2e24(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <sqlite3_errmsg@plt>
mov    -0x1c(%rbp),%edi
mov    %rax,%rdx
lea    0xe35(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x8(%rbp),%rdi
call   1070 <sqlite3_close@plt>
jmp    11eb <validCode+0x6b>
mov    -0x8(%rbp),%rdi
call   1070 <sqlite3_close@plt>
mov    $0xa,%edi
call   10a0 <sqlite3_malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1080 <sqlite3_msize@plt>
mov    %eax,%esi
lea    0xe17(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1090 <sqlite3_free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<validCode>:
push   %rbx
sub    $0x10,%rsp
lea    0xe74(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1030 <sqlite3_open@plt>
mov    0x2e4b(%rip),%rcx
cmp    (%rcx),%eax
je     11c5 <validCode+0x45>
mov    0x2e30(%rip),%rax
mov    (%rax),%ebx
mov    0x8(%rsp),%rdi
call   1050 <sqlite3_errmsg@plt>
lea    0xe49(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1060 <fprintf@plt>
mov    0x8(%rsp),%rdi
call   1070 <sqlite3_close@plt>
mov    $0xa,%edi
call   10a0 <sqlite3_malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1080 <sqlite3_msize@plt>
lea    0xe37(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1090 <sqlite3_free@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [4 x i8] c"/db\00"
@SQLITE_OK = global i32 0
@stderr = global i32 0
@.str.1 = [30 x i8] c"Error opening sqlite3 db: %s\0A\00"
@.str.2 = [12 x i8] c"size: %ull\0A\00"
define void @validCode() {
%1 = alloca i32*
%2 = alloca i32
%3 = alloca i8*
%4 = call i32 @sqlite3_open(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32** %1)
store i32 %4, i32* %2
%5 = load i32, i32* %2
%6 = load i32, i32* @SQLITE_OK
%7 = icmp ne i32 %5, %6
br i1 %7, label %8, label %15
8: ; preds = %0
%9 = load i32, i32* @stderr
%10 = load i32*, i32** %1
%11 = call i8* @sqlite3_errmsg(i32* %10)
%12 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %11)
%13 = load i32*, i32** %1
%14 = call i32 @sqlite3_close(i32* %13)
br label %18
15: ; preds = %0
%16 = load i32*, i32** %1
%17 = call i32 @sqlite3_close(i32* %16)
br label %18
18: ; preds = %15, %8
%19 = call i8* @sqlite3_malloc(i32 10)
store i8* %19, i8** %3
%20 = load i8*, i8** %3
%21 = call i32 @sqlite3_msize(i8* %20)
%22 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %21)
%23 = load i8*, i8** %3
%24 = call i32 @sqlite3_free(i8* %23)
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"/db\00"
@SQLITE_OK = global i32 0
@stderr = global i32 0
@.str.1 = [30 x i8] c"Error opening sqlite3 db: %s\0A\00"
@.str.2 = [12 x i8] c"size: %ull\0A\00"
define void @validCode() {
%1 = alloca i32*
%2 = bitcast i32** %1 to i8*
%3 = call i32 @sqlite3_open(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32** %1)
%4 = load i32, i32* @SQLITE_OK
%5 = icmp eq i32 %3, %4
br i1 %5, label %11, label %6
6: ; preds = %0
%7 = load i32, i32* @stderr
%8 = load i32*, i32** %1
%9 = call i8* @sqlite3_errmsg(i32* %8)
%10 = call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %9)
br label %11
11: ; preds = %0, %6
%12 = load i32*, i32** %1
%13 = call i32 @sqlite3_close(i32* %12)
%14 = call i8* @sqlite3_malloc(i32 10)
%15 = call i32 @sqlite3_msize(i8* %14)
%16 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %15)
%17 = call i32 @sqlite3_free(i8* %14)
ret void
}