#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*/ fprintf(int /*<<< orphan*/, char *, int, int, int, int,
                           double);
int /*<<< orphan*/ printf(char *);
int query_int(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ sql_exec(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ sql_stdout(int /*<<< orphan*/ *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
void show_stats(sqlite3 *db, int precise) {
  sql_exec(db, "BEGIN;");
  int essids = query_int(db, "SELECT COUNT(*) FROM essid;");
  int passwds = query_int(db, "SELECT COUNT(*) FROM passwd;");
  int done;
  if (precise != 0) {
    printf("Determining precise statistics may be slow...\n");
    done = query_int(
        db, "SELECT COUNT(*) FROM essid,passwd INNER JOIN pmk ON pmk.essid_id "
            "= essid.essid_id AND pmk.passwd_id = passwd.passwd_id");
  } else {
    done = query_int(db, "SELECT COUNT(*) FROM pmk;");
  }
  fprintf(stdout,
          "There are %i ESSIDs and %i passwords in the database. %i out of %i "
          "possible combinations have been computed (%g%%).\n\n",
          essids, passwds, done, essids * passwds,
          essids * passwds > 0 ? ((double)done * 100) / (essids * passwds) : 0);
  if (precise != 0) {
    sql_stdout(db,
               "select essid.essid AS ESSID, essid.prio AS Priority, "
               "round(count(pmk.essid_id) * 100.0 / count(*),2) AS Done from "
               "essid,passwd left join pmk on pmk.essid_id = essid.essid_id "
               "and pmk.passwd_id = passwd.passwd_id group by essid.essid_id;",
               0);
  } else {
    sql_stdout(db,
               "SELECT essid.essid AS ESSID, essid.prio AS Priority, "
               "ROUND(COUNT(pmk.essid_id) * 100.0 / (SELECT COUNT(*) FROM "
               "passwd),2) AS Done FROM essid LEFT JOIN pmk ON pmk.essid_id = "
               "essid.essid_id GROUP BY essid.essid_id;",
               0);
  }
  sql_exec(db, "COMMIT;");
}


x86 assembly (clang, -O0):
<show_stats>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe9e(%rip),%rsi
call   1030 <sql_exec@plt>
mov    -0x8(%rbp),%rdi
lea    0xe95(%rip),%rsi
call   1070 <query_int@plt>
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe9e(%rip),%rsi
call   1070 <query_int@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     11c3 <show_stats+0x73>
lea    0xea2(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
lea    0xec1(%rip),%rsi
call   1070 <query_int@plt>
mov    %eax,-0x18(%rbp)
jmp    11d6 <show_stats+0x86>
mov    -0x8(%rbp),%rdi
lea    0xf20(%rip),%rsi
call   1070 <query_int@plt>
mov    %eax,-0x18(%rbp)
mov    0x2e03(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%eax
imul   -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%eax
imul   -0x14(%rbp),%eax
cmp    $0x0,%eax
jle    1238 <show_stats+0xe8>
cvtsi2sdl -0x18(%rbp),%xmm0
movsd  0xde5(%rip),%xmm1
mulsd  %xmm1,%xmm0
mov    -0x10(%rbp),%eax
imul   -0x14(%rbp),%eax
cvtsi2sd %eax,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
jmp    1245 <show_stats+0xf5>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
jmp    1245 <show_stats+0xf5>
mov    -0x1c(%rbp),%r9d
mov    -0x20(%rbp),%r8d
mov    -0x24(%rbp),%ecx
mov    -0x28(%rbp),%edx
mov    -0x2c(%rbp),%edi
movsd  -0x38(%rbp),%xmm0
lea    0xea6(%rip),%rsi
call   1050 <fprintf@plt>
cmpl   $0x0,-0xc(%rbp)
je     1288 <show_stats+0x138>
mov    -0x8(%rbp),%rdi
lea    0xf02(%rip),%rsi
xor    %edx,%edx
call   1060 <sql_stdout@plt>
jmp    129a <show_stats+0x14a>
mov    -0x8(%rbp),%rdi
lea    0xfd7(%rip),%rsi
xor    %edx,%edx
call   1060 <sql_stdout@plt>
mov    -0x8(%rbp),%rdi
lea    0x109a(%rip),%rsi
call   1030 <sql_exec@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<show_stats>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %rdi,%rbx
lea    0xea4(%rip),%rsi
call   1040 <sql_exec@plt>
lea    0xe9f(%rip),%rsi
mov    %rbx,%rdi
call   1070 <query_int@plt>
mov    %eax,%r15d
lea    0xea9(%rip),%rsi
mov    %rbx,%rdi
call   1070 <query_int@plt>
mov    %eax,%ebp
test   %r14d,%r14d
je     11a6 <show_stats+0x56>
lea    0x1180(%rip),%rdi
call   1030 <puts@plt>
lea    0xea4(%rip),%rsi
jmp    11ad <show_stats+0x5d>
lea    0xf12(%rip),%rsi
mov    %rbx,%rdi
call   1070 <query_int@plt>
mov    0x2e24(%rip),%rcx
mov    (%rcx),%edi
mov    %ebp,%r9d
imul   %r15d,%r9d
test   %r9d,%r9d
jle    11e1 <show_stats+0x91>
cvtsi2sd %eax,%xmm0
mulsd  0xe2a(%rip),%xmm0
cvtsi2sd %r9d,%xmm1
divsd  %xmm1,%xmm0
jmp    11e5 <show_stats+0x95>
xorpd  %xmm0,%xmm0
lea    0xeed(%rip),%rsi
mov    %r15d,%edx
mov    %ebp,%ecx
mov    %eax,%r8d
call   1050 <fprintf@plt>
test   %r14d,%r14d
lea    0x1038(%rip),%rax
lea    0xf45(%rip),%rsi
cmove  %rax,%rsi
mov    %rbx,%rdi
xor    %edx,%edx
call   1060 <sql_stdout@plt>
lea    0x10f1(%rip),%rsi
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <sql_exec@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"BEGIN;\00"
@.str.1 = [28 x i8] c"SELECT COUNT(*) FROM essid;\00"
@.str.2 = [29 x i8] c"SELECT COUNT(*) FROM passwd;\00"
@.str.3 = [47 x i8] c"Determining precise statistics may be slow...\0A\00"
@.str.4 = [119 x i8] c"SELECT COUNT(*) FROM essid,passwd INNER JOIN pmk ON pmk.essid_id = essid.essid_id AND pmk.passwd_id = passwd.passwd_id\00"
@.str.5 = [26 x i8] c"SELECT COUNT(*) FROM pmk;\00"
@stdout = global i32 0
@.str.6 = [118 x i8] c"There are %i ESSIDs and %i passwords in the database. %i out of %i possible combinations have been computed (%g%%).\0A\0A\00"
@.str.7 = [236 x i8] c"select essid.essid AS ESSID, essid.prio AS Priority, round(count(pmk.essid_id) * 100.0 / count(*),2) AS Done from essid,passwd left join pmk on pmk.essid_id = essid.essid_id and pmk.passwd_id = passwd.passwd_id group by essid.essid_id;\00"
@.str.8 = [213 x i8] c"SELECT essid.essid AS ESSID, essid.prio AS Priority, ROUND(COUNT(pmk.essid_id) * 100.0 / (SELECT COUNT(*) FROM passwd),2) AS Done FROM essid LEFT JOIN pmk ON pmk.essid_id = essid.essid_id GROUP BY essid.essid_id;\00"
@.str.9 = [8 x i8] c"COMMIT;\00"
define void @show_stats(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
%8 = load i32*, i32** %3
%9 = call i32 @sql_exec(i32* %8, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%10 = load i32*, i32** %3
%11 = call i32 @query_int(i32* %10, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
store i32 %11, i32* %5
%12 = load i32*, i32** %3
%13 = call i32 @query_int(i32* %12, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
store i32 %13, i32* %6
%14 = load i32, i32* %4
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %2
%17 = call i32 @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.3, i64 0, i64 0))
%18 = load i32*, i32** %3
%19 = call i32 @query_int(i32* %18, i8* getelementptr inbounds ([119 x i8], [119 x i8]* @.str.4, i64 0, i64 0))
store i32 %19, i32* %7
br label %23
20: ; preds = %2
%21 = load i32*, i32** %3
%22 = call i32 @query_int(i32* %21, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0))
store i32 %22, i32* %7
br label %23
23: ; preds = %20, %16
%24 = load i32, i32* @stdout
%25 = load i32, i32* %5
%26 = load i32, i32* %6
%27 = load i32, i32* %7
%28 = load i32, i32* %5
%29 = load i32, i32* %6
%30 = mul nsw i32 %28, %29
%31 = load i32, i32* %5
%32 = load i32, i32* %6
%33 = mul nsw i32 %31, %32
%34 = icmp sgt i32 %33, 0
br i1 %34, label %35, label %44
35: ; preds = %23
%36 = load i32, i32* %7
%37 = sitofp i32 %36 to double
%38 = fmul double %37, 1.000000e+02
%39 = load i32, i32* %5
%40 = load i32, i32* %6
%41 = mul nsw i32 %39, %40
%42 = sitofp i32 %41 to double
%43 = fdiv double %38, %42
br label %45
44: ; preds = %23
br label %45
45: ; preds = %44, %35
%46 = phi double [ %43, %35 ], [ 0.000000e+00, %44 ]
%47 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([118 x i8], [118 x i8]* @.str.6, i64 0, i64 0), i32 %25, i32 %26, i32 %27, i32 %30, double %46)
%48 = load i32, i32* %4
%49 = icmp ne i32 %48, 0
br i1 %49, label %50, label %53
50: ; preds = %45
%51 = load i32*, i32** %3
%52 = call i32 @sql_stdout(i32* %51, i8* getelementptr inbounds ([236 x i8], [236 x i8]* @.str.7, i64 0, i64 0), i32 0)
br label %56
53: ; preds = %45
%54 = load i32*, i32** %3
%55 = call i32 @sql_stdout(i32* %54, i8* getelementptr inbounds ([213 x i8], [213 x i8]* @.str.8, i64 0, i64 0), i32 0)
br label %56
56: ; preds = %53, %50
%57 = load i32*, i32** %3
%58 = call i32 @sql_exec(i32* %57, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.9, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"BEGIN;\00"
@.str.1 = [28 x i8] c"SELECT COUNT(*) FROM essid;\00"
@.str.2 = [29 x i8] c"SELECT COUNT(*) FROM passwd;\00"
@.str.4 = [119 x i8] c"SELECT COUNT(*) FROM essid,passwd INNER JOIN pmk ON pmk.essid_id = essid.essid_id AND pmk.passwd_id = passwd.passwd_id\00"
@.str.5 = [26 x i8] c"SELECT COUNT(*) FROM pmk;\00"
@stdout = global i32 0
@.str.6 = [118 x i8] c"There are %i ESSIDs and %i passwords in the database. %i out of %i possible combinations have been computed (%g%%).\0A\0A\00"
@.str.7 = [236 x i8] c"select essid.essid AS ESSID, essid.prio AS Priority, round(count(pmk.essid_id) * 100.0 / count(*),2) AS Done from essid,passwd left join pmk on pmk.essid_id = essid.essid_id and pmk.passwd_id = passwd.passwd_id group by essid.essid_id;\00"
@.str.8 = [213 x i8] c"SELECT essid.essid AS ESSID, essid.prio AS Priority, ROUND(COUNT(pmk.essid_id) * 100.0 / (SELECT COUNT(*) FROM passwd),2) AS Done FROM essid LEFT JOIN pmk ON pmk.essid_id = essid.essid_id GROUP BY essid.essid_id;\00"
@.str.9 = [8 x i8] c"COMMIT;\00"
@str = [46 x i8] c"Determining precise statistics may be slow...\00"
define void @show_stats(i32* %0, i32 %1) {
%3 = tail call i32 @sql_exec(i32* %0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32 @query_int(i32* %0, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
%5 = tail call i32 @query_int(i32* %0, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
%6 = icmp eq i32 %1, 0
br i1 %6, label %9, label %7
7: ; preds = %2
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @str, i64 0, i64 0))
br label %9
9: ; preds = %2, %7
%10 = phi i8* [ getelementptr inbounds ([119 x i8], [119 x i8]* @.str.4, i64 0, i64 0), %7 ], [ getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), %2 ]
%11 = tail call i32 @query_int(i32* %0, i8* %10)
%12 = load i32, i32* @stdout
%13 = mul nsw i32 %5, %4
%14 = icmp sgt i32 %13, 0
br i1 %14, label %15, label %20
15: ; preds = %9
%16 = sitofp i32 %11 to double
%17 = fmul double %16, 1.000000e+02
%18 = sitofp i32 %13 to double
%19 = fdiv double %17, %18
br label %20
20: ; preds = %9, %15
%21 = phi double [ %19, %15 ], [ 0.000000e+00, %9 ]
%22 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([118 x i8], [118 x i8]* @.str.6, i64 0, i64 0), i32 %4, i32 %5, i32 %11, i32 %13, double %21)
%23 = select i1 %6, i8* getelementptr inbounds ([213 x i8], [213 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([236 x i8], [236 x i8]* @.str.7, i64 0, i64 0)
%24 = tail call i32 @sql_stdout(i32* %0, i8* %23, i32 0)
%25 = tail call i32 @sql_exec(i32* %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.9, i64 0, i64 0))
ret void
}