#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*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sprintf(char *, char *, ...);
int /*<<< orphan*/ sqlite3_close(int /*<<< orphan*/ *);
char *sqlite3_column_text(int /*<<< orphan*/ *, int /*<<< orphan*/);
char *sqlite3_errmsg(int /*<<< orphan*/ *);
int sqlite3_exec(int /*<<< orphan*/ *, char *, int /*<<< orphan*/ *,
                 int /*<<< orphan*/ *, char **);
int /*<<< orphan*/ sqlite3_finalize(int /*<<< orphan*/ *);
int sqlite3_open(char *, int /*<<< orphan*/ **);
int sqlite3_prepare(int /*<<< orphan*/ *, char *, int, int /*<<< orphan*/ **,
                    int /*<<< orphan*/);
int sqlite3_step(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int time(int /*<<< orphan*/ *);
void record_staff() {
  int rc1 = 0, rc2 = 0;
  char *errmsg;
  const char *staff_mobile = NULL;
  char sql[250] = {0};
  sqlite3 *db1, *db2;
  sqlite3_stmt *ppstmt1 = NULL, *ppstmt2 = NULL;
  rc1 = sqlite3_open("/ailvgo/system/traffic/traffic.db", &db1);
  if (rc1 != SQLITE_OK) {
    printf("open traffic.db error!\n");
    sqlite3_close(db1);
    return;
  }
  rc2 = sqlite3_open("/ailvgo/system/traffic/staff.db", &db2);
  if (rc2 != SQLITE_OK) {
    printf("open staff.db erro!\n");
    sqlite3_close(db2);
    return;
  }
  memset(sql, 0, sizeof(sql));
  sprintf(sql,
          "select distinct mobile from traffic_info where mobile in (select "
          "mobile from traffic_info group by mobile having count(mobile) > 4)");
  rc1 = sqlite3_prepare(db1, sql, -1, &ppstmt1, 0);
  if (rc1 != SQLITE_OK) {
    fprintf(stderr, "SQL error:%s\n", sqlite3_errmsg(db1));
    return;
  }
  rc1 = sqlite3_step(ppstmt1);
  if (rc1 != SQLITE_ROW) {
    printf("no staff mac found in traffic.db!\n");
    sqlite3_finalize(ppstmt1);
    sqlite3_close(db1);
    sqlite3_close(db2);
    return;
  }
  while (rc1 == SQLITE_ROW) {
    staff_mobile = sqlite3_column_text(ppstmt1, 0);
    printf("staff_mac : %s\n", staff_mobile);
    memset(sql, 0, sizeof(sql));
    sprintf(sql, "select * from staff_info where mobile ='%s'", staff_mobile);
    rc2 = sqlite3_prepare(db2, sql, -1, &ppstmt2, 0);
    if (rc2 != SQLITE_OK)
      fprintf(stderr, "SQL error:%s\n", sqlite3_errmsg(db2));
    rc2 = sqlite3_step(ppstmt2);
    if (rc2 == SQLITE_ROW) {
      printf("staff_mac : exist in staff.db, update time\n");
      memset(sql, 0, sizeof(sql));
      sprintf(sql, "update staff_info set time='%d' where mobile='%s'",
              time(NULL), staff_mobile);
    } else {
      printf("staff_mac : new, insert into staff.db!\n");
      memset(sql, 0, sizeof(sql));
      sprintf(sql, "insert into staff_info (mobile, time) values('%s', %d)",
              staff_mobile, time(NULL));
    }
    rc2 = sqlite3_exec(db2, sql, NULL, NULL, &errmsg);
    if (rc2 != SQLITE_OK)
      printf("insert/update staff.db error:%s\n", errmsg);
    rc1 = sqlite3_step(ppstmt1);
  }
  sqlite3_finalize(ppstmt1);
  sqlite3_finalize(ppstmt2);
  sqlite3_close(db1);
  sqlite3_close(db2);
}


x86 assembly (clang, -O0):
<record_staff>:
push   %rbp
mov    %rsp,%rbp
sub    $0x160,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movq   $0x0,-0x18(%rbp)
lea    -0x120(%rbp),%rdi
xor    %esi,%esi
mov    $0xfa,%edx
call   1060 <memset@plt>
movq   $0x0,-0x138(%rbp)
movq   $0x0,-0x140(%rbp)
lea    0xddf(%rip),%rdi
lea    -0x128(%rbp),%rsi
call   1040 <sqlite3_open@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    0x2dae(%rip),%rcx
cmp    (%rcx),%eax
je     1261 <record_staff+0x91>
lea    0xdd9(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x128(%rbp),%rdi
call   10a0 <sqlite3_close@plt>
jmp    15c5 <record_staff+0x3f5>
lea    0xdd2(%rip),%rdi
lea    -0x130(%rbp),%rsi
call   1040 <sqlite3_open@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    0x2d67(%rip),%rcx
cmp    (%rcx),%eax
je     12a8 <record_staff+0xd8>
lea    0xdca(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x130(%rbp),%rdi
call   10a0 <sqlite3_close@plt>
jmp    15c5 <record_staff+0x3f5>
lea    -0x120(%rbp),%rdi
xor    %esi,%esi
mov    $0xfa,%edx
call   1060 <memset@plt>
lea    -0x120(%rbp),%rdi
lea    0xda6(%rip),%rsi
mov    $0x0,%al
call   10f0 <sprintf@plt>
mov    -0x128(%rbp),%rdi
lea    -0x120(%rbp),%rsi
mov    $0xffffffff,%edx
lea    -0x138(%rbp),%rcx
xor    %r8d,%r8d
call   10d0 <sqlite3_prepare@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    0x2ce9(%rip),%rcx
cmp    (%rcx),%eax
je     133c <record_staff+0x16c>
mov    0x2cca(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x144(%rbp)
mov    -0x128(%rbp),%rdi
call   1070 <sqlite3_errmsg@plt>
mov    -0x144(%rbp),%edi
mov    %rax,%rdx
lea    0xdc1(%rip),%rsi
call   1090 <fprintf@plt>
jmp    15c5 <record_staff+0x3f5>
mov    -0x138(%rbp),%rdi
call   1080 <sqlite3_step@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    0x2c7b(%rip),%rcx
cmp    (%rcx),%eax
je     1394 <record_staff+0x1c4>
lea    0xd9d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x138(%rbp),%rdi
call   10e0 <sqlite3_finalize@plt>
mov    -0x128(%rbp),%rdi
call   10a0 <sqlite3_close@plt>
mov    -0x130(%rbp),%rdi
call   10a0 <sqlite3_close@plt>
jmp    15c5 <record_staff+0x3f5>
jmp    1399 <record_staff+0x1c9>
mov    -0x4(%rbp),%eax
mov    0x2c2d(%rip),%rcx
cmp    (%rcx),%eax
jne    1595 <record_staff+0x3c5>
mov    -0x138(%rbp),%rdi
xor    %esi,%esi
call   10c0 <sqlite3_column_text@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xd5c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x120(%rbp),%rdi
xor    %esi,%esi
mov    $0xfa,%edx
call   1060 <memset@plt>
lea    -0x120(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xd40(%rip),%rsi
mov    $0x0,%al
call   10f0 <sprintf@plt>
mov    -0x130(%rbp),%rdi
lea    -0x120(%rbp),%rsi
mov    $0xffffffff,%edx
lea    -0x140(%rbp),%rcx
xor    %r8d,%r8d
call   10d0 <sqlite3_prepare@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    0x2bbe(%rip),%rcx
cmp    (%rcx),%eax
je     1462 <record_staff+0x292>
mov    0x2b9f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x148(%rbp)
mov    -0x130(%rbp),%rdi
call   1070 <sqlite3_errmsg@plt>
mov    -0x148(%rbp),%edi
mov    %rax,%rdx
lea    0xc96(%rip),%rsi
call   1090 <fprintf@plt>
mov    -0x140(%rbp),%rdi
call   1080 <sqlite3_step@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    0x2b55(%rip),%rcx
cmp    (%rcx),%eax
jne    14db <record_staff+0x30b>
lea    0xcd6(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x120(%rbp),%rdi
xor    %esi,%esi
mov    $0xfa,%edx
call   1060 <memset@plt>
lea    -0x120(%rbp),%rax
mov    %rax,-0x150(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   10b0 <time@plt>
mov    -0x150(%rbp),%rdi
mov    %eax,%edx
mov    -0x18(%rbp),%rcx
lea    0xcbd(%rip),%rsi
mov    $0x0,%al
call   10f0 <sprintf@plt>
jmp    153c <record_staff+0x36c>
lea    0xcdc(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x120(%rbp),%rdi
xor    %esi,%esi
mov    $0xfa,%edx
call   1060 <memset@plt>
lea    -0x120(%rbp),%rax
mov    %rax,-0x160(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x158(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   10b0 <time@plt>
mov    -0x160(%rbp),%rdi
mov    -0x158(%rbp),%rdx
mov    %eax,%ecx
lea    0xcb1(%rip),%rsi
mov    $0x0,%al
call   10f0 <sprintf@plt>
mov    -0x130(%rbp),%rdi
lea    -0x120(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x10(%rbp),%r8
mov    %rcx,%rdx
call   1030 <sqlite3_exec@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    0x2a81(%rip),%rcx
cmp    (%rcx),%eax
je     1581 <record_staff+0x3b1>
mov    -0x10(%rbp),%rsi
lea    0xca3(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x138(%rbp),%rdi
call   1080 <sqlite3_step@plt>
mov    %eax,-0x4(%rbp)
jmp    1399 <record_staff+0x1c9>
mov    -0x138(%rbp),%rdi
call   10e0 <sqlite3_finalize@plt>
mov    -0x140(%rbp),%rdi
call   10e0 <sqlite3_finalize@plt>
mov    -0x128(%rbp),%rdi
call   10a0 <sqlite3_close@plt>
mov    -0x130(%rbp),%rdi
call   10a0 <sqlite3_close@plt>
add    $0x160,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<record_staff>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x138,%rsp
xorps  %xmm0,%xmm0
movups %xmm0,0x11a(%rsp)
movaps %xmm0,0x110(%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)
movq   $0x0,0x8(%rsp)
movq   $0x0,0x20(%rsp)
lea    0xd72(%rip),%rdi
lea    0x18(%rsp),%rsi
call   1050 <sqlite3_open@plt>
mov    0x2d49(%rip),%r12
cmp    (%r12),%eax
jne    14a0 <record_staff+0x2b0>
lea    0xd72(%rip),%rdi
lea    0x10(%rsp),%rsi
call   1050 <sqlite3_open@plt>
cmp    (%r12),%eax
jne    14b3 <record_staff+0x2c3>
lea    0x30(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xfa,%edx
call   1070 <memset@plt>
lea    0xd63(%rip),%rsi
mov    $0x84,%edx
mov    %rbx,%rdi
call   10b0 <memcpy@plt>
mov    0x18(%rsp),%rdi
lea    0x8(%rsp),%rcx
mov    %rbx,%rsi
mov    $0xffffffff,%edx
xor    %r8d,%r8d
call   10f0 <sqlite3_prepare@plt>
cmp    (%r12),%eax
jne    14c1 <record_staff+0x2d1>
mov    0x8(%rsp),%rdi
call   1090 <sqlite3_step@plt>
mov    0x2caf(%rip),%rbx
cmp    (%rbx),%eax
jne    14e7 <record_staff+0x2f7>
lea    0xda4(%rip),%r14
lea    0x30(%rsp),%rbp
lea    0xda8(%rip),%r13
jmp    1352 <record_staff+0x162>
xchg   %ax,%ax
mov    0x8(%rsp),%rdi
call   1090 <sqlite3_step@plt>
cmp    (%rbx),%eax
jne    14fa <record_staff+0x30a>
mov    0x8(%rsp),%rdi
xor    %esi,%esi
call   10e0 <sqlite3_column_text@plt>
mov    %rax,%r15
mov    %r14,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0xfa,%edx
call   1070 <memset@plt>
mov    %rbp,%rdi
mov    %r13,%rsi
mov    %r15,%rdx
xor    %eax,%eax
call   1110 <sprintf@plt>
mov    0x10(%rsp),%rdi
mov    %rbp,%rsi
mov    $0xffffffff,%edx
lea    0x20(%rsp),%rcx
xor    %r8d,%r8d
call   10f0 <sqlite3_prepare@plt>
cmp    (%r12),%eax
je     13e6 <record_staff+0x1f6>
mov    %r13,%rbx
mov    %r14,%r13
mov    0x2c1e(%rip),%rax
mov    (%rax),%r14d
mov    0x10(%rsp),%rdi
call   1080 <sqlite3_errmsg@plt>
mov    %r14d,%edi
mov    %r13,%r14
mov    %rbx,%r13
mov    0x2bf9(%rip),%rbx
lea    0xce8(%rip),%rsi
mov    %rax,%rdx
call   10a0 <fprintf@plt>
mov    0x20(%rsp),%rdi
call   1090 <sqlite3_step@plt>
cmp    (%rbx),%eax
jne    1430 <record_staff+0x240>
lea    0xdc6(%rip),%rdi
call   1030 <puts@plt>
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0xfa,%edx
call   1070 <memset@plt>
xor    %edi,%edi
call   10d0 <time@plt>
mov    %rbp,%rdi
lea    0xcf0(%rip),%rsi
mov    %eax,%edx
mov    %r15,%rcx
xor    %eax,%eax
call   1110 <sprintf@plt>
jmp    1468 <record_staff+0x278>
xchg   %ax,%ax
lea    0xd63(%rip),%rdi
call   1030 <puts@plt>
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0xfa,%edx
call   1070 <memset@plt>
xor    %edi,%edi
call   10d0 <time@plt>
mov    %rbp,%rdi
lea    0xce6(%rip),%rsi
mov    %r15,%rdx
mov    %eax,%ecx
xor    %eax,%eax
call   1110 <sprintf@plt>
mov    0x10(%rsp),%rdi
mov    %rbp,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
lea    0x28(%rsp),%r8
call   1040 <sqlite3_exec@plt>
cmp    (%r12),%eax
je     1340 <record_staff+0x150>
mov    0x28(%rsp),%rsi
lea    0xce5(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    1340 <record_staff+0x150>
lea    0xd7b(%rip),%rdi
call   1030 <puts@plt>
mov    0x18(%rsp),%rdi
jmp    151d <record_staff+0x32d>
lea    0xd54(%rip),%rdi
call   1030 <puts@plt>
jmp    1518 <record_staff+0x328>
mov    0x2b10(%rip),%rax
mov    (%rax),%ebx
mov    0x18(%rsp),%rdi
call   1080 <sqlite3_errmsg@plt>
lea    0xbeb(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   10a0 <fprintf@plt>
jmp    1522 <record_staff+0x332>
lea    0xcfe(%rip),%rdi
call   1030 <puts@plt>
mov    0x8(%rsp),%rdi
jmp    1509 <record_staff+0x319>
mov    0x8(%rsp),%rdi
call   1100 <sqlite3_finalize@plt>
mov    0x20(%rsp),%rdi
call   1100 <sqlite3_finalize@plt>
mov    0x18(%rsp),%rdi
call   10c0 <sqlite3_close@plt>
mov    0x10(%rsp),%rdi
call   10c0 <sqlite3_close@plt>
add    $0x138,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [34 x i8] c"/ailvgo/system/traffic/traffic.db\00"
@SQLITE_OK = global i32 0
@.str.1 = [24 x i8] c"open traffic.db error!\0A\00"
@.str.2 = [32 x i8] c"/ailvgo/system/traffic/staff.db\00"
@.str.3 = [21 x i8] c"open staff.db erro!\0A\00"
@.str.4 = [132 x i8] c"select distinct mobile from traffic_info where mobile in (select mobile from traffic_info group by mobile having count(mobile) > 4)\00"
@stderr = global i32 0
@.str.5 = [14 x i8] c"SQL error:%s\0A\00"
@SQLITE_ROW = global i32 0
@.str.6 = [35 x i8] c"no staff mac found in traffic.db!\0A\00"
@.str.7 = [16 x i8] c"staff_mac : %s\0A\00"
@.str.8 = [44 x i8] c"select * from staff_info where mobile ='%s'\00"
@.str.9 = [44 x i8] c"staff_mac : exist in staff.db, update time\0A\00"
@.str.10 = [50 x i8] c"update staff_info set time='%d' where mobile='%s'\00"
@.str.11 = [40 x i8] c"staff_mac : new, insert into staff.db!\0A\00"
@.str.12 = [55 x i8] c"insert into staff_info (mobile, time) values('%s', %d)\00"
@.str.13 = [33 x i8] c"insert/update staff.db error:%s\0A\00"
define void @record_staff() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [250 x i8]
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32*
store i32 0, i32* %1
store i32 0, i32* %2
store i8* null, i8** %4
%10 = bitcast [250 x i8]* %5 to i8*
store i32* null, i32** %8
store i32* null, i32** %9
%11 = call i32 @sqlite3_open(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32** %6)
store i32 %11, i32* %1
%12 = load i32, i32* %1
%13 = load i32, i32* @SQLITE_OK
%14 = icmp ne i32 %12, %13
br i1 %14, label %15, label %19
15: ; preds = %0
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
%17 = load i32*, i32** %6
%18 = call i32 @sqlite3_close(i32* %17)
br label %128
19: ; preds = %0
%20 = call i32 @sqlite3_open(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i32** %7)
store i32 %20, i32* %2
%21 = load i32, i32* %2
%22 = load i32, i32* @SQLITE_OK
%23 = icmp ne i32 %21, %22
br i1 %23, label %24, label %28
24: ; preds = %19
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
%26 = load i32*, i32** %7
%27 = call i32 @sqlite3_close(i32* %26)
br label %128
28: ; preds = %19
%29 = getelementptr inbounds [250 x i8], [250 x i8]* %5, i64 0, i64 0
%30 = call i32 @memset(i8* %29, i32 0, i32 250)
%31 = getelementptr inbounds [250 x i8], [250 x i8]* %5, i64 0, i64 0
%32 = call i32 (i8*, i8*, ...) @sprintf(i8* %31, i8* getelementptr inbounds ([132 x i8], [132 x i8]* @.str.4, i64 0, i64 0))
%33 = load i32*, i32** %6
%34 = getelementptr inbounds [250 x i8], [250 x i8]* %5, i64 0, i64 0
%35 = call i32 @sqlite3_prepare(i32* %33, i8* %34, i32 -1, i32** %8, i32 0)
store i32 %35, i32* %1
%36 = load i32, i32* %1
%37 = load i32, i32* @SQLITE_OK
%38 = icmp ne i32 %36, %37
br i1 %38, label %39, label %44
39: ; preds = %28
%40 = load i32, i32* @stderr
%41 = load i32*, i32** %6
%42 = call i8* @sqlite3_errmsg(i32* %41)
%43 = call i32 @fprintf(i32 %40, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i8* %42)
br label %128
44: ; preds = %28
%45 = load i32*, i32** %8
%46 = call i32 @sqlite3_step(i32* %45)
store i32 %46, i32* %1
%47 = load i32, i32* %1
%48 = load i32, i32* @SQLITE_ROW
%49 = icmp ne i32 %47, %48
br i1 %49, label %50, label %58
50: ; preds = %44
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.6, i64 0, i64 0))
%52 = load i32*, i32** %8
%53 = call i32 @sqlite3_finalize(i32* %52)
%54 = load i32*, i32** %6
%55 = call i32 @sqlite3_close(i32* %54)
%56 = load i32*, i32** %7
%57 = call i32 @sqlite3_close(i32* %56)
br label %128
58: ; preds = %44
br label %59
59: ; preds = %116, %58
%60 = load i32, i32* %1
%61 = load i32, i32* @SQLITE_ROW
%62 = icmp eq i32 %60, %61
br i1 %62, label %63, label %119
63: ; preds = %59
%64 = load i32*, i32** %8
%65 = call i8* @sqlite3_column_text(i32* %64, i32 0)
store i8* %65, i8** %4
%66 = load i8*, i8** %4
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0), i8* %66)
%68 = getelementptr inbounds [250 x i8], [250 x i8]* %5, i64 0, i64 0
%69 = call i32 @memset(i8* %68, i32 0, i32 250)
%70 = getelementptr inbounds [250 x i8], [250 x i8]* %5, i64 0, i64 0
%71 = load i8*, i8** %4
%72 = call i32 (i8*, i8*, ...) @sprintf(i8* %70, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.8, i64 0, i64 0), i8* %71)
%73 = load i32*, i32** %7
%74 = getelementptr inbounds [250 x i8], [250 x i8]* %5, i64 0, i64 0
%75 = call i32 @sqlite3_prepare(i32* %73, i8* %74, i32 -1, i32** %9, i32 0)
store i32 %75, i32* %2
%76 = load i32, i32* %2
%77 = load i32, i32* @SQLITE_OK
%78 = icmp ne i32 %76, %77
br i1 %78, label %79, label %84
79: ; preds = %63
%80 = load i32, i32* @stderr
%81 = load i32*, i32** %7
%82 = call i8* @sqlite3_errmsg(i32* %81)
%83 = call i32 @fprintf(i32 %80, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i8* %82)
br label %84
84: ; preds = %79, %63
%85 = load i32*, i32** %9
%86 = call i32 @sqlite3_step(i32* %85)
store i32 %86, i32* %2
%87 = load i32, i32* %2
%88 = load i32, i32* @SQLITE_ROW
%89 = icmp eq i32 %87, %88
br i1 %89, label %90, label %98
90: ; preds = %84
%91 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.9, i64 0, i64 0))
%92 = getelementptr inbounds [250 x i8], [250 x i8]* %5, i64 0, i64 0
%93 = call i32 @memset(i8* %92, i32 0, i32 250)
%94 = getelementptr inbounds [250 x i8], [250 x i8]* %5, i64 0, i64 0
%95 = call i32 @time(i32* null)
%96 = load i8*, i8** %4
%97 = call i32 (i8*, i8*, ...) @sprintf(i8* %94, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.10, i64 0, i64 0), i32 %95, i8* %96)
br label %106
98: ; preds = %84
%99 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.11, i64 0, i64 0))
%100 = getelementptr inbounds [250 x i8], [250 x i8]* %5, i64 0, i64 0
%101 = call i32 @memset(i8* %100, i32 0, i32 250)
%102 = getelementptr inbounds [250 x i8], [250 x i8]* %5, i64 0, i64 0
%103 = load i8*, i8** %4
%104 = call i32 @time(i32* null)
%105 = call i32 (i8*, i8*, ...) @sprintf(i8* %102, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.12, i64 0, i64 0), i8* %103, i32 %104)
br label %106
106: ; preds = %98, %90
%107 = load i32*, i32** %7
%108 = getelementptr inbounds [250 x i8], [250 x i8]* %5, i64 0, i64 0
%109 = call i32 @sqlite3_exec(i32* %107, i8* %108, i32* null, i32* null, i8** %3)
store i32 %109, i32* %2
%110 = load i32, i32* %2
%111 = load i32, i32* @SQLITE_OK
%112 = icmp ne i32 %110, %111
br i1 %112, label %113, label %116
113: ; preds = %106
%114 = load i8*, i8** %3
%115 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.13, i64 0, i64 0), i8* %114)
br label %116
116: ; preds = %113, %106
%117 = load i32*, i32** %8
%118 = call i32 @sqlite3_step(i32* %117)
store i32 %118, i32* %1
br label %59
119: ; preds = %59
%120 = load i32*, i32** %8
%121 = call i32 @sqlite3_finalize(i32* %120)
%122 = load i32*, i32** %9
%123 = call i32 @sqlite3_finalize(i32* %122)
%124 = load i32*, i32** %6
%125 = call i32 @sqlite3_close(i32* %124)
%126 = load i32*, i32** %7
%127 = call i32 @sqlite3_close(i32* %126)
br label %128
128: ; preds = %119, %50, %39, %24, %15
ret void
}

LLVM IR (-O2):
@.str = [34 x i8] c"/ailvgo/system/traffic/traffic.db\00"
@SQLITE_OK = global i32 0
@.str.2 = [32 x i8] c"/ailvgo/system/traffic/staff.db\00"
@.str.4 = [132 x i8] c"select distinct mobile from traffic_info where mobile in (select mobile from traffic_info group by mobile having count(mobile) > 4)\00"
@stderr = global i32 0
@.str.5 = [14 x i8] c"SQL error:%s\0A\00"
@SQLITE_ROW = global i32 0
@.str.7 = [16 x i8] c"staff_mac : %s\0A\00"
@.str.8 = [44 x i8] c"select * from staff_info where mobile ='%s'\00"
@.str.10 = [50 x i8] c"update staff_info set time='%d' where mobile='%s'\00"
@.str.12 = [55 x i8] c"insert into staff_info (mobile, time) values('%s', %d)\00"
@.str.13 = [33 x i8] c"insert/update staff.db error:%s\0A\00"
@str = [39 x i8] c"staff_mac : new, insert into staff.db!\00"
@str.14 = [43 x i8] c"staff_mac : exist in staff.db, update time\00"
@str.15 = [34 x i8] c"no staff mac found in traffic.db!\00"
@str.16 = [20 x i8] c"open staff.db erro!\00"
@str.17 = [23 x i8] c"open traffic.db error!\00"
define void @record_staff() {
%1 = alloca i8*
%2 = alloca [250 x i8]
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32*
%7 = bitcast i8** %1 to i8*
%8 = getelementptr inbounds [250 x i8], [250 x i8]* %2, i64 0, i64 0
%9 = bitcast i32** %3 to i8*
%10 = bitcast i32** %4 to i8*
%11 = bitcast i32** %5 to i8*
store i32* null, i32** %5
%12 = bitcast i32** %6 to i8*
store i32* null, i32** %6
%13 = call i32 @sqlite3_open(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32** %3)
%14 = load i32, i32* @SQLITE_OK
%15 = icmp eq i32 %13, %14
br i1 %15, label %20, label %16
16: ; preds = %0
%17 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.17, i64 0, i64 0))
%18 = load i32*, i32** %3
%19 = call i32 @sqlite3_close(i32* %18)
br label %104
20: ; preds = %0
%21 = call i32 @sqlite3_open(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i32** %4)
%22 = load i32, i32* @SQLITE_OK
%23 = icmp eq i32 %21, %22
br i1 %23, label %28, label %24
24: ; preds = %20
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.16, i64 0, i64 0))
%26 = load i32*, i32** %4
%27 = call i32 @sqlite3_close(i32* %26)
br label %104
28: ; preds = %20
%29 = call i32 @memset(i8* %8, i32 0, i32 250)
%30 = load i32*, i32** %3
%31 = call i32 @sqlite3_prepare(i32* %30, i8* %8, i32 -1, i32** %5, i32 0)
%32 = load i32, i32* @SQLITE_OK
%33 = icmp eq i32 %31, %32
br i1 %33, label %39, label %34
34: ; preds = %28
%35 = load i32, i32* @stderr
%36 = load i32*, i32** %3
%37 = call i8* @sqlite3_errmsg(i32* %36)
%38 = call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i8* %37)
br label %104
39: ; preds = %28
%40 = load i32*, i32** %5
%41 = call i32 @sqlite3_step(i32* %40)
%42 = load i32, i32* @SQLITE_ROW
%43 = icmp eq i32 %41, %42
br i1 %43, label %52, label %44
44: ; preds = %39
%45 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str.15, i64 0, i64 0))
%46 = load i32*, i32** %5
%47 = call i32 @sqlite3_finalize(i32* %46)
%48 = load i32*, i32** %3
%49 = call i32 @sqlite3_close(i32* %48)
%50 = load i32*, i32** %4
%51 = call i32 @sqlite3_close(i32* %50)
br label %104
52: ; preds = %39, %90
%53 = load i32*, i32** %5
%54 = call i8* @sqlite3_column_text(i32* %53, i32 0)
%55 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0), i8* %54)
%56 = call i32 @memset(i8* %8, i32 0, i32 250)
%57 = call i32 (i8*, i8*, ...) @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.8, i64 0, i64 0), i8* %54)
%58 = load i32*, i32** %4
%59 = call i32 @sqlite3_prepare(i32* %58, i8* %8, i32 -1, i32** %6, i32 0)
%60 = load i32, i32* @SQLITE_OK
%61 = icmp eq i32 %59, %60
br i1 %61, label %67, label %62
62: ; preds = %52
%63 = load i32, i32* @stderr
%64 = load i32*, i32** %4
%65 = call i8* @sqlite3_errmsg(i32* %64)
%66 = call i32 @fprintf(i32 %63, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i8* %65)
br label %67
67: ; preds = %62, %52
%68 = load i32*, i32** %6
%69 = call i32 @sqlite3_step(i32* %68)
%70 = load i32, i32* @SQLITE_ROW
%71 = icmp eq i32 %69, %70
br i1 %71, label %72, label %77
72: ; preds = %67
%73 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @str.14, i64 0, i64 0))
%74 = call i32 @memset(i8* %8, i32 0, i32 250)
%75 = call i32 @time(i32* null)
%76 = call i32 (i8*, i8*, ...) @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @.str.10, i64 0, i64 0), i32 %75, i8* %54)
br label %82
77: ; preds = %67
%78 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str, i64 0, i64 0))
%79 = call i32 @memset(i8* %8, i32 0, i32 250)
%80 = call i32 @time(i32* null)
%81 = call i32 (i8*, i8*, ...) @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @.str.12, i64 0, i64 0), i8* %54, i32 %80)
br label %82
82: ; preds = %77, %72
%83 = load i32*, i32** %4
%84 = call i32 @sqlite3_exec(i32* %83, i8* %8, i32* null, i32* null, i8** %1)
%85 = load i32, i32* @SQLITE_OK
%86 = icmp eq i32 %84, %85
br i1 %86, label %90, label %87
87: ; preds = %82
%88 = load i8*, i8** %1
%89 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.13, i64 0, i64 0), i8* %88)
br label %90
90: ; preds = %87, %82
%91 = load i32*, i32** %5
%92 = call i32 @sqlite3_step(i32* %91)
%93 = load i32, i32* @SQLITE_ROW
%94 = icmp eq i32 %92, %93
br i1 %94, label %52, label %95
95: ; preds = %90
%96 = load i32*, i32** %5
%97 = call i32 @sqlite3_finalize(i32* %96)
%98 = load i32*, i32** %6
%99 = call i32 @sqlite3_finalize(i32* %98)
%100 = load i32*, i32** %3
%101 = call i32 @sqlite3_close(i32* %100)
%102 = load i32*, i32** %4
%103 = call i32 @sqlite3_close(i32* %102)
br label %104
104: ; preds = %95, %44, %34, %24, %16
ret void
}