#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*/ sprintf(char *, char *, char const *, char const *);
int sqlite3_exec(int /*<<< orphan*/ *, char *, int /*<<< orphan*/ *,
                 int /*<<< orphan*/ *, char **);
int sqlite_find_user(int /*<<< orphan*/ *, char const *, char *);
int /*<<< orphan*/ stderr;
int sqlite_insert_user(sqlite3 *db, const char *name, const char *passwd) {
  int ret = 0;
  char password[128];
  char sql[512];
  char *errmsg;
  ret = sqlite_find_user(db, name, password);
  if (ret >= 1) {
    goto exit;
  }
  sprintf(sql, "insert into users values('%s','%s');", name, passwd);
  ret = sqlite3_exec(db, sql, NULL, NULL, &errmsg);
  if (ret != SQLITE_OK) {
    fprintf(stderr, "Fail to sqlite3_exec : %s\n", errmsg);
    ret = -1;
    goto exit;
  }
  ret = 0;
exit:
  return ret;
}


x86 assembly (clang, -O0):
<sqlite_insert_user>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2b0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    -0xa0(%rbp),%rdx
call   1040 <sqlite_find_user@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x1,-0x1c(%rbp)
jl     1184 <sqlite_insert_user+0x44>
jmp    1201 <sqlite_insert_user+0xc1>
lea    -0x2a0(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xe66(%rip),%rsi
call   1060 <sprintf@plt>
mov    -0x8(%rbp),%rdi
lea    -0x2a0(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x2a8(%rbp),%r8
mov    %rcx,%rdx
call   1030 <sqlite3_exec@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    0x2e1e(%rip),%rcx
cmp    (%rcx),%eax
je     11fa <sqlite_insert_user+0xba>
mov    0x2dff(%rip),%rax
mov    (%rax),%edi
mov    -0x2a8(%rbp),%rdx
lea    0xe3c(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x1c(%rbp)
jmp    1201 <sqlite_insert_user+0xc1>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x2b0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sqlite_insert_user>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x290,%rsp
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%r14
lea    0x10(%rsp),%rdx
call   1040 <sqlite_find_user@plt>
mov    %eax,%ebx
test   %eax,%eax
jg     11c6 <sqlite_insert_user+0x86>
lea    0xe90(%rip),%rsi
lea    0x90(%rsp),%r13
mov    %r13,%rdi
mov    %r12,%rdx
mov    %r15,%rcx
call   1060 <sprintf@plt>
xor    %ebx,%ebx
lea    0x8(%rsp),%r8
mov    %r14,%rdi
mov    %r13,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
call   1030 <sqlite3_exec@plt>
mov    0x2e45(%rip),%rcx
cmp    (%rcx),%eax
je     11c6 <sqlite_insert_user+0x86>
mov    0x2e2a(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rsp),%rdx
lea    0xe69(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x290,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [37 x i8] c"insert into users values('%s','%s');\00"
@SQLITE_OK = global i32 0
@stderr = global i32 0
@.str.1 = [27 x i8] c"Fail to sqlite3_exec : %s\0A\00"
define i32 @sqlite_insert_user(i32* %0, i8* %1, i8* %2) {
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca [128 x i8]
%9 = alloca [512 x i8]
%10 = alloca i8*
store i32* %0, i32** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
store i32 0, i32* %7
%11 = load i32*, i32** %4
%12 = load i8*, i8** %5
%13 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%14 = call i32 @sqlite_find_user(i32* %11, i8* %12, i8* %13)
store i32 %14, i32* %7
%15 = load i32, i32* %7
%16 = icmp sge i32 %15, 1
br i1 %16, label %17, label %18
17: ; preds = %3
br label %34
18: ; preds = %3
%19 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%20 = load i8*, i8** %5
%21 = load i8*, i8** %6
%22 = call i32 @sprintf(i8* %19, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8* %20, i8* %21)
%23 = load i32*, i32** %4
%24 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%25 = call i32 @sqlite3_exec(i32* %23, i8* %24, i32* null, i32* null, i8** %10)
store i32 %25, i32* %7
%26 = load i32, i32* %7
%27 = load i32, i32* @SQLITE_OK
%28 = icmp ne i32 %26, %27
br i1 %28, label %29, label %33
29: ; preds = %18
%30 = load i32, i32* @stderr
%31 = load i8*, i8** %10
%32 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %31)
store i32 -1, i32* %7
br label %34
33: ; preds = %18
store i32 0, i32* %7
br label %34
34: ; preds = %33, %29, %17
%35 = load i32, i32* %7
ret i32 %35
}

LLVM IR (-O2):
@.str = [37 x i8] c"insert into users values('%s','%s');\00"
@SQLITE_OK = global i32 0
@stderr = global i32 0
@.str.1 = [27 x i8] c"Fail to sqlite3_exec : %s\0A\00"
define i32 @sqlite_insert_user(i32* %0, i8* %1, i8* %2) {
%4 = alloca [128 x i8]
%5 = alloca [512 x i8]
%6 = alloca i8*
%7 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%9 = bitcast i8** %6 to i8*
%10 = call i32 @sqlite_find_user(i32* %0, i8* %1, i8* %7)
%11 = icmp sgt i32 %10, 0
br i1 %11, label %21, label %12
12: ; preds = %3
%13 = call i32 @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8* %1, i8* %2)
%14 = call i32 @sqlite3_exec(i32* %0, i8* %8, i32* null, i32* null, i8** %6)
%15 = load i32, i32* @SQLITE_OK
%16 = icmp eq i32 %14, %15
br i1 %16, label %21, label %17
17: ; preds = %12
%18 = load i32, i32* @stderr
%19 = load i8*, i8** %6
%20 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %19)
br label %21
21: ; preds = %12, %3, %17
%22 = phi i32 [ %10, %3 ], [ -1, %17 ], [ 0, %12 ]
ret i32 %22
}