#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;
typedef int /*<<< orphan*/ sql;

/* Variables and functions */
int SQLITE_OK;
int SQLITE_ROW;
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, ...);
int sqlite3_exec(int /*<<< orphan*/ *, char *, int /*<<< orphan*/ *,
                 int /*<<< orphan*/ *, char **);
int /*<<< orphan*/ sqlite3_finalize(int /*<<< orphan*/ *);
int /*<<< orphan*/ sqlite3_prepare(int /*<<< orphan*/ *, char *, int,
                                   int /*<<< orphan*/ **, int /*<<< orphan*/);
int sqlite3_step(int /*<<< orphan*/ *);
int traffic_total_collect(char *mac_get, int time_get, sqlite3 *db) {
  int rc = 0;
  char sql[250] = {0};
  char *errmsg;
  sqlite3_stmt *ppstmt = NULL;
  memset(sql, 0, sizeof(sql));
  sprintf(sql, "select time from traffic_total where mobile='%s'", mac_get);
  sqlite3_prepare(db, sql, -1, &ppstmt, 0);
  rc = sqlite3_step(ppstmt);
  if (rc != SQLITE_ROW) {
    sqlite3_finalize(ppstmt);
    memset(sql, 0, sizeof(sql));
    sprintf(sql, "insert into traffic_total (mobile,time) values('%s','%ld')",
            mac_get, time_get);
    rc = sqlite3_exec(db, sql, NULL, NULL, &errmsg);
    if (SQLITE_OK != rc) {
      printf("insert traffic_total.db error : %s\n", errmsg);
      return 1;
    } else
      return 0;
  } else {
    sqlite3_finalize(ppstmt);
    memset(sql, 0, sizeof(sql));
    sprintf(sql, "update traffic_total set time='%ld' where mobile='%s'",
            time_get, mac_get);
    rc = sqlite3_exec(db, sql, NULL, NULL, &errmsg);
    if (SQLITE_OK != rc) {
      printf("update traffic_total.db error : %s\n", errmsg);
      return 2;
    } else
      return 0;
  }
}


x86 assembly (clang, -O0):
<traffic_total_collect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
lea    -0x120(%rbp),%rdi
xor    %esi,%esi
mov    $0xfa,%edx
call   1050 <memset@plt>
movq   $0x0,-0x130(%rbp)
lea    -0x120(%rbp),%rdi
xor    %esi,%esi
mov    $0xfa,%edx
call   1050 <memset@plt>
lea    -0x120(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe30(%rip),%rsi
mov    $0x0,%al
call   1090 <sprintf@plt>
mov    -0x20(%rbp),%rdi
lea    -0x120(%rbp),%rsi
mov    $0xffffffff,%edx
lea    -0x130(%rbp),%rcx
xor    %r8d,%r8d
call   1070 <sqlite3_prepare@plt>
mov    -0x130(%rbp),%rdi
call   1060 <sqlite3_step@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    0x2dc9(%rip),%rcx
cmp    (%rcx),%eax
je     12b0 <traffic_total_collect+0x140>
mov    -0x130(%rbp),%rdi
call   1080 <sqlite3_finalize@plt>
lea    -0x120(%rbp),%rdi
xor    %esi,%esi
mov    $0xfa,%edx
call   1050 <memset@plt>
lea    -0x120(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x14(%rbp),%ecx
lea    0xde6(%rip),%rsi
mov    $0x0,%al
call   1090 <sprintf@plt>
mov    -0x20(%rbp),%rdi
lea    -0x120(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x128(%rbp),%r8
mov    %rcx,%rdx
call   1030 <sqlite3_exec@plt>
mov    %eax,-0x24(%rbp)
mov    0x2d6e(%rip),%rax
mov    (%rax),%eax
cmp    -0x24(%rbp),%eax
je     12a4 <traffic_total_collect+0x134>
mov    -0x128(%rbp),%rsi
lea    0xdd9(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1344 <traffic_total_collect+0x1d4>
movl   $0x0,-0x4(%rbp)
jmp    1344 <traffic_total_collect+0x1d4>
mov    -0x130(%rbp),%rdi
call   1080 <sqlite3_finalize@plt>
lea    -0x120(%rbp),%rdi
xor    %esi,%esi
mov    $0xfa,%edx
call   1050 <memset@plt>
lea    -0x120(%rbp),%rdi
mov    -0x14(%rbp),%edx
mov    -0x10(%rbp),%rcx
lea    0xdac(%rip),%rsi
mov    $0x0,%al
call   1090 <sprintf@plt>
mov    -0x20(%rbp),%rdi
lea    -0x120(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x128(%rbp),%r8
mov    %rcx,%rdx
call   1030 <sqlite3_exec@plt>
mov    %eax,-0x24(%rbp)
mov    0x2cd5(%rip),%rax
mov    (%rax),%eax
cmp    -0x24(%rbp),%eax
je     133d <traffic_total_collect+0x1cd>
mov    -0x128(%rbp),%rsi
lea    0xd9a(%rip),%rdi
call   1040 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1344 <traffic_total_collect+0x1d4>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<traffic_total_collect>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x128,%rsp
mov    %rdx,%r12
mov    %esi,0xc(%rsp)
mov    %rdi,%r13
xorps  %xmm0,%xmm0
movups %xmm0,0x10a(%rsp)
movaps %xmm0,0x100(%rsp)
movaps %xmm0,0xf0(%rsp)
movaps %xmm0,0xe0(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movq   $0x0,0x10(%rsp)
lea    0x20(%rsp),%rbx
xor    %r14d,%r14d
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xfa,%edx
call   1050 <memset@plt>
lea    0xddd(%rip),%rsi
mov    %rbx,%rdi
mov    %r13,%rdx
xor    %eax,%eax
call   1090 <sprintf@plt>
lea    0x10(%rsp),%rcx
mov    %r12,%rdi
mov    %rbx,%rsi
mov    $0xffffffff,%edx
xor    %r8d,%r8d
call   1070 <sqlite3_prepare@plt>
mov    0x10(%rsp),%rdi
call   1060 <sqlite3_step@plt>
mov    %eax,%ebp
mov    0x2d7d(%rip),%rax
mov    (%rax),%r15d
mov    0x10(%rsp),%rdi
call   1080 <sqlite3_finalize@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xfa,%edx
call   1050 <memset@plt>
cmp    %r15d,%ebp
jne    12d4 <traffic_total_collect+0x164>
lea    0xe0d(%rip),%rsi
xor    %r14d,%r14d
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
mov    0xc(%rsp),%edx
mov    %r13,%rcx
xor    %eax,%eax
call   1090 <sprintf@plt>
lea    0x18(%rsp),%r8
mov    %r12,%rdi
mov    %rbx,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
call   1030 <sqlite3_exec@plt>
mov    0x2d31(%rip),%rcx
cmp    %eax,(%rcx)
je     1327 <traffic_total_collect+0x1b7>
mov    0x18(%rsp),%rsi
lea    0xdff(%rip),%rdi
call   1040 <printf@plt>
mov    $0x2,%r14d
jmp    1327 <traffic_total_collect+0x1b7>
lea    0xd56(%rip),%rsi
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
mov    %r13,%rdx
mov    0xc(%rsp),%ecx
xor    %eax,%eax
call   1090 <sprintf@plt>
lea    0x18(%rsp),%r8
mov    %r12,%rdi
mov    %rbx,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
call   1030 <sqlite3_exec@plt>
mov    0x2cdc(%rip),%rcx
cmp    %eax,(%rcx)
je     1327 <traffic_total_collect+0x1b7>
mov    0x18(%rsp),%rsi
lea    0xd50(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%r14d
mov    %r14d,%eax
add    $0x128,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [49 x i8] c"select time from traffic_total where mobile='%s'\00"
@SQLITE_ROW = global i32 0
@.str.1 = [59 x i8] c"insert into traffic_total (mobile,time) values('%s','%ld')\00"
@SQLITE_OK = global i32 0
@.str.2 = [36 x i8] c"insert traffic_total.db error : %s\0A\00"
@.str.3 = [54 x i8] c"update traffic_total set time='%ld' where mobile='%s'\00"
@.str.4 = [36 x i8] c"update traffic_total.db error : %s\0A\00"
define i32 @traffic_total_collect(i8* %0, i32 %1, i32* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
%9 = alloca [250 x i8]
%10 = alloca i8*
%11 = alloca i32*
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32* %2, i32** %7
store i32 0, i32* %8
%12 = bitcast [250 x i8]* %9 to i8*
store i32* null, i32** %11
%13 = getelementptr inbounds [250 x i8], [250 x i8]* %9, i64 0, i64 0
%14 = call i32 @memset(i8* %13, i32 0, i32 250)
%15 = getelementptr inbounds [250 x i8], [250 x i8]* %9, i64 0, i64 0
%16 = load i8*, i8** %5
%17 = call i32 (i8*, i8*, ...) @sprintf(i8* %15, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = load i32*, i32** %7
%19 = getelementptr inbounds [250 x i8], [250 x i8]* %9, i64 0, i64 0
%20 = call i32 @sqlite3_prepare(i32* %18, i8* %19, i32 -1, i32** %11, i32 0)
%21 = load i32*, i32** %11
%22 = call i32 @sqlite3_step(i32* %21)
store i32 %22, i32* %8
%23 = load i32, i32* %8
%24 = load i32, i32* @SQLITE_ROW
%25 = icmp ne i32 %23, %24
br i1 %25, label %26, label %45
26: ; preds = %3
%27 = load i32*, i32** %11
%28 = call i32 @sqlite3_finalize(i32* %27)
%29 = getelementptr inbounds [250 x i8], [250 x i8]* %9, i64 0, i64 0
%30 = call i32 @memset(i8* %29, i32 0, i32 250)
%31 = getelementptr inbounds [250 x i8], [250 x i8]* %9, i64 0, i64 0
%32 = load i8*, i8** %5
%33 = load i32, i32* %6
%34 = call i32 (i8*, i8*, ...) @sprintf(i8* %31, i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.1, i64 0, i64 0), i8* %32, i32 %33)
%35 = load i32*, i32** %7
%36 = getelementptr inbounds [250 x i8], [250 x i8]* %9, i64 0, i64 0
%37 = call i32 @sqlite3_exec(i32* %35, i8* %36, i32* null, i32* null, i8** %10)
store i32 %37, i32* %8
%38 = load i32, i32* @SQLITE_OK
%39 = load i32, i32* %8
%40 = icmp ne i32 %38, %39
br i1 %40, label %41, label %44
41: ; preds = %26
%42 = load i8*, i8** %10
%43 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i8* %42)
store i32 1, i32* %4
br label %64
44: ; preds = %26
store i32 0, i32* %4
br label %64
45: ; preds = %3
%46 = load i32*, i32** %11
%47 = call i32 @sqlite3_finalize(i32* %46)
%48 = getelementptr inbounds [250 x i8], [250 x i8]* %9, i64 0, i64 0
%49 = call i32 @memset(i8* %48, i32 0, i32 250)
%50 = getelementptr inbounds [250 x i8], [250 x i8]* %9, i64 0, i64 0
%51 = load i32, i32* %6
%52 = load i8*, i8** %5
%53 = call i32 (i8*, i8*, ...) @sprintf(i8* %50, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.3, i64 0, i64 0), i32 %51, i8* %52)
%54 = load i32*, i32** %7
%55 = getelementptr inbounds [250 x i8], [250 x i8]* %9, i64 0, i64 0
%56 = call i32 @sqlite3_exec(i32* %54, i8* %55, i32* null, i32* null, i8** %10)
store i32 %56, i32* %8
%57 = load i32, i32* @SQLITE_OK
%58 = load i32, i32* %8
%59 = icmp ne i32 %57, %58
br i1 %59, label %60, label %63
60: ; preds = %45
%61 = load i8*, i8** %10
%62 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0), i8* %61)
store i32 2, i32* %4
br label %64
63: ; preds = %45
store i32 0, i32* %4
br label %64
64: ; preds = %63, %60, %44, %41
%65 = load i32, i32* %4
ret i32 %65
}

LLVM IR (-O2):
@.str = [49 x i8] c"select time from traffic_total where mobile='%s'\00"
@SQLITE_ROW = global i32 0
@.str.1 = [59 x i8] c"insert into traffic_total (mobile,time) values('%s','%ld')\00"
@SQLITE_OK = global i32 0
@.str.2 = [36 x i8] c"insert traffic_total.db error : %s\0A\00"
@.str.3 = [54 x i8] c"update traffic_total set time='%ld' where mobile='%s'\00"
@.str.4 = [36 x i8] c"update traffic_total.db error : %s\0A\00"
define i32 @traffic_total_collect(i8* %0, i32 %1, i32* %2) {
%4 = alloca [250 x i8]
%5 = alloca i8*
%6 = alloca i32*
%7 = getelementptr inbounds [250 x i8], [250 x i8]* %4, i64 0, i64 0
%8 = bitcast i8** %5 to i8*
%9 = bitcast i32** %6 to i8*
store i32* null, i32** %6
%10 = call i32 @memset(i8* %7, i32 0, i32 250)
%11 = call i32 (i8*, i8*, ...) @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i8* %0)
%12 = call i32 @sqlite3_prepare(i32* %2, i8* %7, i32 -1, i32** %6, i32 0)
%13 = load i32*, i32** %6
%14 = call i32 @sqlite3_step(i32* %13)
%15 = load i32, i32* @SQLITE_ROW
%16 = icmp eq i32 %14, %15
%17 = load i32*, i32** %6
%18 = call i32 @sqlite3_finalize(i32* %17)
%19 = call i32 @memset(i8* %7, i32 0, i32 250)
br i1 %16, label %28, label %20
20: ; preds = %3
%21 = call i32 (i8*, i8*, ...) @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([59 x i8], [59 x i8]* @.str.1, i64 0, i64 0), i8* %0, i32 %1)
%22 = call i32 @sqlite3_exec(i32* %2, i8* %7, i32* null, i32* null, i8** %5)
%23 = load i32, i32* @SQLITE_OK
%24 = icmp eq i32 %23, %22
br i1 %24, label %36, label %25
25: ; preds = %20
%26 = load i8*, i8** %5
%27 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i8* %26)
br label %36
28: ; preds = %3
%29 = call i32 (i8*, i8*, ...) @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([54 x i8], [54 x i8]* @.str.3, i64 0, i64 0), i32 %1, i8* %0)
%30 = call i32 @sqlite3_exec(i32* %2, i8* %7, i32* null, i32* null, i8** %5)
%31 = load i32, i32* @SQLITE_OK
%32 = icmp eq i32 %31, %30
br i1 %32, label %36, label %33
33: ; preds = %28
%34 = load i8*, i8** %5
%35 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0), i8* %34)
br label %36
36: ; preds = %28, %20, %33, %25
%37 = phi i32 [ 1, %25 ], [ 2, %33 ], [ 0, %20 ], [ 0, %28 ]
ret i32 %37
}