#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*/ printf(char *);
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));
    printf("Error insert\n");
    return -1;
  }
  syslog(LOG_INFO, "[Validator Service] new request inserted");
  printf("inserto bien\n");
  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    0x2de5(%rip),%rax
mov    (%rax),%edi
mov    0x2dcc(%rip),%rax
or     (%rax),%edi
call   1030 <LOG_UPTO@plt>
mov    %eax,%edi
call   10a0 <setlogmask@plt>
lea    0xdf7(%rip),%rdi
lea    -0x28(%rbp),%rsi
call   1040 <sqlite3_open@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
je     1242 <insert_request+0x82>
mov    0x2d9a(%rip),%rax
mov    (%rax),%edi
lea    0xde5(%rip),%rsi
mov    $0x0,%al
call   10b0 <syslog@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    135e <insert_request+0x19e>
mov    -0x28(%rbp),%rdi
lea    0xdfb(%rip),%rsi
mov    $0xffffffff,%edx
lea    -0x50(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%r8d
call   10e0 <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    0x2d60(%rip),%rax
mov    (%rax),%r8d
mov    $0x2,%esi
mov    $0xffffffff,%ecx
call   10c0 <sqlite3_bind_text@plt>
mov    -0x50(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    0x2d3f(%rip),%rax
mov    (%rax),%r8d
mov    $0x3,%esi
mov    $0xffffffff,%ecx
call   10c0 <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   1080 <sqlite3_step@plt>
mov    %eax,-0x54(%rbp)
mov    -0x54(%rbp),%eax
mov    0x2cfe(%rip),%rcx
cmp    (%rcx),%eax
je     1322 <insert_request+0x162>
mov    0x2cd7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x58(%rbp)
mov    -0x28(%rbp),%rdi
call   1070 <sqlite3_errmsg@plt>
mov    -0x58(%rbp),%edi
mov    %eax,%edx
lea    0xdec(%rip),%rsi
mov    $0x0,%al
call   10b0 <syslog@plt>
lea    0xe0f(%rip),%rdi
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    135e <insert_request+0x19e>
mov    0x2ca7(%rip),%rax
mov    (%rax),%edi
lea    0xdfc(%rip),%rsi
mov    $0x0,%al
call   10b0 <syslog@plt>
lea    0xe17(%rip),%rdi
call   1060 <printf@plt>
mov    -0x50(%rbp),%rdi
call   10d0 <sqlite3_finalize@plt>
mov    -0x28(%rbp),%rdi
call   1090 <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    0x2df0(%rip),%rax
mov    0x2dd9(%rip),%r13
mov    0x0(%r13),%edi
or     (%rax),%edi
call   1040 <LOG_UPTO@plt>
mov    %eax,%edi
call   10a0 <setlogmask@plt>
lea    0xe00(%rip),%rdi
lea    0x10(%rsp),%rsi
call   1050 <sqlite3_open@plt>
test   %eax,%eax
je     122a <insert_request+0x6a>
mov    0x0(%r13),%edi
lea    0xdfb(%rip),%rsi
xor    %eax,%eax
call   10b0 <syslog@plt>
mov    $0xffffffff,%ebx
jmp    1329 <insert_request+0x169>
mov    0x10(%rsp),%rdi
lea    0xe12(%rip),%rsi
mov    $0xffffffff,%ebx
lea    0x8(%rsp),%rcx
mov    $0xffffffff,%edx
xor    %r8d,%r8d
call   10e0 <sqlite3_prepare_v2@plt>
mov    0x8(%rsp),%rdi
mov    $0x1,%esi
mov    %ebp,%edx
call   1060 <sqlite3_bind_int@plt>
mov    0x8(%rsp),%rdi
mov    0x2d76(%rip),%rbp
mov    0x0(%rbp),%r8d
mov    $0x2,%esi
mov    %r12,%rdx
mov    $0xffffffff,%ecx
call   10c0 <sqlite3_bind_text@plt>
mov    0x8(%rsp),%rdi
mov    0x0(%rbp),%r8d
mov    $0x3,%esi
mov    %r15,%rdx
mov    $0xffffffff,%ecx
call   10c0 <sqlite3_bind_text@plt>
mov    0x8(%rsp),%rdi
mov    $0x4,%esi
mov    %r14d,%edx
call   1060 <sqlite3_bind_int@plt>
mov    0x8(%rsp),%rdi
call   1080 <sqlite3_step@plt>
mov    0x2d1a(%rip),%rcx
cmp    (%rcx),%eax
jne    12fd <insert_request+0x13d>
mov    0x2d07(%rip),%rax
mov    (%rax),%edi
lea    0xe4e(%rip),%rsi
xor    %eax,%eax
call   10b0 <syslog@plt>
lea    0xe69(%rip),%rdi
call   1030 <puts@plt>
mov    0x8(%rsp),%rdi
call   10d0 <sqlite3_finalize@plt>
mov    0x10(%rsp),%rdi
call   1090 <sqlite3_close@plt>
xor    %ebx,%ebx
jmp    1329 <insert_request+0x169>
mov    0x0(%r13),%ebp
mov    0x10(%rsp),%rdi
call   1070 <sqlite3_errmsg@plt>
lea    0xddd(%rip),%rsi
mov    %ebp,%edi
mov    %eax,%edx
xor    %eax,%eax
call   10b0 <syslog@plt>
lea    0xe32(%rip),%rdi
call   1030 <puts@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 = [14 x i8] c"Error insert\0A\00"
@.str.5 = [41 x i8] c"[Validator Service] new request inserted\00"
@.str.6 = [14 x i8] c"inserto bien\0A\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 %65
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 %57
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)
%56 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
store i32 -1, i32* %5
br label %65
57: ; preds = %29
%58 = load i32, i32* @LOG_INFO
%59 = call i32 (i32, i8*, ...) @syslog(i32 %58, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.5, i64 0, i64 0))
%60 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0))
%61 = load i32*, i32** %16
%62 = call i32 @sqlite3_finalize(i32* %61)
%63 = load i32*, i32** %10
%64 = call i32 @sqlite3_close(i32* %63)
store i32 0, i32* %5
br label %65
65: ; preds = %57, %51, %26
%66 = load i32, i32* %5
ret i32 %66
}

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.5 = [41 x i8] c"[Validator Service] new request inserted\00"
@str = [13 x i8] c"inserto bien\00"
@str.7 = [13 x i8] c"Error insert\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 %50
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 %42, 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)
%41 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.7, i64 0, i64 0))
br label %50
42: ; preds = %19
%43 = load i32, i32* @LOG_INFO
%44 = call i32 (i32, i8*, ...) @syslog(i32 %43, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.5, i64 0, i64 0))
%45 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
%46 = load i32*, i32** %6
%47 = call i32 @sqlite3_finalize(i32* %46)
%48 = load i32*, i32** %5
%49 = call i32 @sqlite3_close(i32* %48)
br label %50
50: ; preds = %36, %42, %16
%51 = phi i32 [ -1, %16 ], [ -1, %36 ], [ 0, %42 ]
ret i32 %51
}