#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 */
struct timeval {
  int tv_sec;
};
typedef int /*<<< orphan*/ sqlite3;

/* Variables and functions */
scalar_t__ SQLITE_OK;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int query_int(int /*<<< orphan*/ *, char *);
scalar_t__ sql_exec(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ sqlite3_close(int /*<<< orphan*/ *);
int /*<<< orphan*/ sqlite3_free(char *);
char *sqlite3_mprintf(char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
void batch_process(sqlite3 *db) {
  int rc;
  int cur_essid = 0;
  struct timeval starttime;
  struct timeval curtime;
  gettimeofday(&starttime, NULL);
  int rowcount = 0;
  char *sql;
  if (sql_exec(
          db,
          "CREATE TEMPORARY TABLE temp.buffer (wb_id integer, essid_id "
          "integer, passwd_id integer, essid text, passwd text, pmk blob);") !=
      SQLITE_OK) {
    fprintf(stderr, "Failed to create buffer for batch processing.\n");
    return;
  }
  cur_essid = query_int(db, "SELECT essid_id FROM workbench LIMIT 1;");
  while (1) {
    do {
      do {
        sql_exec(db, "DELETE FROM temp.buffer;");
        sql_exec(db, "BEGIN EXCLUSIVE;");
        sql_exec(
            db,
            "INSERT INTO temp.buffer (wb_id,essid_id,passwd_id,essid,passwd) "
            "SELECT wb_id, essid.essid_id,passwd.passwd_id,essid,passwd FROM "
            "workbench CROSS JOIN essid ON essid.essid_id = workbench.essid_id "
            "CROSS JOIN passwd ON passwd.passwd_id = workbench.passwd_id ORDER "
            "BY lockid LIMIT 25000;");
        sql_exec(db, "UPDATE workbench SET lockid=lockid+1 WHERE wb_id IN "
                     "(SELECT wb_id FROM buffer);");
        sql_exec(db, "COMMIT;");
        rc = query_int(db, "SELECT COUNT(*) FROM buffer;");
        if (rc > 0) {
          sql_exec(db, "UPDATE temp.buffer SET pmk = PMK(essid,passwd);");
          sql_exec(db, "BEGIN EXCLUSIVE;");
          sql_exec(db, "INSERT OR IGNORE INTO pmk (essid_id,passwd_id,pmk) "
                       "SELECT essid_id,passwd_id,pmk FROM temp.buffer");
          sql_exec(db, "DELETE FROM workbench WHERE wb_id IN (SELECT wb_id "
                       "FROM buffer);");
          sql_exec(db, "COMMIT;");
          rowcount += rc;
          gettimeofday(&curtime, NULL);
          int timediff = curtime.tv_sec - starttime.tv_sec;
          fprintf(stdout,
                  "\rComputed %i PMK in %i seconds (%i PMK/s, %i in buffer). ",
                  rowcount, timediff,
                  timediff > 0 ? rowcount / timediff : rowcount,
                  query_int(db, "SELECT COUNT(*) FROM workbench;"));
          fflush(stdout);
        }
      } while (rc > 0);
      sql = sqlite3_mprintf(
          "INSERT OR IGNORE INTO workbench (essid_id,passwd_id) SELECT "
          "essid.essid_id,passwd.passwd_id FROM passwd CROSS JOIN essid LEFT "
          "JOIN pmk ON pmk.essid_id = essid.essid_id AND pmk.passwd_id = "
          "passwd.passwd_id WHERE essid.essid_id = %i AND pmk.essid_id IS NULL "
          "LIMIT 250000;",
          cur_essid);
      sql_exec(db, sql);
      sqlite3_free(sql);
    } while (
        query_int(db, "SELECT COUNT(*) FROM workbench INNER JOIN essid ON "
                      "essid.essid_id = workbench.essid_id INNER JOIN passwd "
                      "ON passwd.passwd_id = workbench.passwd_id;") > 0);
    cur_essid = query_int(
        db, "SELECT essid.essid_id FROM essid LEFT JOIN pmk USING (essid_id) "
            "WHERE VERIFY_ESSID(essid.essid) == 0 GROUP BY essid.essid_id "
            "HAVING COUNT(pmk.essid_id) < (SELECT COUNT(*) FROM passwd) ORDER "
            "BY essid.prio,COUNT(pmk.essid_id),RANDOM() LIMIT 1;");
    if (cur_essid == 0) {
      printf("All ESSID processed.\n\n");
      sqlite3_close(db);
      exit(0);
    }
  }
  sql_exec(db, "DROP TABLE temp.buffer;");
}


x86 assembly (clang, -O0):
<batch_process>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe2e(%rip),%rsi
call   1030 <sql_exec@plt>
mov    0x2e0a(%rip),%rcx
cmp    (%rcx),%rax
je     1204 <batch_process+0x64>
mov    0x2dea(%rip),%rax
mov    (%rax),%edi
lea    0xe85(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
add    $0x50,%rsp
pop    %rbp
ret
mov    -0x8(%rbp),%rdi
lea    0xe9c(%rip),%rsi
call   1090 <query_int@plt>
mov    %eax,-0x10(%rbp)
jmp    121c <batch_process+0x7c>
jmp    1221 <batch_process+0x81>
mov    -0x8(%rbp),%rdi
lea    0xea7(%rip),%rsi
call   1030 <sql_exec@plt>
mov    -0x8(%rbp),%rdi
lea    0xeb0(%rip),%rsi
call   1030 <sql_exec@plt>
mov    -0x8(%rbp),%rdi
lea    0xeb1(%rip),%rsi
call   1030 <sql_exec@plt>
mov    -0x8(%rbp),%rdi
lea    0xfbc(%rip),%rsi
call   1030 <sql_exec@plt>
mov    -0x8(%rbp),%rdi
lea    0xffc(%rip),%rsi
call   1030 <sql_exec@plt>
mov    -0x8(%rbp),%rdi
lea    0xff4(%rip),%rsi
call   1090 <query_int@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jle    1376 <batch_process+0x1d6>
mov    -0x8(%rbp),%rdi
lea    0xff4(%rip),%rsi
call   1030 <sql_exec@plt>
mov    -0x8(%rbp),%rdi
lea    0xe43(%rip),%rsi
call   1030 <sql_exec@plt>
mov    -0x8(%rbp),%rdi
lea    0x1004(%rip),%rsi
call   1030 <sql_exec@plt>
mov    -0x8(%rbp),%rdi
lea    0x1056(%rip),%rsi
call   1030 <sql_exec@plt>
mov    -0x8(%rbp),%rdi
lea    0xf8f(%rip),%rsi
call   1030 <sql_exec@plt>
mov    -0xc(%rbp),%eax
add    -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
lea    -0x20(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
mov    -0x20(%rbp),%eax
sub    -0x18(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    0x2ccc(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x34(%rbp),%eax
mov    %eax,-0x38(%rbp)
cmpl   $0x0,-0x34(%rbp)
jle    132e <batch_process+0x18e>
mov    -0x24(%rbp),%eax
cltd
idivl  -0x34(%rbp)
mov    %eax,-0x44(%rbp)
jmp    1334 <batch_process+0x194>
mov    -0x24(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    -0x44(%rbp),%eax
mov    %eax,-0x48(%rbp)
mov    -0x8(%rbp),%rdi
lea    0x1055(%rip),%rsi
call   1090 <query_int@plt>
mov    -0x40(%rbp),%edi
mov    -0x3c(%rbp),%edx
mov    -0x38(%rbp),%ecx
mov    -0x48(%rbp),%r8d
mov    %eax,%r9d
lea    0xfff(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2c61(%rip),%rax
mov    (%rax),%edi
call   1080 <fflush@plt>
jmp    137b <batch_process+0x1db>
cmpl   $0x0,-0xc(%rbp)
jg     1221 <batch_process+0x81>
mov    -0x10(%rbp),%esi
lea    0x102b(%rip),%rdi
call   10c0 <sqlite3_mprintf@plt>
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1030 <sql_exec@plt>
mov    -0x30(%rbp),%rdi
call   10a0 <sqlite3_free@plt>
mov    -0x8(%rbp),%rdi
lea    0x110f(%rip),%rsi
call   1090 <query_int@plt>
cmp    $0x0,%eax
jg     121c <batch_process+0x7c>
mov    -0x8(%rbp),%rdi
lea    0x118a(%rip),%rsi
call   1090 <query_int@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jne    1400 <batch_process+0x260>
lea    0x1263(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1070 <sqlite3_close@plt>
xor    %edi,%edi
call   10b0 <exit@plt>
jmp    1217 <batch_process+0x77>

x86 assembly (clang, -O2):
<batch_process>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdi,%rbx
lea    0x18(%rsp),%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
lea    0xe3c(%rip),%rsi
mov    %rbx,%rdi
call   1040 <sql_exec@plt>
mov    0x2e15(%rip),%rcx
cmp    (%rcx),%rax
je     11fd <batch_process+0x5d>
mov    0x2df9(%rip),%rax
mov    (%rax),%edi
lea    0xe94(%rip),%rsi
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <fprintf@plt>
lea    0xea7(%rip),%rsi
mov    %rbx,%rdi
call   1090 <query_int@plt>
mov    %eax,%r13d
mov    0x18(%rsp),%eax
mov    %eax,0x20(%rsp)
lea    0x104a(%rip),%r14
lea    0x12a3(%rip),%r12
movl   $0x0,0xc(%rsp)
jmp    1280 <batch_process+0xe0>
mov    %eax,0x24(%rsp)
mov    %rbx,%rdi
lea    0x115d(%rip),%rsi
call   1090 <query_int@plt>
mov    0xc(%rsp),%edi
lea    0x1113(%rip),%rsi
mov    %ebp,0xc(%rsp)
mov    %ebp,%edx
mov    %r15d,%ecx
mov    0x24(%rsp),%r8d
mov    %eax,%r9d
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x2d64(%rip),%rax
mov    (%rax),%edi
call   1080 <fflush@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
lea    0xe49(%rip),%rsi
call   1040 <sql_exec@plt>
mov    %rbx,%rdi
lea    0xe53(%rip),%rsi
call   1040 <sql_exec@plt>
mov    %rbx,%rdi
lea    0xe55(%rip),%rsi
call   1040 <sql_exec@plt>
mov    %rbx,%rdi
lea    0xf61(%rip),%rsi
call   1040 <sql_exec@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <sql_exec@plt>
mov    %rbx,%rdi
lea    0xf9f(%rip),%rsi
call   1090 <query_int@plt>
test   %eax,%eax
jg     1331 <batch_process+0x191>
lea    0x10d9(%rip),%rdi
mov    %r13d,%esi
call   10c0 <sqlite3_mprintf@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
mov    %rax,%rsi
call   1040 <sql_exec@plt>
mov    %rbp,%rdi
call   10a0 <sqlite3_free@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1090 <query_int@plt>
test   %eax,%eax
jg     1280 <batch_process+0xe0>
mov    %rbx,%rdi
lea    0x1240(%rip),%rsi
call   1090 <query_int@plt>
mov    %eax,%r13d
test   %eax,%eax
jne    1280 <batch_process+0xe0>
jmp    13b8 <batch_process+0x218>
mov    %eax,%r15d
mov    %rbx,%rdi
lea    0xf4f(%rip),%rsi
call   1040 <sql_exec@plt>
mov    %rbx,%rdi
lea    0xd9f(%rip),%rsi
call   1040 <sql_exec@plt>
mov    %rbx,%rdi
lea    0xf61(%rip),%rsi
call   1040 <sql_exec@plt>
mov    %rbx,%rdi
lea    0xfb4(%rip),%rsi
call   1040 <sql_exec@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <sql_exec@plt>
mov    0xc(%rsp),%ebp
add    %r15d,%ebp
lea    0x10(%rsp),%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
mov    0x10(%rsp),%r15d
mov    0x2c36(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rsp)
mov    %ebp,%eax
sub    0x20(%rsp),%r15d
jle    122f <batch_process+0x8f>
mov    %ebp,%eax
cltd
idiv   %r15d
jmp    122f <batch_process+0x8f>
lea    0x128f(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1070 <sqlite3_close@plt>
xor    %edi,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
%struct.timeval = type { i32 }
@.str = [124 x i8] c"CREATE TEMPORARY TABLE temp.buffer (wb_id integer, essid_id integer, passwd_id integer, essid text, passwd text, pmk blob);\00"
@SQLITE_OK = global i64 0
@stderr = global i32 0
@.str.1 = [47 x i8] c"Failed to create buffer for batch processing.\0A\00"
@.str.2 = [40 x i8] c"SELECT essid_id FROM workbench LIMIT 1;\00"
@.str.3 = [25 x i8] c"DELETE FROM temp.buffer;\00"
@.str.4 = [17 x i8] c"BEGIN EXCLUSIVE;\00"
@.str.5 = [283 x i8] c"INSERT INTO temp.buffer (wb_id,essid_id,passwd_id,essid,passwd) SELECT wb_id, essid.essid_id,passwd.passwd_id,essid,passwd FROM workbench CROSS JOIN essid ON essid.essid_id = workbench.essid_id CROSS JOIN passwd ON passwd.passwd_id = workbench.passwd_id ORDER BY lockid LIMIT 25000;\00"
@.str.6 = [80 x i8] c"UPDATE workbench SET lockid=lockid+1 WHERE wb_id IN (SELECT wb_id FROM buffer);\00"
@.str.7 = [8 x i8] c"COMMIT;\00"
@.str.8 = [29 x i8] c"SELECT COUNT(*) FROM buffer;\00"
@.str.9 = [48 x i8] c"UPDATE temp.buffer SET pmk = PMK(essid,passwd);\00"
@.str.10 = [98 x i8] c"INSERT OR IGNORE INTO pmk (essid_id,passwd_id,pmk) SELECT essid_id,passwd_id,pmk FROM temp.buffer\00"
@.str.11 = [65 x i8] c"DELETE FROM workbench WHERE wb_id IN (SELECT wb_id FROM buffer);\00"
@stdout = global i32 0
@.str.12 = [58 x i8] c"\0DComputed %i PMK in %i seconds (%i PMK/s, %i in buffer). \00"
@.str.13 = [32 x i8] c"SELECT COUNT(*) FROM workbench;\00"
@.str.14 = [270 x i8] c"INSERT OR IGNORE INTO workbench (essid_id,passwd_id) SELECT essid.essid_id,passwd.passwd_id FROM passwd CROSS JOIN essid LEFT JOIN pmk ON pmk.essid_id = essid.essid_id AND pmk.passwd_id = passwd.passwd_id WHERE essid.essid_id = %i AND pmk.essid_id IS NULL LIMIT 250000;\00"
@.str.15 = [148 x i8] c"SELECT COUNT(*) FROM workbench INNER JOIN essid ON essid.essid_id = workbench.essid_id INNER JOIN passwd ON passwd.passwd_id = workbench.passwd_id;\00"
@.str.16 = [242 x i8] c"SELECT essid.essid_id FROM essid LEFT JOIN pmk USING (essid_id) WHERE VERIFY_ESSID(essid.essid) == 0 GROUP BY essid.essid_id HAVING COUNT(pmk.essid_id) < (SELECT COUNT(*) FROM passwd) ORDER BY essid.prio,COUNT(pmk.essid_id),RANDOM() LIMIT 1;\00"
@.str.17 = [23 x i8] c"All ESSID processed.\0A\0A\00"
define void @batch_process(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.timeval
%6 = alloca %struct.timeval
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
store i32* %0, i32** %2
store i32 0, i32* %4
%10 = call i32 @gettimeofday(%struct.timeval* %5, i32* null)
store i32 0, i32* %7
%11 = load i32*, i32** %2
%12 = call i64 @sql_exec(i32* %11, i8* getelementptr inbounds ([124 x i8], [124 x i8]* @.str, i64 0, i64 0))
%13 = load i64, i64* @SQLITE_OK
%14 = icmp ne i64 %12, %13
br i1 %14, label %15, label %18
15: ; preds = %1
%16 = load i32, i32* @stderr
%17 = call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0))
ret void
18: ; preds = %1
%19 = load i32*, i32** %2
%20 = call i32 @query_int(i32* %19, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0))
store i32 %20, i32* %4
br label %21
21: ; preds = %18, %102
br label %22
22: ; preds = %88, %21
br label %23
23: ; preds = %77, %22
%24 = load i32*, i32** %2
%25 = call i64 @sql_exec(i32* %24, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
%26 = load i32*, i32** %2
%27 = call i64 @sql_exec(i32* %26, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
%28 = load i32*, i32** %2
%29 = call i64 @sql_exec(i32* %28, i8* getelementptr inbounds ([283 x i8], [283 x i8]* @.str.5, i64 0, i64 0))
%30 = load i32*, i32** %2
%31 = call i64 @sql_exec(i32* %30, i8* getelementptr inbounds ([80 x i8], [80 x i8]* @.str.6, i64 0, i64 0))
%32 = load i32*, i32** %2
%33 = call i64 @sql_exec(i32* %32, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0))
%34 = load i32*, i32** %2
%35 = call i32 @query_int(i32* %34, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.8, i64 0, i64 0))
store i32 %35, i32* %3
%36 = load i32, i32* %3
%37 = icmp sgt i32 %36, 0
br i1 %37, label %38, label %76
38: ; preds = %23
%39 = load i32*, i32** %2
%40 = call i64 @sql_exec(i32* %39, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.9, i64 0, i64 0))
%41 = load i32*, i32** %2
%42 = call i64 @sql_exec(i32* %41, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
%43 = load i32*, i32** %2
%44 = call i64 @sql_exec(i32* %43, i8* getelementptr inbounds ([98 x i8], [98 x i8]* @.str.10, i64 0, i64 0))
%45 = load i32*, i32** %2
%46 = call i64 @sql_exec(i32* %45, i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.11, i64 0, i64 0))
%47 = load i32*, i32** %2
%48 = call i64 @sql_exec(i32* %47, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0))
%49 = load i32, i32* %3
%50 = load i32, i32* %7
%51 = add nsw i32 %50, %49
store i32 %51, i32* %7
%52 = call i32 @gettimeofday(%struct.timeval* %6, i32* null)
%53 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 0
%54 = load i32, i32* %53
%55 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 0
%56 = load i32, i32* %55
%57 = sub nsw i32 %54, %56
store i32 %57, i32* %9
%58 = load i32, i32* @stdout
%59 = load i32, i32* %7
%60 = load i32, i32* %9
%61 = load i32, i32* %9
%62 = icmp sgt i32 %61, 0
br i1 %62, label %63, label %67
63: ; preds = %38
%64 = load i32, i32* %7
%65 = load i32, i32* %9
%66 = sdiv i32 %64, %65
br label %69
67: ; preds = %38
%68 = load i32, i32* %7
br label %69
69: ; preds = %67, %63
%70 = phi i32 [ %66, %63 ], [ %68, %67 ]
%71 = load i32*, i32** %2
%72 = call i32 @query_int(i32* %71, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.13, i64 0, i64 0))
%73 = call i32 (i32, i8*, ...) @fprintf(i32 %58, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.12, i64 0, i64 0), i32 %59, i32 %60, i32 %70, i32 %72)
%74 = load i32, i32* @stdout
%75 = call i32 @fflush(i32 %74)
br label %76
76: ; preds = %69, %23
br label %77
77: ; preds = %76
%78 = load i32, i32* %3
%79 = icmp sgt i32 %78, 0
br i1 %79, label %23, label %80
80: ; preds = %77
%81 = load i32, i32* %4
%82 = call i8* @sqlite3_mprintf(i8* getelementptr inbounds ([270 x i8], [270 x i8]* @.str.14, i64 0, i64 0), i32 %81)
store i8* %82, i8** %8
%83 = load i32*, i32** %2
%84 = load i8*, i8** %8
%85 = call i64 @sql_exec(i32* %83, i8* %84)
%86 = load i8*, i8** %8
%87 = call i32 @sqlite3_free(i8* %86)
br label %88
88: ; preds = %80
%89 = load i32*, i32** %2
%90 = call i32 @query_int(i32* %89, i8* getelementptr inbounds ([148 x i8], [148 x i8]* @.str.15, i64 0, i64 0))
%91 = icmp sgt i32 %90, 0
br i1 %91, label %22, label %92
92: ; preds = %88
%93 = load i32*, i32** %2
%94 = call i32 @query_int(i32* %93, i8* getelementptr inbounds ([242 x i8], [242 x i8]* @.str.16, i64 0, i64 0))
store i32 %94, i32* %4
%95 = load i32, i32* %4
%96 = icmp eq i32 %95, 0
br i1 %96, label %97, label %102
97: ; preds = %92
%98 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.17, i64 0, i64 0))
%99 = load i32*, i32** %2
%100 = call i32 @sqlite3_close(i32* %99)
%101 = call i32 @exit(i32 0)
unreachable
102: ; preds = %92
br label %21
}

LLVM IR (-O2):
%struct.timeval = type { i32 }
@.str = [124 x i8] c"CREATE TEMPORARY TABLE temp.buffer (wb_id integer, essid_id integer, passwd_id integer, essid text, passwd text, pmk blob);\00"
@SQLITE_OK = global i64 0
@stderr = global i32 0
@.str.1 = [47 x i8] c"Failed to create buffer for batch processing.\0A\00"
@.str.2 = [40 x i8] c"SELECT essid_id FROM workbench LIMIT 1;\00"
@.str.3 = [25 x i8] c"DELETE FROM temp.buffer;\00"
@.str.4 = [17 x i8] c"BEGIN EXCLUSIVE;\00"
@.str.5 = [283 x i8] c"INSERT INTO temp.buffer (wb_id,essid_id,passwd_id,essid,passwd) SELECT wb_id, essid.essid_id,passwd.passwd_id,essid,passwd FROM workbench CROSS JOIN essid ON essid.essid_id = workbench.essid_id CROSS JOIN passwd ON passwd.passwd_id = workbench.passwd_id ORDER BY lockid LIMIT 25000;\00"
@.str.6 = [80 x i8] c"UPDATE workbench SET lockid=lockid+1 WHERE wb_id IN (SELECT wb_id FROM buffer);\00"
@.str.7 = [8 x i8] c"COMMIT;\00"
@.str.8 = [29 x i8] c"SELECT COUNT(*) FROM buffer;\00"
@.str.9 = [48 x i8] c"UPDATE temp.buffer SET pmk = PMK(essid,passwd);\00"
@.str.10 = [98 x i8] c"INSERT OR IGNORE INTO pmk (essid_id,passwd_id,pmk) SELECT essid_id,passwd_id,pmk FROM temp.buffer\00"
@.str.11 = [65 x i8] c"DELETE FROM workbench WHERE wb_id IN (SELECT wb_id FROM buffer);\00"
@stdout = global i32 0
@.str.12 = [58 x i8] c"\0DComputed %i PMK in %i seconds (%i PMK/s, %i in buffer). \00"
@.str.13 = [32 x i8] c"SELECT COUNT(*) FROM workbench;\00"
@.str.14 = [270 x i8] c"INSERT OR IGNORE INTO workbench (essid_id,passwd_id) SELECT essid.essid_id,passwd.passwd_id FROM passwd CROSS JOIN essid LEFT JOIN pmk ON pmk.essid_id = essid.essid_id AND pmk.passwd_id = passwd.passwd_id WHERE essid.essid_id = %i AND pmk.essid_id IS NULL LIMIT 250000;\00"
@.str.15 = [148 x i8] c"SELECT COUNT(*) FROM workbench INNER JOIN essid ON essid.essid_id = workbench.essid_id INNER JOIN passwd ON passwd.passwd_id = workbench.passwd_id;\00"
@.str.16 = [242 x i8] c"SELECT essid.essid_id FROM essid LEFT JOIN pmk USING (essid_id) WHERE VERIFY_ESSID(essid.essid) == 0 GROUP BY essid.essid_id HAVING COUNT(pmk.essid_id) < (SELECT COUNT(*) FROM passwd) ORDER BY essid.prio,COUNT(pmk.essid_id),RANDOM() LIMIT 1;\00"
@str = [22 x i8] c"All ESSID processed.\0A\00"
define void @batch_process(i32* %0) {
%2 = alloca %struct.timeval
%3 = alloca %struct.timeval
%4 = bitcast %struct.timeval* %2 to i8*
%5 = bitcast %struct.timeval* %3 to i8*
%6 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
%7 = tail call i64 @sql_exec(i32* %0, i8* getelementptr inbounds ([124 x i8], [124 x i8]* @.str, i64 0, i64 0))
%8 = load i64, i64* @SQLITE_OK
%9 = icmp eq i64 %7, %8
br i1 %9, label %13, label %10
10: ; preds = %1
%11 = load i32, i32* @stderr
%12 = tail call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0))
ret void
13: ; preds = %1
%14 = tail call i32 @query_int(i32* %0, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0))
%15 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
%16 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
%17 = load i32, i32* %16
br label %18
18: ; preds = %57, %13
%19 = phi i32 [ 0, %13 ], [ %22, %57 ]
%20 = phi i32 [ %14, %13 ], [ %58, %57 ]
br label %21
21: ; preds = %18, %45
%22 = phi i32 [ %19, %18 ], [ %37, %45 ]
br label %23
23: ; preds = %21, %51
%24 = tail call i64 @sql_exec(i32* %0, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
%25 = tail call i64 @sql_exec(i32* %0, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
%26 = tail call i64 @sql_exec(i32* %0, i8* getelementptr inbounds ([283 x i8], [283 x i8]* @.str.5, i64 0, i64 0))
%27 = tail call i64 @sql_exec(i32* %0, i8* getelementptr inbounds ([80 x i8], [80 x i8]* @.str.6, i64 0, i64 0))
%28 = tail call i64 @sql_exec(i32* %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0))
%29 = tail call i32 @query_int(i32* %0, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.8, i64 0, i64 0))
%30 = icmp sgt i32 %29, 0
br i1 %30, label %31, label %51
31: ; preds = %23
%32 = tail call i64 @sql_exec(i32* %0, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.9, i64 0, i64 0))
%33 = tail call i64 @sql_exec(i32* %0, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
%34 = tail call i64 @sql_exec(i32* %0, i8* getelementptr inbounds ([98 x i8], [98 x i8]* @.str.10, i64 0, i64 0))
%35 = tail call i64 @sql_exec(i32* %0, i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.11, i64 0, i64 0))
%36 = tail call i64 @sql_exec(i32* %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0))
%37 = add nsw i32 %29, %22
%38 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%39 = load i32, i32* %15
%40 = sub nsw i32 %39, %17
%41 = load i32, i32* @stdout
%42 = icmp sgt i32 %40, 0
br i1 %42, label %43, label %45
43: ; preds = %31
%44 = sdiv i32 %37, %40
br label %45
45: ; preds = %43, %31
%46 = phi i32 [ %44, %43 ], [ %37, %31 ]
%47 = tail call i32 @query_int(i32* %0, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.13, i64 0, i64 0))
%48 = tail call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.12, i64 0, i64 0), i32 %37, i32 %40, i32 %46, i32 %47)
%49 = load i32, i32* @stdout
%50 = tail call i32 @fflush(i32 %49)
br label %21
51: ; preds = %23
%52 = tail call i8* @sqlite3_mprintf(i8* getelementptr inbounds ([270 x i8], [270 x i8]* @.str.14, i64 0, i64 0), i32 %20)
%53 = tail call i64 @sql_exec(i32* %0, i8* %52)
%54 = tail call i32 @sqlite3_free(i8* %52)
%55 = tail call i32 @query_int(i32* %0, i8* getelementptr inbounds ([148 x i8], [148 x i8]* @.str.15, i64 0, i64 0))
%56 = icmp sgt i32 %55, 0
br i1 %56, label %23, label %57
57: ; preds = %51
%58 = tail call i32 @query_int(i32* %0, i8* getelementptr inbounds ([242 x i8], [242 x i8]* @.str.16, i64 0, i64 0))
%59 = icmp eq i32 %58, 0
br i1 %59, label %60, label %18
60: ; preds = %57
%61 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
%62 = tail call i32 @sqlite3_close(i32* %0)
%63 = tail call i32 @exit(i32 0)
unreachable
}