#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 *, char *, ...);
int sqlite3_column_int(int /*<<< orphan*/ *, int /*<<< orphan*/);
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_collect(char *mac_get, int time_get, sqlite3 *db) {
  int rc = 0;
  char sql[250] = {0};
  char *errmsg;
  int time_data = 0;
  sqlite3_stmt *ppstmt = NULL;
  memset(sql, 0, sizeof(sql));
  sprintf(sql,
          "select time from traffic_info where mobile='%s' order by time desc "
          "limit 1",
          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_info (mobile,time) values('%s','%ld')",
            mac_get, time_get);
    rc = sqlite3_exec(db, sql, NULL, NULL, &errmsg);
    if (SQLITE_OK != rc) {
      printf("insert traffic.db error : %s\n", errmsg);
      return 1;
    } else
      return 0;
  } else {
    time_data = sqlite3_column_int(ppstmt, 0);
    if (time_get - time_data > 43200) {
      sqlite3_finalize(ppstmt);
      memset(sql, 0, sizeof(sql));
      sprintf(sql, "insert into traffic_info (mobile,time) values('%s','%ld')",
              mac_get, time_get);
      rc = sqlite3_exec(db, sql, NULL, NULL, &errmsg);
      if (SQLITE_OK != rc) {
        printf("insert traffic.db error : %s\n", errmsg);
        return 2;
      } else
        return 0;
    } else {
      sqlite3_finalize(ppstmt);
      return 0;
    }
  }
}


x86 assembly (clang, -O0):
<traffic_collect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%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>
movl   $0x0,-0x12c(%rbp)
movq   $0x0,-0x138(%rbp)
lea    -0x120(%rbp),%rdi
xor    %esi,%esi
mov    $0xfa,%edx
call   1050 <memset@plt>
lea    -0x120(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe16(%rip),%rsi
mov    $0x0,%al
call   10a0 <sprintf@plt>
mov    -0x20(%rbp),%rdi
lea    -0x120(%rbp),%rsi
mov    $0xffffffff,%edx
lea    -0x138(%rbp),%rcx
xor    %r8d,%r8d
call   1080 <sqlite3_prepare@plt>
mov    -0x138(%rbp),%rdi
call   1070 <sqlite3_step@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    0x2daf(%rip),%rcx
cmp    (%rcx),%eax
je     12ca <traffic_collect+0x14a>
mov    -0x138(%rbp),%rdi
call   1090 <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   10a0 <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    0x2d54(%rip),%rax
mov    (%rax),%eax
cmp    -0x24(%rbp),%eax
je     12be <traffic_collect+0x13e>
mov    -0x128(%rbp),%rsi
lea    0xdd8(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    139e <traffic_collect+0x21e>
movl   $0x0,-0x4(%rbp)
jmp    139e <traffic_collect+0x21e>
mov    -0x138(%rbp),%rdi
xor    %esi,%esi
call   1060 <sqlite3_column_int@plt>
mov    %eax,-0x12c(%rbp)
mov    -0x14(%rbp),%eax
sub    -0x12c(%rbp),%eax
cmp    $0xa8c0,%eax
jle    138b <traffic_collect+0x20b>
mov    -0x138(%rbp),%rdi
call   1090 <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    0xd25(%rip),%rsi
mov    $0x0,%al
call   10a0 <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    0x2c93(%rip),%rax
mov    (%rax),%eax
cmp    -0x24(%rbp),%eax
je     137f <traffic_collect+0x1ff>
mov    -0x128(%rbp),%rsi
lea    0xd17(%rip),%rdi
call   1040 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    139e <traffic_collect+0x21e>
movl   $0x0,-0x4(%rbp)
jmp    139e <traffic_collect+0x21e>
mov    -0x138(%rbp),%rdi
call   1090 <sqlite3_finalize@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<traffic_collect>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x110,%rsp
mov    %rdx,%r14
mov    %esi,%r15d
mov    %rdi,%rbp
xorps  %xmm0,%xmm0
movups %xmm0,0xfa(%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)
movaps %xmm0,0x10(%rsp)
movq   $0x0,(%rsp)
lea    0x10(%rsp),%rbx
xor    %r12d,%r12d
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xfa,%edx
call   1050 <memset@plt>
lea    0xdd4(%rip),%rsi
mov    %rbx,%rdi
mov    %rbp,%rdx
xor    %eax,%eax
call   10a0 <sprintf@plt>
mov    %rsp,%rcx
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0xffffffff,%edx
xor    %r8d,%r8d
call   1080 <sqlite3_prepare@plt>
mov    (%rsp),%rdi
call   1070 <sqlite3_step@plt>
mov    0x2d79(%rip),%rcx
mov    (%rsp),%rdi
cmp    (%rcx),%eax
jne    12df <traffic_collect+0x15f>
xor    %r12d,%r12d
xor    %esi,%esi
call   1060 <sqlite3_column_int@plt>
mov    %r15d,%ebx
sub    %eax,%ebx
mov    (%rsp),%rdi
call   1090 <sqlite3_finalize@plt>
cmp    $0xa8c1,%ebx
jl     1347 <traffic_collect+0x1c7>
lea    0x10(%rsp),%rbx
xor    %r12d,%r12d
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xfa,%edx
call   1050 <memset@plt>
lea    0xda2(%rip),%rsi
mov    %rbx,%rdi
mov    %rbp,%rdx
mov    %r15d,%ecx
xor    %eax,%eax
call   10a0 <sprintf@plt>
lea    0x8(%rsp),%r8
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
call   1030 <sqlite3_exec@plt>
mov    0x2d14(%rip),%rcx
mov    $0x2,%ebx
cmp    %eax,(%rcx)
jne    1333 <traffic_collect+0x1b3>
jmp    1347 <traffic_collect+0x1c7>
call   1090 <sqlite3_finalize@plt>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xfa,%edx
call   1050 <memset@plt>
lea    0xd4c(%rip),%rsi
mov    %rbx,%rdi
mov    %rbp,%rdx
mov    %r15d,%ecx
xor    %eax,%eax
call   10a0 <sprintf@plt>
lea    0x8(%rsp),%r8
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
call   1030 <sqlite3_exec@plt>
mov    0x2cbe(%rip),%rcx
mov    $0x1,%ebx
cmp    %eax,(%rcx)
je     1347 <traffic_collect+0x1c7>
mov    0x8(%rsp),%rsi
lea    0xd46(%rip),%rdi
call   1040 <printf@plt>
mov    %ebx,%r12d
mov    %r12d,%eax
add    $0x110,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [75 x i8] c"select time from traffic_info where mobile='%s' order by time desc limit 1\00"
@SQLITE_ROW = global i32 0
@.str.1 = [58 x i8] c"insert into traffic_info (mobile,time) values('%s','%ld')\00"
@SQLITE_OK = global i32 0
@.str.2 = [30 x i8] c"insert traffic.db error : %s\0A\00"
define i32 @traffic_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
%12 = alloca i32*
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32* %2, i32** %7
store i32 0, i32* %8
%13 = bitcast [250 x i8]* %9 to i8*
store i32 0, i32* %11
store i32* null, i32** %12
%14 = getelementptr inbounds [250 x i8], [250 x i8]* %9, i64 0, i64 0
%15 = call i32 @memset(i8* %14, i32 0, i32 250)
%16 = getelementptr inbounds [250 x i8], [250 x i8]* %9, i64 0, i64 0
%17 = load i8*, i8** %5
%18 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %16, i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = load i32*, i32** %7
%20 = getelementptr inbounds [250 x i8], [250 x i8]* %9, i64 0, i64 0
%21 = call i32 @sqlite3_prepare(i32* %19, i8* %20, i32 -1, i32** %12, i32 0)
%22 = load i32*, i32** %12
%23 = call i32 @sqlite3_step(i32* %22)
store i32 %23, i32* %8
%24 = load i32, i32* %8
%25 = load i32, i32* @SQLITE_ROW
%26 = icmp ne i32 %24, %25
br i1 %26, label %27, label %46
27: ; preds = %3
%28 = load i32*, i32** %12
%29 = call i32 @sqlite3_finalize(i32* %28)
%30 = getelementptr inbounds [250 x i8], [250 x i8]* %9, i64 0, i64 0
%31 = call i32 @memset(i8* %30, i32 0, i32 250)
%32 = getelementptr inbounds [250 x i8], [250 x i8]* %9, i64 0, i64 0
%33 = load i8*, i8** %5
%34 = load i32, i32* %6
%35 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %32, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.1, i64 0, i64 0), i8* %33, i32 %34)
%36 = load i32*, i32** %7
%37 = getelementptr inbounds [250 x i8], [250 x i8]* %9, i64 0, i64 0
%38 = call i32 @sqlite3_exec(i32* %36, i8* %37, i32* null, i32* null, i8** %10)
store i32 %38, i32* %8
%39 = load i32, i32* @SQLITE_OK
%40 = load i32, i32* %8
%41 = icmp ne i32 %39, %40
br i1 %41, label %42, label %45
42: ; preds = %27
%43 = load i8*, i8** %10
%44 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* %43)
store i32 1, i32* %4
br label %75
45: ; preds = %27
store i32 0, i32* %4
br label %75
46: ; preds = %3
%47 = load i32*, i32** %12
%48 = call i32 @sqlite3_column_int(i32* %47, i32 0)
store i32 %48, i32* %11
%49 = load i32, i32* %6
%50 = load i32, i32* %11
%51 = sub nsw i32 %49, %50
%52 = icmp sgt i32 %51, 43200
br i1 %52, label %53, label %72
53: ; preds = %46
%54 = load i32*, i32** %12
%55 = call i32 @sqlite3_finalize(i32* %54)
%56 = getelementptr inbounds [250 x i8], [250 x i8]* %9, i64 0, i64 0
%57 = call i32 @memset(i8* %56, i32 0, i32 250)
%58 = getelementptr inbounds [250 x i8], [250 x i8]* %9, i64 0, i64 0
%59 = load i8*, i8** %5
%60 = load i32, i32* %6
%61 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %58, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.1, i64 0, i64 0), i8* %59, i32 %60)
%62 = load i32*, i32** %7
%63 = getelementptr inbounds [250 x i8], [250 x i8]* %9, i64 0, i64 0
%64 = call i32 @sqlite3_exec(i32* %62, i8* %63, i32* null, i32* null, i8** %10)
store i32 %64, i32* %8
%65 = load i32, i32* @SQLITE_OK
%66 = load i32, i32* %8
%67 = icmp ne i32 %65, %66
br i1 %67, label %68, label %71
68: ; preds = %53
%69 = load i8*, i8** %10
%70 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* %69)
store i32 2, i32* %4
br label %75
71: ; preds = %53
store i32 0, i32* %4
br label %75
72: ; preds = %46
%73 = load i32*, i32** %12
%74 = call i32 @sqlite3_finalize(i32* %73)
store i32 0, i32* %4
br label %75
75: ; preds = %72, %71, %68, %45, %42
%76 = load i32, i32* %4
ret i32 %76
}

LLVM IR (-O2):
@.str = [75 x i8] c"select time from traffic_info where mobile='%s' order by time desc limit 1\00"
@SQLITE_ROW = global i32 0
@.str.1 = [58 x i8] c"insert into traffic_info (mobile,time) values('%s','%ld')\00"
@SQLITE_OK = global i32 0
@.str.2 = [30 x i8] c"insert traffic.db error : %s\0A\00"
define i32 @traffic_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*, i8*, ...) @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([75 x i8], [75 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
br i1 %16, label %25, label %18
18: ; preds = %3
%19 = call i32 @sqlite3_finalize(i32* %17)
%20 = call i32 @memset(i8* %7, i32 0, i32 250)
%21 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([58 x i8], [58 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 %41, label %37
25: ; preds = %3
%26 = call i32 @sqlite3_column_int(i32* %17, i32 0)
%27 = sub nsw i32 %1, %26
%28 = icmp sgt i32 %27, 43200
%29 = load i32*, i32** %6
%30 = call i32 @sqlite3_finalize(i32* %29)
br i1 %28, label %31, label %41
31: ; preds = %25
%32 = call i32 @memset(i8* %7, i32 0, i32 250)
%33 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([58 x i8], [58 x i8]* @.str.1, i64 0, i64 0), i8* %0, i32 %1)
%34 = call i32 @sqlite3_exec(i32* %2, i8* %7, i32* null, i32* null, i8** %5)
%35 = load i32, i32* @SQLITE_OK
%36 = icmp eq i32 %35, %34
br i1 %36, label %41, label %37
37: ; preds = %31, %18
%38 = phi i32 [ 1, %18 ], [ 2, %31 ]
%39 = load i8*, i8** %5
%40 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* %39)
br label %41
41: ; preds = %37, %25, %31, %18
%42 = phi i32 [ 0, %18 ], [ 0, %31 ], [ 0, %25 ], [ %38, %37 ]
ret i32 %42
}