#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 *, 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_name(int country_code, int area_code, unsigned long long number,
                char *new_name, 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 = \"%s\" WHERE %s = %d AND %s = %d AND %s = %lld",
          listname, "name", new_name, "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_name>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
sub    $0x480,%rsp
mov    %edi,-0x18(%rbp)
mov    %esi,-0x1c(%rbp)
mov    %rdx,-0x28(%rbp)
mov    %rcx,-0x30(%rbp)
mov    %r8d,-0x34(%rbp)
mov    -0x34(%rbp),%esi
mov    $0x2,%edx
lea    0xe7b(%rip),%rax
lea    0xe6a(%rip),%rcx
cmp    %esi,%edx
cmove  %rcx,%rax
mov    %rax,-0x40(%rbp)
movq   $0x0,-0x458(%rbp)
lea    0xe62(%rip),%rdi
lea    -0x48(%rbp),%rsi
call   1040 <sqlite3_open@plt>
mov    %eax,-0x45c(%rbp)
cmpl   $0x0,-0x45c(%rbp)
je     1216 <change_name+0xb6>
mov    0x2dfb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x460(%rbp)
mov    -0x48(%rbp),%rdi
call   1050 <sqlite3_errmsg@plt>
mov    -0x460(%rbp),%edi
mov    %eax,%ecx
lea    0xe33(%rip),%rsi
lea    0xe49(%rip),%rdx
call   1070 <syslog@plt>
mov    -0x48(%rbp),%rdi
call   1060 <sqlite3_close@plt>
movl   $0x0,-0x14(%rbp)
jmp    1301 <change_name+0x1a1>
lea    -0x450(%rbp),%rdi
mov    -0x40(%rbp),%rdx
mov    -0x30(%rbp),%r8
mov    -0x18(%rbp),%r14d
mov    -0x1c(%rbp),%r11d
mov    -0x28(%rbp),%rax
lea    0xe1c(%rip),%rsi
lea    0xe55(%rip),%rcx
lea    0xe53(%rip),%r9
lea    0xe58(%rip),%rbx
lea    0xe5a(%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    -0x48(%rbp),%rdi
lea    -0x450(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
xor    %ecx,%ecx
lea    -0x458(%rbp),%r8
call   1030 <sqlite3_exec@plt>
mov    %eax,-0x45c(%rbp)
mov    0x2d4d(%rip),%rax
mov    (%rax),%eax
cmp    -0x45c(%rbp),%eax
je     12f1 <change_name+0x191>
mov    0x2d20(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x464(%rbp)
mov    -0x48(%rbp),%rdi
call   1050 <sqlite3_errmsg@plt>
mov    -0x464(%rbp),%edi
mov    %eax,%ecx
lea    0xde5(%rip),%rsi
lea    0xd6e(%rip),%rdx
call   1070 <syslog@plt>
mov    -0x48(%rbp),%rdi
call   1060 <sqlite3_close@plt>
movl   $0x0,-0x14(%rbp)
jmp    1301 <change_name+0x1a1>
mov    -0x48(%rbp),%rdi
call   1060 <sqlite3_close@plt>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x480,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

x86 assembly (clang, -O2):
<change_name>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x410,%rsp
mov    %r8d,%ebp
mov    %rcx,%rbx
mov    %rdx,%r12
mov    %esi,%r15d
mov    %edi,%r14d
movq   $0x0,0x8(%rsp)
lea    0xe86(%rip),%rdi
mov    %rsp,%rsi
call   1040 <sqlite3_open@plt>
test   %eax,%eax
je     11b8 <change_name+0x58>
mov    0x2e2f(%rip),%rax
mov    (%rax),%ebx
mov    (%rsp),%rdi
call   1050 <sqlite3_errmsg@plt>
lea    0xe75(%rip),%rsi
jmp    124f <change_name+0xef>
cmp    $0x2,%ebp
lea    0xe3e(%rip),%rax
lea    0xe41(%rip),%rdx
cmove  %rax,%rdx
sub    $0x8,%rsp
lea    0xed6(%rip),%rax
lea    0xec6(%rip),%r10
lea    0xe6e(%rip),%rsi
lea    0xea7(%rip),%rcx
lea    0xea5(%rip),%r9
lea    0x18(%rsp),%rbp
mov    %rbp,%rdi
mov    %rbx,%r8
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    %rbp,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
call   1030 <sqlite3_exec@plt>
mov    0x2dbb(%rip),%rcx
mov    $0x1,%ebx
cmp    %eax,(%rcx)
je     1261 <change_name+0x101>
mov    0x2d93(%rip),%rax
mov    (%rax),%ebx
mov    (%rsp),%rdi
call   1050 <sqlite3_errmsg@plt>
lea    0xe66(%rip),%rsi
lea    0xdef(%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 = [64 x i8] c"UPDATE %s SET %s = \22%s\22 WHERE %s = %d AND %s = %d AND %s = %lld\00"
@.str.6 = [5 x i8] c"name\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_name(i32 %0, i32 %1, i64 %2, i8* %3, i32 %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i64
%10 = alloca i8*
%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 i8* %3, i8** %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 i8*, i8** %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 ([64 x i8], [64 x i8]* @.str.5, i64 0, i64 0), i8* %33, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i8* %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 = [64 x i8] c"UPDATE %s SET %s = \22%s\22 WHERE %s = %d AND %s = %d AND %s = %lld\00"
@.str.6 = [5 x i8] c"name\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_name(i32 %0, i32 %1, i64 %2, i8* %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 ([64 x i8], [64 x i8]* @.str.5, i64 0, i64 0), i8* %21, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i8* %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
}