#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 /*<<< orphan*/ LOG_ERR;
int SQLITE_OK;
int /*<<< orphan*/ sprintf(char *, char *, char *, char *, char *, char *,
                           char *, char *, char *, int, int, int,
                           unsigned long long, char *, char *);
int /*<<< orphan*/ sqlite3_close(int /*<<< orphan*/ *);
int /*<<< orphan*/ sqlite3_errmsg(int /*<<< orphan*/ *);
int sqlite3_exec(int /*<<< orphan*/ *, char *, int /*<<< orphan*/ *,
                 int /*<<< orphan*/, char **);
int sqlite3_open(char *, int /*<<< orphan*/ **);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *, char *, ...);
int add_entry(int country_code, int area_code, unsigned long long number,
              char *name, char *reason, int priority, int listflag) {
  if (priority < -999 || 0 == country_code || 0 == area_code || 0 == number) {
    syslog(LOG_ERR, "[%s] Please fill out the obligation fields.",
           "phone-firewall");
    return -1;
  }
  char *listname = (0x02 == listflag) ? "whitelist" : "blacklist";
  sqlite3 *db;
  char *errMsg = 0;
  char stmt[1024];
  int rc;
  rc = sqlite3_open("db/phonefirewall.db", &db);
  if (rc) {
    syslog(LOG_ERR, "[%s] Can't open database: %s", "phone-firewall",
           sqlite3_errmsg(db));
    sqlite3_close(db);
    return -1;
  }
  sprintf(stmt,
          "INSERT INTO %s (%s, %s, %s, %s, %s, %s) VALUES(%d, %d, %d, %lld, "
          "\"%s\", \"%s\")",
          listname, "priority", "countrycode", "areacode", "number", "name",
          "reason", priority, country_code, area_code, number, name, reason);
  rc = sqlite3_exec(db, stmt, NULL, 0, &errMsg);
  if (SQLITE_OK != rc) {
    syslog(LOG_ERR, "[%s] SQL error: %s", "phone-firewall", sqlite3_errmsg(db));
    sqlite3_close(db);
    return -1;
  }
  sqlite3_close(db);
  return 0;
}


x86 assembly (clang, -O0):
<add_entry>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x4a8,%rsp
mov    0x10(%rbp),%eax
mov    %edi,-0x30(%rbp)
mov    %esi,-0x34(%rbp)
mov    %rdx,-0x40(%rbp)
mov    %rcx,-0x48(%rbp)
mov    %r8,-0x50(%rbp)
mov    %r9d,-0x54(%rbp)
cmpl   $0xfffffc19,-0x54(%rbp)
jl     11bc <add_entry+0x5c>
xor    %eax,%eax
cmp    -0x30(%rbp),%eax
je     11bc <add_entry+0x5c>
xor    %eax,%eax
cmp    -0x34(%rbp),%eax
je     11bc <add_entry+0x5c>
xor    %eax,%eax
cmp    -0x40(%rbp),%rax
jne    11e6 <add_entry+0x86>
mov    0x2e0d(%rip),%rax
mov    (%rax),%edi
lea    0xe34(%rip),%rsi
lea    0xe59(%rip),%rdx
mov    $0x0,%al
call   1070 <syslog@plt>
movl   $0xffffffff,-0x2c(%rbp)
jmp    139b <add_entry+0x23b>
mov    0x10(%rbp),%esi
mov    $0x2,%edx
lea    0xe50(%rip),%rax
lea    0xe3f(%rip),%rcx
cmp    %esi,%edx
cmove  %rcx,%rax
mov    %rax,-0x60(%rbp)
movq   $0x0,-0x70(%rbp)
lea    0xe3a(%rip),%rdi
lea    -0x68(%rbp),%rsi
call   1040 <sqlite3_open@plt>
mov    %eax,-0x474(%rbp)
cmpl   $0x0,-0x474(%rbp)
je     127b <add_entry+0x11b>
mov    0x2d98(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x478(%rbp)
mov    -0x68(%rbp),%rdi
call   1050 <sqlite3_errmsg@plt>
mov    -0x478(%rbp),%edi
mov    %eax,%ecx
lea    0xe0b(%rip),%rsi
lea    0xdcd(%rip),%rdx
mov    $0x0,%al
call   1070 <syslog@plt>
mov    -0x68(%rbp),%rdi
call   1060 <sqlite3_close@plt>
movl   $0xffffffff,-0x2c(%rbp)
jmp    139b <add_entry+0x23b>
lea    -0x470(%rbp),%rdi
mov    -0x60(%rbp),%rdx
mov    -0x54(%rbp),%r15d
mov    -0x30(%rbp),%r14d
mov    -0x34(%rbp),%ebx
mov    -0x40(%rbp),%r11
mov    -0x48(%rbp),%r10
mov    -0x50(%rbp),%rax
mov    %rax,-0x480(%rbp)
lea    0xdd5(%rip),%rsi
lea    0xe1b(%rip),%rcx
lea    0xe1d(%rip),%r8
lea    0xe22(%rip),%r9
lea    0xe24(%rip),%rax
lea    0xe24(%rip),%r13
lea    0xe22(%rip),%r12
mov    %rax,(%rsp)
mov    -0x480(%rbp),%rax
mov    %r13,0x8(%rsp)
mov    %r12,0x10(%rsp)
mov    %r15d,0x18(%rsp)
mov    %r14d,0x20(%rsp)
mov    %ebx,0x28(%rsp)
mov    %r11,0x30(%rsp)
mov    %r10,0x38(%rsp)
mov    %rax,0x40(%rsp)
call   1080 <sprintf@plt>
mov    -0x68(%rbp),%rdi
lea    -0x470(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
xor    %ecx,%ecx
lea    -0x70(%rbp),%r8
call   1030 <sqlite3_exec@plt>
mov    %eax,-0x474(%rbp)
mov    0x2cb5(%rip),%rax
mov    (%rax),%eax
cmp    -0x474(%rbp),%eax
je     138b <add_entry+0x22b>
mov    0x2c88(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x484(%rbp)
mov    -0x68(%rbp),%rdi
call   1050 <sqlite3_errmsg@plt>
mov    -0x484(%rbp),%edi
mov    %eax,%ecx
lea    0xd96(%rip),%rsi
lea    0xcbd(%rip),%rdx
mov    $0x0,%al
call   1070 <syslog@plt>
mov    -0x68(%rbp),%rdi
call   1060 <sqlite3_close@plt>
movl   $0xffffffff,-0x2c(%rbp)
jmp    139b <add_entry+0x23b>
mov    -0x68(%rbp),%rdi
call   1060 <sqlite3_close@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x4a8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_entry>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x418,%rsp
test   %rdx,%rdx
je     11d3 <add_entry+0x73>
mov    %esi,%r12d
test   %esi,%esi
je     11d3 <add_entry+0x73>
mov    %edi,%r15d
test   %edi,%edi
je     11d3 <add_entry+0x73>
mov    %r9d,%r14d
cmp    $0xfffffc18,%r9d
jle    11d3 <add_entry+0x73>
mov    %r8,%rbp
mov    %rcx,%r13
mov    %rdx,%rbx
movq   $0x0,0x8(%rsp)
lea    0xea6(%rip),%rdi
mov    %rsp,%rsi
call   1040 <sqlite3_open@plt>
test   %eax,%eax
je     11fb <add_entry+0x9b>
mov    0x2e14(%rip),%rax
mov    (%rax),%ebx
mov    (%rsp),%rdi
call   1050 <sqlite3_errmsg@plt>
lea    0xe95(%rip),%rsi
jmp    12a4 <add_entry+0x144>
mov    0x2df6(%rip),%rax
mov    (%rax),%edi
lea    0xe1d(%rip),%rsi
lea    0xe42(%rip),%rdx
xor    %eax,%eax
call   1070 <syslog@plt>
mov    $0xffffffff,%ebx
jmp    12c4 <add_entry+0x164>
cmpl   $0x2,0x450(%rsp)
02
lea    0xe31(%rip),%rax
lea    0xe34(%rip),%rdx
cmove  %rax,%rdx
sub    $0x8,%rsp
lea    0xed7(%rip),%rax
lea    0xecb(%rip),%r11
lea    0xebd(%rip),%r10
lea    0xe4b(%rip),%rsi
lea    0xe91(%rip),%rcx
lea    0xe93(%rip),%r8
lea    0xe98(%rip),%r9
lea    0x18(%rsp),%rdi
push   %rbp
push   %r13
push   %rbx
push   %r12
push   %r15
push   %r14
push   %rax
push   %r11
push   %r10
call   1080 <sprintf@plt>
add    $0x50,%rsp
mov    (%rsp),%rdi
xor    %ebx,%ebx
lea    0x8(%rsp),%r8
lea    0x10(%rsp),%rsi
xor    %edx,%edx
xor    %ecx,%ecx
call   1030 <sqlite3_exec@plt>
mov    0x2d61(%rip),%rcx
cmp    %eax,(%rcx)
je     12bb <add_entry+0x15b>
mov    0x2d3e(%rip),%rax
mov    (%rax),%ebx
mov    (%rsp),%rdi
call   1050 <sqlite3_errmsg@plt>
lea    0xe5a(%rip),%rsi
lea    0xd81(%rip),%rdx
mov    %ebx,%edi
mov    %eax,%ecx
xor    %eax,%eax
call   1070 <syslog@plt>
mov    $0xffffffff,%ebx
mov    (%rsp),%rdi
call   1060 <sqlite3_close@plt>
mov    %ebx,%eax
add    $0x418,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@LOG_ERR = global i32 0
@.str = [44 x i8] c"[%s] Please fill out the obligation fields.\00"
@.str.1 = [15 x i8] c"phone-firewall\00"
@.str.2 = [10 x i8] c"whitelist\00"
@.str.3 = [10 x i8] c"blacklist\00"
@.str.4 = [20 x i8] c"db/phonefirewall.db\00"
@.str.5 = [29 x i8] c"[%s] Can't open database: %s\00"
@.str.6 = [77 x i8] c"INSERT INTO %s (%s, %s, %s, %s, %s, %s) VALUES(%d, %d, %d, %lld, \22%s\22, \22%s\22)\00"
@.str.7 = [9 x i8] c"priority\00"
@.str.8 = [12 x i8] c"countrycode\00"
@.str.9 = [9 x i8] c"areacode\00"
@.str.10 = [7 x i8] c"number\00"
@.str.11 = [5 x i8] c"name\00"
@.str.12 = [7 x i8] c"reason\00"
@SQLITE_OK = global i32 0
@.str.13 = [19 x i8] c"[%s] SQL error: %s\00"
define i32 @add_entry(i32 %0, i32 %1, i64 %2, i8* %3, i8* %4, i32 %5, i32 %6) {
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i64
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i32
%15 = alloca i32
%16 = alloca i8*
%17 = alloca i32*
%18 = alloca i8*
%19 = alloca [1024 x i8]
%20 = alloca i32
store i32 %0, i32* %9
store i32 %1, i32* %10
store i64 %2, i64* %11
store i8* %3, i8** %12
store i8* %4, i8** %13
store i32 %5, i32* %14
store i32 %6, i32* %15
%21 = load i32, i32* %14
%22 = icmp slt i32 %21, -999
br i1 %22, label %32, label %23
23: ; preds = %7
%24 = load i32, i32* %9
%25 = icmp eq i32 0, %24
br i1 %25, label %32, label %26
26: ; preds = %23
%27 = load i32, i32* %10
%28 = icmp eq i32 0, %27
br i1 %28, label %32, label %29
29: ; preds = %26
%30 = load i64, i64* %11
%31 = icmp eq i64 0, %30
br i1 %31, label %32, label %35
32: ; preds = %29, %26, %23, %7
%33 = load i32, i32* @LOG_ERR
%34 = call i32 (i32, i8*, i8*, ...) @syslog(i32 %33, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %8
br label %76
35: ; preds = %29
%36 = load i32, i32* %15
%37 = icmp eq i32 2, %36
%38 = zext i1 %37 to i64
%39 = select i1 %37, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0)
store i8* %39, i8** %16
store i8* null, i8** %18
%40 = call i32 @sqlite3_open(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i32** %17)
store i32 %40, i32* %20
%41 = load i32, i32* %20
%42 = icmp ne i32 %41, 0
br i1 %42, label %43, label %50
43: ; preds = %35
%44 = load i32, i32* @LOG_ERR
%45 = load i32*, i32** %17
%46 = call i32 @sqlite3_errmsg(i32* %45)
%47 = call i32 (i32, i8*, i8*, ...) @syslog(i32 %44, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %46)
%48 = load i32*, i32** %17
%49 = call i32 @sqlite3_close(i32* %48)
store i32 -1, i32* %8
br label %76
50: ; preds = %35
%51 = getelementptr inbounds [1024 x i8], [1024 x i8]* %19, i64 0, i64 0
%52 = load i8*, i8** %16
%53 = load i32, i32* %14
%54 = load i32, i32* %9
%55 = load i32, i32* %10
%56 = load i64, i64* %11
%57 = load i8*, i8** %12
%58 = load i8*, i8** %13
%59 = call i32 @sprintf(i8* %51, i8* getelementptr inbounds ([77 x i8], [77 x i8]* @.str.6, i64 0, i64 0), i8* %52, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.12, i64 0, i64 0), i32 %53, i32 %54, i32 %55, i64 %56, i8* %57, i8* %58)
%60 = load i32*, i32** %17
%61 = getelementptr inbounds [1024 x i8], [1024 x i8]* %19, i64 0, i64 0
%62 = call i32 @sqlite3_exec(i32* %60, i8* %61, i32* null, i32 0, i8** %18)
store i32 %62, i32* %20
%63 = load i32, i32* @SQLITE_OK
%64 = load i32, i32* %20
%65 = icmp ne i32 %63, %64
br i1 %65, label %66, label %73
66: ; preds = %50
%67 = load i32, i32* @LOG_ERR
%68 = load i32*, i32** %17
%69 = call i32 @sqlite3_errmsg(i32* %68)
%70 = call i32 (i32, i8*, i8*, ...) @syslog(i32 %67, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.13, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %69)
%71 = load i32*, i32** %17
%72 = call i32 @sqlite3_close(i32* %71)
store i32 -1, i32* %8
br label %76
73: ; preds = %50
%74 = load i32*, i32** %17
%75 = call i32 @sqlite3_close(i32* %74)
store i32 0, i32* %8
br label %76
76: ; preds = %73, %66, %43, %32
%77 = load i32, i32* %8
ret i32 %77
}

LLVM IR (-O2):
@LOG_ERR = global i32 0
@.str = [44 x i8] c"[%s] Please fill out the obligation fields.\00"
@.str.1 = [15 x i8] c"phone-firewall\00"
@.str.2 = [10 x i8] c"whitelist\00"
@.str.3 = [10 x i8] c"blacklist\00"
@.str.4 = [20 x i8] c"db/phonefirewall.db\00"
@.str.5 = [29 x i8] c"[%s] Can't open database: %s\00"
@.str.6 = [77 x i8] c"INSERT INTO %s (%s, %s, %s, %s, %s, %s) VALUES(%d, %d, %d, %lld, \22%s\22, \22%s\22)\00"
@.str.7 = [9 x i8] c"priority\00"
@.str.8 = [12 x i8] c"countrycode\00"
@.str.9 = [9 x i8] c"areacode\00"
@.str.10 = [7 x i8] c"number\00"
@.str.11 = [5 x i8] c"name\00"
@.str.12 = [7 x i8] c"reason\00"
@SQLITE_OK = global i32 0
@.str.13 = [19 x i8] c"[%s] SQL error: %s\00"
define i32 @add_entry(i32 %0, i32 %1, i64 %2, i8* %3, i8* %4, i32 %5, i32 %6) {
%8 = alloca i32*
%9 = alloca i8*
%10 = alloca [1024 x i8]
%11 = icmp slt i32 %5, -999
%12 = icmp eq i32 %0, 0
%13 = or i1 %12, %11
%14 = icmp eq i32 %1, 0
%15 = or i1 %14, %13
%16 = icmp eq i64 %2, 0
%17 = or i1 %16, %15
br i1 %17, label %18, label %21
18: ; preds = %7
%19 = load i32, i32* @LOG_ERR
%20 = tail call i32 (i32, i8*, i8*, ...) @syslog(i32 %19, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %49
21: ; preds = %7
%22 = bitcast i32** %8 to i8*
%23 = bitcast i8** %9 to i8*
store i8* null, i8** %9
%24 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%25 = call i32 @sqlite3_open(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i32** %8)
%26 = icmp eq i32 %25, 0
br i1 %26, label %32, label %27
27: ; preds = %21
%28 = load i32, i32* @LOG_ERR
%29 = load i32*, i32** %8
%30 = call i32 @sqlite3_errmsg(i32* %29)
%31 = call i32 (i32, i8*, i8*, ...) @syslog(i32 %28, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %30)
br label %45
32: ; preds = %21
%33 = icmp eq i32 %6, 2
%34 = select i1 %33, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0)
%35 = call i32 @sprintf(i8* %24, i8* dereferenceable(1) getelementptr inbounds ([77 x i8], [77 x i8]* @.str.6, i64 0, i64 0), i8* %34, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.12, i64 0, i64 0), i32 %5, i32 %0, i32 %1, i64 %2, i8* %3, i8* %4)
%36 = load i32*, i32** %8
%37 = call i32 @sqlite3_exec(i32* %36, i8* %24, i32* null, i32 0, i8** %9)
%38 = load i32, i32* @SQLITE_OK
%39 = icmp eq i32 %38, %37
br i1 %39, label %45, label %40
40: ; preds = %32
%41 = load i32, i32* @LOG_ERR
%42 = load i32*, i32** %8
%43 = call i32 @sqlite3_errmsg(i32* %42)
%44 = call i32 (i32, i8*, i8*, ...) @syslog(i32 %41, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.13, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %43)
br label %45
45: ; preds = %32, %40, %27
%46 = phi i32 [ -1, %27 ], [ -1, %40 ], [ 0, %32 ]
%47 = load i32*, i32** %8
%48 = call i32 @sqlite3_close(i32* %47)
br label %49
49: ; preds = %45, %18
%50 = phi i32 [ -1, %18 ], [ %46, %45 ]
ret i32 %50
}