#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 *, unsigned long long, 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_number(int country_code, int area_code, unsigned long long number,
                  int new_country_code, int new_area_code,
                  unsigned long long new_number, 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 AND %s = %d AND %s = %lld WHERE %s = %d AND "
          "%s = %d AND %s = %lld",
          listname, "countrycode", new_country_code, "areacode", new_area_code,
          "number", new_number, "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_number>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x498,%rsp
mov    0x10(%rbp),%eax
mov    %edi,-0x30(%rbp)
mov    %esi,-0x34(%rbp)
mov    %rdx,-0x40(%rbp)
mov    %ecx,-0x44(%rbp)
mov    %r8d,-0x48(%rbp)
mov    %r9,-0x50(%rbp)
mov    0x10(%rbp),%esi
mov    $0x2,%edx
lea    0xe6f(%rip),%rax
lea    0xe5e(%rip),%rcx
cmp    %esi,%edx
cmove  %rcx,%rax
mov    %rax,-0x58(%rbp)
movq   $0x0,-0x468(%rbp)
lea    0xe56(%rip),%rdi
lea    -0x60(%rbp),%rsi
call   1040 <sqlite3_open@plt>
mov    %eax,-0x46c(%rbp)
cmpl   $0x0,-0x46c(%rbp)
je     1222 <change_number+0xc2>
mov    0x2def(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x470(%rbp)
mov    -0x60(%rbp),%rdi
call   1050 <sqlite3_errmsg@plt>
mov    -0x470(%rbp),%edi
mov    %eax,%ecx
lea    0xe27(%rip),%rsi
lea    0xe3d(%rip),%rdx
call   1070 <syslog@plt>
mov    -0x60(%rbp),%rdi
call   1060 <sqlite3_close@plt>
movl   $0x0,-0x2c(%rbp)
jmp    1328 <change_number+0x1c8>
lea    -0x460(%rbp),%rdi
mov    -0x58(%rbp),%rdx
mov    -0x44(%rbp),%r8d
mov    -0x48(%rbp),%r13d
mov    -0x50(%rbp),%r12
mov    -0x30(%rbp),%r14d
mov    -0x34(%rbp),%r11d
mov    -0x40(%rbp),%rax
lea    0xe08(%rip),%rsi
lea    0xe59(%rip),%r15
lea    0xe5e(%rip),%rbx
lea    0xe60(%rip),%r10
mov    %r15,%rcx
mov    %rbx,%r9
mov    %r13d,(%rsp)
mov    %r10,0x8(%rsp)
mov    %r12,0x10(%rsp)
mov    %r15,0x18(%rsp)
mov    %r14d,0x20(%rsp)
mov    %rbx,0x28(%rsp)
mov    %r11d,0x30(%rsp)
mov    %r10,0x38(%rsp)
mov    %rax,0x40(%rsp)
call   1080 <sprintf@plt>
mov    -0x60(%rbp),%rdi
lea    -0x460(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
xor    %ecx,%ecx
lea    -0x468(%rbp),%r8
call   1030 <sqlite3_exec@plt>
mov    %eax,-0x46c(%rbp)
mov    0x2d26(%rip),%rax
mov    (%rax),%eax
cmp    -0x46c(%rbp),%eax
je     1318 <change_number+0x1b8>
mov    0x2cf9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x474(%rbp)
mov    -0x60(%rbp),%rdi
call   1050 <sqlite3_errmsg@plt>
mov    -0x474(%rbp),%edi
mov    %eax,%ecx
lea    0xdd1(%rip),%rsi
lea    0xd47(%rip),%rdx
call   1070 <syslog@plt>
mov    -0x60(%rbp),%rdi
call   1060 <sqlite3_close@plt>
movl   $0x0,-0x2c(%rbp)
jmp    1328 <change_number+0x1c8>
mov    -0x60(%rbp),%rdi
call   1060 <sqlite3_close@plt>
movl   $0x1,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x498,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

x86 assembly (clang, -O2):
<change_number>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x418,%rsp
mov    %r9,%r15
mov    %r8d,%r14d
mov    %ecx,%r13d
mov    %rdx,%rbp
mov    %esi,%ebx
mov    %edi,%r12d
movq   $0x0,0x8(%rsp)
lea    0xe82(%rip),%rdi
mov    %rsp,%rsi
call   1040 <sqlite3_open@plt>
test   %eax,%eax
je     11bc <change_number+0x5c>
mov    0x2e2b(%rip),%rax
mov    (%rax),%ebx
mov    (%rsp),%rdi
call   1050 <sqlite3_errmsg@plt>
lea    0xe71(%rip),%rsi
jmp    1254 <change_number+0xf4>
cmpl   $0x2,0x450(%rsp)
02
lea    0xe35(%rip),%rax
lea    0xe38(%rip),%rdx
cmove  %rax,%rdx
sub    $0x8,%rsp
lea    0xee0(%rip),%rax
lea    0xed0(%rip),%r9
lea    0xebd(%rip),%rcx
lea    0xe5e(%rip),%rsi
lea    0x18(%rsp),%rdi
mov    %r13d,%r8d
push   %rbp
push   %rax
push   %rbx
push   %r9
push   %r12
push   %rcx
push   %r15
push   %rax
push   %r14
call   1080 <sprintf@plt>
add    $0x50,%rsp
mov    (%rsp),%rdi
lea    0x8(%rsp),%r8
lea    0x10(%rsp),%rsi
xor    %edx,%edx
xor    %ecx,%ecx
call   1030 <sqlite3_exec@plt>
mov    0x2db6(%rip),%rcx
mov    $0x1,%ebx
cmp    %eax,(%rcx)
je     1266 <change_number+0x106>
mov    0x2d8e(%rip),%rax
mov    (%rax),%ebx
mov    (%rsp),%rdi
call   1050 <sqlite3_errmsg@plt>
lea    0xe74(%rip),%rsi
lea    0xdea(%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    $0x418,%rsp
pop    %rbx
pop    %r12
pop    %r13
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 = [88 x i8] c"UPDATE %s SET %s = %d AND %s = %d AND %s = %lld WHERE %s = %d AND %s = %d AND %s = %lld\00"
@.str.6 = [12 x i8] c"countrycode\00"
@.str.7 = [9 x i8] c"areacode\00"
@.str.8 = [7 x i8] c"number\00"
@SQLITE_OK = global i32 0
@.str.9 = [19 x i8] c"[%s] SQL error: %s\00"
define i32 @change_number(i32 %0, i32 %1, i64 %2, i32 %3, i32 %4, i64 %5, i32 %6) {
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i64
%12 = alloca i32
%13 = alloca i32
%14 = alloca i64
%15 = alloca i32
%16 = alloca i8*
%17 = alloca i32*
%18 = alloca [1024 x i8]
%19 = alloca i8*
%20 = alloca i32
store i32 %0, i32* %9
store i32 %1, i32* %10
store i64 %2, i64* %11
store i32 %3, i32* %12
store i32 %4, i32* %13
store i64 %5, i64* %14
store i32 %6, i32* %15
%21 = load i32, i32* %15
%22 = icmp eq i32 2, %21
%23 = zext i1 %22 to i64
%24 = select i1 %22, 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* %24, i8** %16
store i8* null, i8** %19
%25 = call i32 @sqlite3_open(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32** %17)
store i32 %25, i32* %20
%26 = load i32, i32* %20
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %35
28: ; preds = %7
%29 = load i32, i32* @LOG_ERR
%30 = load i32*, i32** %17
%31 = call i32 @sqlite3_errmsg(i32* %30)
%32 = call i32 @syslog(i32 %29, 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 %31)
%33 = load i32*, i32** %17
%34 = call i32 @sqlite3_close(i32* %33)
store i32 0, i32* %8
br label %61
35: ; preds = %7
%36 = getelementptr inbounds [1024 x i8], [1024 x i8]* %18, i64 0, i64 0
%37 = load i8*, i8** %16
%38 = load i32, i32* %12
%39 = load i32, i32* %13
%40 = load i64, i64* %14
%41 = load i32, i32* %9
%42 = load i32, i32* %10
%43 = load i64, i64* %11
%44 = call i32 @sprintf(i8* %36, i8* getelementptr inbounds ([88 x i8], [88 x i8]* @.str.5, i64 0, i64 0), i8* %37, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i32 %38, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0), i32 %39, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0), i64 %40, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i32 %41, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0), i32 %42, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0), i64 %43)
%45 = load i32*, i32** %17
%46 = getelementptr inbounds [1024 x i8], [1024 x i8]* %18, i64 0, i64 0
%47 = call i32 @sqlite3_exec(i32* %45, i8* %46, i32* null, i32 0, i8** %19)
store i32 %47, i32* %20
%48 = load i32, i32* @SQLITE_OK
%49 = load i32, i32* %20
%50 = icmp ne i32 %48, %49
br i1 %50, label %51, label %58
51: ; preds = %35
%52 = load i32, i32* @LOG_ERR
%53 = load i32*, i32** %17
%54 = call i32 @sqlite3_errmsg(i32* %53)
%55 = call i32 @syslog(i32 %52, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i32 %54)
%56 = load i32*, i32** %17
%57 = call i32 @sqlite3_close(i32* %56)
store i32 0, i32* %8
br label %61
58: ; preds = %35
%59 = load i32*, i32** %17
%60 = call i32 @sqlite3_close(i32* %59)
store i32 1, i32* %8
br label %61
61: ; preds = %58, %51, %28
%62 = load i32, i32* %8
ret i32 %62
}

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 = [88 x i8] c"UPDATE %s SET %s = %d AND %s = %d AND %s = %lld WHERE %s = %d AND %s = %d AND %s = %lld\00"
@.str.6 = [12 x i8] c"countrycode\00"
@.str.7 = [9 x i8] c"areacode\00"
@.str.8 = [7 x i8] c"number\00"
@SQLITE_OK = global i32 0
@.str.9 = [19 x i8] c"[%s] SQL error: %s\00"
define i32 @change_number(i32 %0, i32 %1, i64 %2, i32 %3, i32 %4, i64 %5, i32 %6) {
%8 = alloca i32*
%9 = alloca [1024 x i8]
%10 = alloca i8*
%11 = bitcast i32** %8 to i8*
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%13 = bitcast i8** %10 to i8*
store i8* null, i8** %10
%14 = call i32 @sqlite3_open(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32** %8)
%15 = icmp eq i32 %14, 0
br i1 %15, label %21, label %16
16: ; preds = %7
%17 = load i32, i32* @LOG_ERR
%18 = load i32*, i32** %8
%19 = call i32 @sqlite3_errmsg(i32* %18)
%20 = call i32 @syslog(i32 %17, 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 %19)
br label %34
21: ; preds = %7
%22 = icmp eq i32 %6, 2
%23 = select i1 %22, 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)
%24 = call i32 @sprintf(i8* %12, i8* dereferenceable(1) getelementptr inbounds ([88 x i8], [88 x i8]* @.str.5, i64 0, i64 0), i8* %23, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i32 %3, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0), i32 %4, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0), i64 %5, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i32 %0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0), i32 %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0), i64 %2)
%25 = load i32*, i32** %8
%26 = call i32 @sqlite3_exec(i32* %25, i8* %12, i32* null, i32 0, i8** %10)
%27 = load i32, i32* @SQLITE_OK
%28 = icmp eq i32 %27, %26
br i1 %28, label %34, label %29
29: ; preds = %21
%30 = load i32, i32* @LOG_ERR
%31 = load i32*, i32** %8
%32 = call i32 @sqlite3_errmsg(i32* %31)
%33 = call i32 @syslog(i32 %30, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i32 %32)
br label %34
34: ; preds = %21, %29, %16
%35 = phi i32 [ 0, %16 ], [ 0, %29 ], [ 1, %21 ]
%36 = load i32*, i32** %8
%37 = call i32 @sqlite3_close(i32* %36)
ret i32 %35
}