#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 *, int, char *, int,
                           char *, int, char *, unsigned long long);
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 /*<<< orphan*/);
int change_priority(int country_code, int area_code, unsigned long long number,
                    int new_priority, int listflag) {
  char *listname = (0x02 == listflag) ? "whitelist" : "blacklist";
  sqlite3 *db;
  char stmt[1024];
  char *errMsg = 0;
  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 0;
  }
  sprintf(stmt, "UPDATE %s SET %s = %d WHERE %s = %d AND %s = %d AND %s = %lld",
          listname, "priority", new_priority, "countrycode", country_code,
          "areacode", area_code, "number", number);
  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 0;
  }
  sqlite3_close(db);
  return 1;
}


x86 assembly (clang, -O0):
<change_priority>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
sub    $0x470,%rsp
mov    %edi,-0x18(%rbp)
mov    %esi,-0x1c(%rbp)
mov    %rdx,-0x28(%rbp)
mov    %ecx,-0x2c(%rbp)
mov    %r8d,-0x30(%rbp)
mov    -0x30(%rbp),%esi
mov    $0x2,%edx
lea    0xe7c(%rip),%rax
lea    0xe6b(%rip),%rcx
cmp    %esi,%edx
cmove  %rcx,%rax
mov    %rax,-0x38(%rbp)
movq   $0x0,-0x448(%rbp)
lea    0xe63(%rip),%rdi
lea    -0x40(%rbp),%rsi
call   1040 <sqlite3_open@plt>
mov    %eax,-0x44c(%rbp)
cmpl   $0x0,-0x44c(%rbp)
je     1215 <change_priority+0xb5>
mov    0x2dfc(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x450(%rbp)
mov    -0x40(%rbp),%rdi
call   1050 <sqlite3_errmsg@plt>
mov    -0x450(%rbp),%edi
mov    %eax,%ecx
lea    0xe34(%rip),%rsi
lea    0xe4a(%rip),%rdx
call   1070 <syslog@plt>
mov    -0x40(%rbp),%rdi
call   1060 <sqlite3_close@plt>
movl   $0x0,-0x14(%rbp)
jmp    1300 <change_priority+0x1a0>
lea    -0x440(%rbp),%rdi
mov    -0x38(%rbp),%rdx
mov    -0x2c(%rbp),%r8d
mov    -0x18(%rbp),%r14d
mov    -0x1c(%rbp),%r11d
mov    -0x28(%rbp),%rax
lea    0xe1d(%rip),%rsi
lea    0xe54(%rip),%rcx
lea    0xe56(%rip),%r9
lea    0xe5b(%rip),%rbx
lea    0xe5d(%rip),%r10
mov    %r14d,(%rsp)
mov    %rbx,0x8(%rsp)
mov    %r11d,0x10(%rsp)
mov    %r10,0x18(%rsp)
mov    %rax,0x20(%rsp)
call   1080 <sprintf@plt>
mov    -0x40(%rbp),%rdi
lea    -0x440(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
xor    %ecx,%ecx
lea    -0x448(%rbp),%r8
call   1030 <sqlite3_exec@plt>
mov    %eax,-0x44c(%rbp)
mov    0x2d4e(%rip),%rax
mov    (%rax),%eax
cmp    -0x44c(%rbp),%eax
je     12f0 <change_priority+0x190>
mov    0x2d21(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x454(%rbp)
mov    -0x40(%rbp),%rdi
call   1050 <sqlite3_errmsg@plt>
mov    -0x454(%rbp),%edi
mov    %eax,%ecx
lea    0xde8(%rip),%rsi
lea    0xd6f(%rip),%rdx
call   1070 <syslog@plt>
mov    -0x40(%rbp),%rdi
call   1060 <sqlite3_close@plt>
movl   $0x0,-0x14(%rbp)
jmp    1300 <change_priority+0x1a0>
mov    -0x40(%rbp),%rdi
call   1060 <sqlite3_close@plt>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x470,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

x86 assembly (clang, -O2):
<change_priority>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x410,%rsp
mov    %r8d,%ebx
mov    %ecx,%ebp
mov    %rdx,%r12
mov    %esi,%r15d
mov    %edi,%r14d
movq   $0x0,0x8(%rsp)
lea    0xe87(%rip),%rdi
mov    %rsp,%rsi
call   1040 <sqlite3_open@plt>
test   %eax,%eax
je     11b7 <change_priority+0x57>
mov    0x2e30(%rip),%rax
mov    (%rax),%ebx
mov    (%rsp),%rdi
call   1050 <sqlite3_errmsg@plt>
lea    0xe76(%rip),%rsi
jmp    124e <change_priority+0xee>
cmp    $0x2,%ebx
lea    0xe3f(%rip),%rax
lea    0xe42(%rip),%rdx
cmove  %rax,%rdx
sub    $0x8,%rsp
lea    0xed9(%rip),%rax
lea    0xec9(%rip),%r10
lea    0xe6f(%rip),%rsi
lea    0xea6(%rip),%rcx
lea    0xea8(%rip),%r9
lea    0x18(%rsp),%rbx
mov    %rbx,%rdi
mov    %ebp,%r8d
push   %r12
push   %rax
push   %r15
push   %r10
push   %r14
call   1080 <sprintf@plt>
add    $0x30,%rsp
mov    (%rsp),%rdi
lea    0x8(%rsp),%r8
mov    %rbx,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
call   1030 <sqlite3_exec@plt>
mov    0x2dbc(%rip),%rcx
mov    $0x1,%ebx
cmp    %eax,(%rcx)
je     1260 <change_priority+0x100>
mov    0x2d94(%rip),%rax
mov    (%rax),%ebx
mov    (%rsp),%rdi
call   1050 <sqlite3_errmsg@plt>
lea    0xe69(%rip),%rsi
lea    0xdf0(%rip),%rdx
mov    %ebx,%edi
mov    %eax,%ecx
call   1070 <syslog@plt>
xor    %ebx,%ebx
mov    (%rsp),%rdi
call   1060 <sqlite3_close@plt>
mov    %ebx,%eax
add    $0x410,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"whitelist\00"
@.str.1 = [10 x i8] c"blacklist\00"
@.str.2 = [20 x i8] c"db/phonefirewall.db\00"
@LOG_ERR = global i32 0
@.str.3 = [29 x i8] c"[%s] Can't open database: %s\00"
@.str.4 = [15 x i8] c"phone-firewall\00"
@.str.5 = [62 x i8] c"UPDATE %s SET %s = %d WHERE %s = %d AND %s = %d AND %s = %lld\00"
@.str.6 = [9 x i8] c"priority\00"
@.str.7 = [12 x i8] c"countrycode\00"
@.str.8 = [9 x i8] c"areacode\00"
@.str.9 = [7 x i8] c"number\00"
@SQLITE_OK = global i32 0
@.str.10 = [19 x i8] c"[%s] SQL error: %s\00"
define i32 @change_priority(i32 %0, i32 %1, i64 %2, i32 %3, i32 %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i64
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i32*
%14 = alloca [1024 x i8]
%15 = alloca i8*
%16 = alloca i32
store i32 %0, i32* %7
store i32 %1, i32* %8
store i64 %2, i64* %9
store i32 %3, i32* %10
store i32 %4, i32* %11
%17 = load i32, i32* %11
%18 = icmp eq i32 2, %17
%19 = zext i1 %18 to i64
%20 = select i1 %18, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0)
store i8* %20, i8** %12
store i8* null, i8** %15
%21 = call i32 @sqlite3_open(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32** %13)
store i32 %21, i32* %16
%22 = load i32, i32* %16
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %31
24: ; preds = %5
%25 = load i32, i32* @LOG_ERR
%26 = load i32*, i32** %13
%27 = call i32 @sqlite3_errmsg(i32* %26)
%28 = call i32 @syslog(i32 %25, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i32 %27)
%29 = load i32*, i32** %13
%30 = call i32 @sqlite3_close(i32* %29)
store i32 0, i32* %6
br label %55
31: ; preds = %5
%32 = getelementptr inbounds [1024 x i8], [1024 x i8]* %14, i64 0, i64 0
%33 = load i8*, i8** %12
%34 = load i32, i32* %10
%35 = load i32, i32* %7
%36 = load i32, i32* %8
%37 = load i64, i64* %9
%38 = call i32 @sprintf(i8* %32, i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.5, i64 0, i64 0), i8* %33, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i32 %34, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0), i32 %35, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0), i32 %36, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0), i64 %37)
%39 = load i32*, i32** %13
%40 = getelementptr inbounds [1024 x i8], [1024 x i8]* %14, i64 0, i64 0
%41 = call i32 @sqlite3_exec(i32* %39, i8* %40, i32* null, i32 0, i8** %15)
store i32 %41, i32* %16
%42 = load i32, i32* @SQLITE_OK
%43 = load i32, i32* %16
%44 = icmp ne i32 %42, %43
br i1 %44, label %45, label %52
45: ; preds = %31
%46 = load i32, i32* @LOG_ERR
%47 = load i32*, i32** %13
%48 = call i32 @sqlite3_errmsg(i32* %47)
%49 = call i32 @syslog(i32 %46, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i32 %48)
%50 = load i32*, i32** %13
%51 = call i32 @sqlite3_close(i32* %50)
store i32 0, i32* %6
br label %55
52: ; preds = %31
%53 = load i32*, i32** %13
%54 = call i32 @sqlite3_close(i32* %53)
store i32 1, i32* %6
br label %55
55: ; preds = %52, %45, %24
%56 = load i32, i32* %6
ret i32 %56
}

LLVM IR (-O2):
@.str = [10 x i8] c"whitelist\00"
@.str.1 = [10 x i8] c"blacklist\00"
@.str.2 = [20 x i8] c"db/phonefirewall.db\00"
@LOG_ERR = global i32 0
@.str.3 = [29 x i8] c"[%s] Can't open database: %s\00"
@.str.4 = [15 x i8] c"phone-firewall\00"
@.str.5 = [62 x i8] c"UPDATE %s SET %s = %d WHERE %s = %d AND %s = %d AND %s = %lld\00"
@.str.6 = [9 x i8] c"priority\00"
@.str.7 = [12 x i8] c"countrycode\00"
@.str.8 = [9 x i8] c"areacode\00"
@.str.9 = [7 x i8] c"number\00"
@SQLITE_OK = global i32 0
@.str.10 = [19 x i8] c"[%s] SQL error: %s\00"
define i32 @change_priority(i32 %0, i32 %1, i64 %2, i32 %3, i32 %4) {
%6 = alloca i32*
%7 = alloca [1024 x i8]
%8 = alloca i8*
%9 = bitcast i32** %6 to i8*
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%11 = bitcast i8** %8 to i8*
store i8* null, i8** %8
%12 = call i32 @sqlite3_open(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32** %6)
%13 = icmp eq i32 %12, 0
br i1 %13, label %19, label %14
14: ; preds = %5
%15 = load i32, i32* @LOG_ERR
%16 = load i32*, i32** %6
%17 = call i32 @sqlite3_errmsg(i32* %16)
%18 = call i32 @syslog(i32 %15, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i32 %17)
br label %32
19: ; preds = %5
%20 = icmp eq i32 %4, 2
%21 = select i1 %20, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0)
%22 = call i32 @sprintf(i8* %10, i8* dereferenceable(1) getelementptr inbounds ([62 x i8], [62 x i8]* @.str.5, i64 0, i64 0), i8* %21, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i32 %3, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0), i32 %0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0), i32 %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0), i64 %2)
%23 = load i32*, i32** %6
%24 = call i32 @sqlite3_exec(i32* %23, i8* %10, i32* null, i32 0, i8** %8)
%25 = load i32, i32* @SQLITE_OK
%26 = icmp eq i32 %25, %24
br i1 %26, label %32, label %27
27: ; preds = %19
%28 = load i32, i32* @LOG_ERR
%29 = load i32*, i32** %6
%30 = call i32 @sqlite3_errmsg(i32* %29)
%31 = call i32 @syslog(i32 %28, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i32 %30)
br label %32
32: ; preds = %19, %27, %14
%33 = phi i32 [ 0, %14 ], [ 0, %27 ], [ 1, %19 ]
%34 = load i32*, i32** %6
%35 = call i32 @sqlite3_close(i32* %34)
ret i32 %33
}