#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;
typedef int /*<<< orphan*/ sqlite3;

/* Variables and functions */
int LOG_ERR;
int LOG_INFO;
int /*<<< orphan*/ LOG_UPTO(int);
int SQLITE_DONE;
int /*<<< orphan*/ SQLITE_STATIC;
int /*<<< orphan*/ setlogmask(int /*<<< orphan*/);
int /*<<< orphan*/ sqlite3_bind_int(int /*<<< orphan*/ *, int, int);
int /*<<< orphan*/ sqlite3_bind_text(int /*<<< orphan*/ *, int, char *, int,
                                     int /*<<< orphan*/);
int /*<<< orphan*/ sqlite3_close(int /*<<< orphan*/ *);
int /*<<< orphan*/ sqlite3_errmsg(int /*<<< orphan*/ *);
int /*<<< orphan*/ sqlite3_finalize(int /*<<< orphan*/ *);
int sqlite3_open(char *, int /*<<< orphan*/ **);
int /*<<< orphan*/ sqlite3_prepare_v2(int /*<<< orphan*/ *, char *, int,
                                      int /*<<< orphan*/ **,
                                      int /*<<< orphan*/ *);
int sqlite3_step(int /*<<< orphan*/ *);
int /*<<< orphan*/ syslog(int, char *, ...);
int insert_request(int customer_id, char *transaction_id, char *card_number,
                   int amount) {
  sqlite3 *conn;
  sqlite3_stmt *res;
  int error = 0;
  int rec_count = 0;
  const char *errMSG;
  const char *tail;
  sqlite3_stmt *stmt;
  setlogmask(LOG_UPTO(LOG_INFO | LOG_ERR));
  error = sqlite3_open("purchase_service.db", &conn);
  if (error) {
    syslog(LOG_ERR, "[Validator Service]: Error can not open database...");
    return -1;
  }
  sqlite3_prepare_v2(conn,
                     "insert into requests (customer_id, transaction_id,       "
                     "                                        card_number, "
                     "amount)                         values (?1, ?2, ?3, ?4);",
                     -1, &stmt, NULL);
  sqlite3_bind_int(stmt, 1, customer_id);
  sqlite3_bind_text(stmt, 2, transaction_id, -1, SQLITE_STATIC);
  sqlite3_bind_text(stmt, 3, card_number, -1, SQLITE_STATIC);
  sqlite3_bind_int(stmt, 4, amount);
  int rc = sqlite3_step(stmt);
  if (rc != SQLITE_DONE) {
    syslog(LOG_ERR, "[Validator Service]: Error inserting data %s\n...",
           sqlite3_errmsg(conn));
    return -1;
  }
  syslog(LOG_INFO, "[Validator Service] new request inserted");
  sqlite3_finalize(stmt);
  sqlite3_close(conn);
  return 0;
}


x86 assembly (clang, -O0):
<insert_request>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
movl   $0x0,-0x34(%rbp)
movl   $0x0,-0x38(%rbp)
mov    0x2df5(%rip),%rax
mov    (%rax),%edi
mov    0x2ddc(%rip),%rax
or     (%rax),%edi
call   1030 <LOG_UPTO@plt>
mov    %eax,%edi
call   1090 <setlogmask@plt>
lea    0xe07(%rip),%rdi
lea    -0x28(%rbp),%rsi
call   1040 <sqlite3_open@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
je     1232 <insert_request+0x82>
mov    0x2daa(%rip),%rax
mov    (%rax),%edi
lea    0xdf5(%rip),%rsi
mov    $0x0,%al
call   10a0 <syslog@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1336 <insert_request+0x186>
mov    -0x28(%rbp),%rdi
lea    0xe0b(%rip),%rsi
mov    $0xffffffff,%edx
lea    -0x50(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%r8d
call   10d0 <sqlite3_prepare_v2@plt>
mov    -0x50(%rbp),%rdi
mov    -0x8(%rbp),%edx
mov    $0x1,%esi
call   1050 <sqlite3_bind_int@plt>
mov    -0x50(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    0x2d70(%rip),%rax
mov    (%rax),%r8d
mov    $0x2,%esi
mov    $0xffffffff,%ecx
call   10b0 <sqlite3_bind_text@plt>
mov    -0x50(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    0x2d4f(%rip),%rax
mov    (%rax),%r8d
mov    $0x3,%esi
mov    $0xffffffff,%ecx
call   10b0 <sqlite3_bind_text@plt>
mov    -0x50(%rbp),%rdi
mov    -0x1c(%rbp),%edx
mov    $0x4,%esi
call   1050 <sqlite3_bind_int@plt>
mov    -0x50(%rbp),%rdi
call   1070 <sqlite3_step@plt>
mov    %eax,-0x54(%rbp)
mov    -0x54(%rbp),%eax
mov    0x2d0e(%rip),%rcx
cmp    (%rcx),%eax
je     1306 <insert_request+0x156>
mov    0x2ce7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x58(%rbp)
mov    -0x28(%rbp),%rdi
call   1060 <sqlite3_errmsg@plt>
mov    -0x58(%rbp),%edi
mov    %eax,%edx
lea    0xdfc(%rip),%rsi
mov    $0x0,%al
call   10a0 <syslog@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1336 <insert_request+0x186>
mov    0x2cc3(%rip),%rax
mov    (%rax),%edi
lea    0xe0a(%rip),%rsi
mov    $0x0,%al
call   10a0 <syslog@plt>
mov    -0x50(%rbp),%rdi
call   10c0 <sqlite3_finalize@plt>
mov    -0x28(%rbp),%rdi
call   1080 <sqlite3_close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<insert_request>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %ecx,%r14d
mov    %rdx,%r15
mov    %rsi,%r12
mov    %edi,%ebp
mov    0x2e00(%rip),%rax
mov    0x2de9(%rip),%r13
mov    0x0(%r13),%edi
or     (%rax),%edi
call   1030 <LOG_UPTO@plt>
mov    %eax,%edi
call   1090 <setlogmask@plt>
lea    0xe10(%rip),%rdi
lea    0x10(%rsp),%rsi
call   1040 <sqlite3_open@plt>
test   %eax,%eax
je     121a <insert_request+0x6a>
mov    0x0(%r13),%edi
lea    0xe0b(%rip),%rsi
xor    %eax,%eax
call   10a0 <syslog@plt>
mov    $0xffffffff,%ebx
jmp    1301 <insert_request+0x151>
mov    0x10(%rsp),%rdi
lea    0xe22(%rip),%rsi
mov    $0xffffffff,%ebx
lea    0x8(%rsp),%rcx
mov    $0xffffffff,%edx
xor    %r8d,%r8d
call   10d0 <sqlite3_prepare_v2@plt>
mov    0x8(%rsp),%rdi
mov    $0x1,%esi
mov    %ebp,%edx
call   1050 <sqlite3_bind_int@plt>
mov    0x8(%rsp),%rdi
mov    0x2d86(%rip),%rbp
mov    0x0(%rbp),%r8d
mov    $0x2,%esi
mov    %r12,%rdx
mov    $0xffffffff,%ecx
call   10b0 <sqlite3_bind_text@plt>
mov    0x8(%rsp),%rdi
mov    0x0(%rbp),%r8d
mov    $0x3,%esi
mov    %r15,%rdx
mov    $0xffffffff,%ecx
call   10b0 <sqlite3_bind_text@plt>
mov    0x8(%rsp),%rdi
mov    $0x4,%esi
mov    %r14d,%edx
call   1050 <sqlite3_bind_int@plt>
mov    0x8(%rsp),%rdi
call   1070 <sqlite3_step@plt>
mov    0x2d2a(%rip),%rcx
cmp    (%rcx),%eax
jne    12e1 <insert_request+0x131>
mov    0x2d17(%rip),%rax
mov    (%rax),%edi
lea    0xe5e(%rip),%rsi
xor    %eax,%eax
call   10a0 <syslog@plt>
mov    0x8(%rsp),%rdi
call   10c0 <sqlite3_finalize@plt>
mov    0x10(%rsp),%rdi
call   1080 <sqlite3_close@plt>
xor    %ebx,%ebx
jmp    1301 <insert_request+0x151>
mov    0x0(%r13),%ebp
mov    0x10(%rsp),%rdi
call   1060 <sqlite3_errmsg@plt>
lea    0xdf9(%rip),%rsi
mov    %ebp,%edi
mov    %eax,%edx
xor    %eax,%eax
call   10a0 <syslog@plt>
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@LOG_INFO = global i32 0
@LOG_ERR = global i32 0
@.str = [20 x i8] c"purchase_service.db\00"
@.str.1 = [52 x i8] c"[Validator Service]: Error can not open database...\00"
@.str.2 = [167 x i8] c"insert into requests (customer_id, transaction_id, card_number, amount) values (?1, ?2, ?3, ?4);\00"
@SQLITE_STATIC = global i32 0
@SQLITE_DONE = global i32 0
@.str.3 = [49 x i8] c"[Validator Service]: Error inserting data %s\0A...\00"
@.str.4 = [41 x i8] c"[Validator Service] new request inserted\00"
define i32 @insert_request(i32 %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32*
%11 = alloca i32*
%12 = alloca i32
%13 = alloca i32
%14 = alloca i8*
%15 = alloca i8*
%16 = alloca i32*
%17 = alloca i32
store i32 %0, i32* %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i32 %3, i32* %9
store i32 0, i32* %12
store i32 0, i32* %13
%18 = load i32, i32* @LOG_INFO
%19 = load i32, i32* @LOG_ERR
%20 = or i32 %18, %19
%21 = call i32 @LOG_UPTO(i32 %20)
%22 = call i32 @setlogmask(i32 %21)
%23 = call i32 @sqlite3_open(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32** %10)
store i32 %23, i32* %12
%24 = load i32, i32* %12
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %4
%27 = load i32, i32* @LOG_ERR
%28 = call i32 (i32, i8*, ...) @syslog(i32 %27, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %5
br label %63
29: ; preds = %4
%30 = load i32*, i32** %10
%31 = call i32 @sqlite3_prepare_v2(i32* %30, i8* getelementptr inbounds ([167 x i8], [167 x i8]* @.str.2, i64 0, i64 0), i32 -1, i32** %16, i32* null)
%32 = load i32*, i32** %16
%33 = load i32, i32* %6
%34 = call i32 @sqlite3_bind_int(i32* %32, i32 1, i32 %33)
%35 = load i32*, i32** %16
%36 = load i8*, i8** %7
%37 = load i32, i32* @SQLITE_STATIC
%38 = call i32 @sqlite3_bind_text(i32* %35, i32 2, i8* %36, i32 -1, i32 %37)
%39 = load i32*, i32** %16
%40 = load i8*, i8** %8
%41 = load i32, i32* @SQLITE_STATIC
%42 = call i32 @sqlite3_bind_text(i32* %39, i32 3, i8* %40, i32 -1, i32 %41)
%43 = load i32*, i32** %16
%44 = load i32, i32* %9
%45 = call i32 @sqlite3_bind_int(i32* %43, i32 4, i32 %44)
%46 = load i32*, i32** %16
%47 = call i32 @sqlite3_step(i32* %46)
store i32 %47, i32* %17
%48 = load i32, i32* %17
%49 = load i32, i32* @SQLITE_DONE
%50 = icmp ne i32 %48, %49
br i1 %50, label %51, label %56
51: ; preds = %29
%52 = load i32, i32* @LOG_ERR
%53 = load i32*, i32** %10
%54 = call i32 @sqlite3_errmsg(i32* %53)
%55 = call i32 (i32, i8*, ...) @syslog(i32 %52, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.3, i64 0, i64 0), i32 %54)
store i32 -1, i32* %5
br label %63
56: ; preds = %29
%57 = load i32, i32* @LOG_INFO
%58 = call i32 (i32, i8*, ...) @syslog(i32 %57, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.4, i64 0, i64 0))
%59 = load i32*, i32** %16
%60 = call i32 @sqlite3_finalize(i32* %59)
%61 = load i32*, i32** %10
%62 = call i32 @sqlite3_close(i32* %61)
store i32 0, i32* %5
br label %63
63: ; preds = %56, %51, %26
%64 = load i32, i32* %5
ret i32 %64
}

LLVM IR (-O2):
@LOG_INFO = global i32 0
@LOG_ERR = global i32 0
@.str = [20 x i8] c"purchase_service.db\00"
@.str.1 = [52 x i8] c"[Validator Service]: Error can not open database...\00"
@.str.2 = [167 x i8] c"insert into requests (customer_id, transaction_id, card_number, amount) values (?1, ?2, ?3, ?4);\00"
@SQLITE_STATIC = global i32 0
@SQLITE_DONE = global i32 0
@.str.3 = [49 x i8] c"[Validator Service]: Error inserting data %s\0A...\00"
@.str.4 = [41 x i8] c"[Validator Service] new request inserted\00"
define i32 @insert_request(i32 %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca i32*
%6 = alloca i32*
%7 = bitcast i32** %5 to i8*
%8 = bitcast i32** %6 to i8*
%9 = load i32, i32* @LOG_INFO
%10 = load i32, i32* @LOG_ERR
%11 = or i32 %10, %9
%12 = tail call i32 @LOG_UPTO(i32 %11)
%13 = tail call i32 @setlogmask(i32 %12)
%14 = call i32 @sqlite3_open(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32** %5)
%15 = icmp eq i32 %14, 0
br i1 %15, label %19, label %16
16: ; preds = %4
%17 = load i32, i32* @LOG_ERR
%18 = call i32 (i32, i8*, ...) @syslog(i32 %17, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0))
br label %48
19: ; preds = %4
%20 = load i32*, i32** %5
%21 = call i32 @sqlite3_prepare_v2(i32* %20, i8* getelementptr inbounds ([167 x i8], [167 x i8]* @.str.2, i64 0, i64 0), i32 -1, i32** %6, i32* null)
%22 = load i32*, i32** %6
%23 = call i32 @sqlite3_bind_int(i32* %22, i32 1, i32 %0)
%24 = load i32*, i32** %6
%25 = load i32, i32* @SQLITE_STATIC
%26 = call i32 @sqlite3_bind_text(i32* %24, i32 2, i8* %1, i32 -1, i32 %25)
%27 = load i32*, i32** %6
%28 = load i32, i32* @SQLITE_STATIC
%29 = call i32 @sqlite3_bind_text(i32* %27, i32 3, i8* %2, i32 -1, i32 %28)
%30 = load i32*, i32** %6
%31 = call i32 @sqlite3_bind_int(i32* %30, i32 4, i32 %3)
%32 = load i32*, i32** %6
%33 = call i32 @sqlite3_step(i32* %32)
%34 = load i32, i32* @SQLITE_DONE
%35 = icmp eq i32 %33, %34
br i1 %35, label %41, label %36
36: ; preds = %19
%37 = load i32, i32* @LOG_ERR
%38 = load i32*, i32** %5
%39 = call i32 @sqlite3_errmsg(i32* %38)
%40 = call i32 (i32, i8*, ...) @syslog(i32 %37, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.3, i64 0, i64 0), i32 %39)
br label %48
41: ; preds = %19
%42 = load i32, i32* @LOG_INFO
%43 = call i32 (i32, i8*, ...) @syslog(i32 %42, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.4, i64 0, i64 0))
%44 = load i32*, i32** %6
%45 = call i32 @sqlite3_finalize(i32* %44)
%46 = load i32*, i32** %5
%47 = call i32 @sqlite3_close(i32* %46)
br label %48
48: ; preds = %36, %41, %16
%49 = phi i32 [ -1, %16 ], [ -1, %36 ], [ 0, %41 ]
ret i32 %49
}