#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*/ printf(char *);
int /*<<< orphan*/ sql_stdout(int /*<<< orphan*/ *, char *, int /*<<< orphan*/);
void verify(sqlite3 *db, int complete) {
  if (complete != 1) {
    printf("Checking ~10 000 randomly chosen PMKs...\n");
    sql_stdout(db,
               "select s.essid AS ESSID, COUNT(*) AS CHECKED, CASE WHEN "
               "MIN(s.pmk == PMK(essid,passwd)) == 0 THEN 'FAILED' ELSE 'OK' "
               "END AS STATUS FROM (select distinct essid,passwd,pmk FROM pmk "
               "INNER JOIN passwd ON passwd.passwd_id = pmk.passwd_id INNER "
               "JOIN essid ON essid.essid_id = pmk.essid_id WHERE abs(random() "
               "% (select count(*) from pmk)) < 10000) AS s GROUP BY s.essid;",
               0);
  } else {
    printf("Checking all PMKs. This could take a while...\n");
    sql_stdout(
        db,
        "select essid AS ESSID,passwd AS PASSWORD,HEX(pmk) AS PMK_DB, "
        "HEX(PMK(essid,passwd)) AS CORRECT FROM pmk INNER JOIN passwd ON "
        "passwd.passwd_id = pmk.passwd_id INNER JOIN essid ON essid.essid_id = "
        "pmk.essid_id WHERE pmk.pmk != PMK(essid,passwd);",
        0);
  }
}


x86 assembly (clang, -O0):
<verify>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x1,-0xc(%rbp)
je     115c <verify+0x3c>
lea    0xec0(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%rdi
lea    0xeda(%rip),%rsi
xor    %edx,%edx
call   1040 <sql_stdout@plt>
jmp    117a <verify+0x5a>
lea    0x1033(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%rdi
lea    0x1052(%rip),%rsi
xor    %edx,%edx
call   1040 <sql_stdout@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<verify>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
cmp    $0x1,%esi
lea    0x112f(%rip),%rax
lea    0x1156(%rip),%rdi
cmove  %rax,%rdi
lea    0x1029(%rip),%rax
lea    0xeb6(%rip),%rbx
cmove  %rax,%rbx
call   1030 <puts@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %edx,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <sql_stdout@plt>

LLVM IR (-O0):
@.str = [42 x i8] c"Checking ~10 000 randomly chosen PMKs...\0A\00"
@.str.1 = [364 x i8] c"select s.essid AS ESSID, COUNT(*) AS CHECKED, CASE WHEN MIN(s.pmk == PMK(essid,passwd)) == 0 THEN 'FAILED' ELSE 'OK' END AS STATUS FROM (select distinct essid,passwd,pmk FROM pmk INNER JOIN passwd ON passwd.passwd_id = pmk.passwd_id INNER JOIN essid ON essid.essid_id = pmk.essid_id WHERE abs(random() % (select count(*) from pmk)) < 10000) AS s GROUP BY s.essid;\00"
@.str.2 = [47 x i8] c"Checking all PMKs. This could take a while...\0A\00"
@.str.3 = [244 x i8] c"select essid AS ESSID,passwd AS PASSWORD,HEX(pmk) AS PMK_DB, HEX(PMK(essid,passwd)) AS CORRECT FROM pmk INNER JOIN passwd ON passwd.passwd_id = pmk.passwd_id INNER JOIN essid ON essid.essid_id = pmk.essid_id WHERE pmk.pmk != PMK(essid,passwd);\00"
define void @verify(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
%5 = load i32, i32* %4
%6 = icmp ne i32 %5, 1
br i1 %6, label %7, label %11
7: ; preds = %2
%8 = call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
%9 = load i32*, i32** %3
%10 = call i32 @sql_stdout(i32* %9, i8* getelementptr inbounds ([364 x i8], [364 x i8]* @.str.1, i64 0, i64 0), i32 0)
br label %15
11: ; preds = %2
%12 = call i32 @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0))
%13 = load i32*, i32** %3
%14 = call i32 @sql_stdout(i32* %13, i8* getelementptr inbounds ([244 x i8], [244 x i8]* @.str.3, i64 0, i64 0), i32 0)
br label %15
15: ; preds = %11, %7
ret void
}

LLVM IR (-O2):
@.str.1 = [364 x i8] c"select s.essid AS ESSID, COUNT(*) AS CHECKED, CASE WHEN MIN(s.pmk == PMK(essid,passwd)) == 0 THEN 'FAILED' ELSE 'OK' END AS STATUS FROM (select distinct essid,passwd,pmk FROM pmk INNER JOIN passwd ON passwd.passwd_id = pmk.passwd_id INNER JOIN essid ON essid.essid_id = pmk.essid_id WHERE abs(random() % (select count(*) from pmk)) < 10000) AS s GROUP BY s.essid;\00"
@.str.3 = [244 x i8] c"select essid AS ESSID,passwd AS PASSWORD,HEX(pmk) AS PMK_DB, HEX(PMK(essid,passwd)) AS CORRECT FROM pmk INNER JOIN passwd ON passwd.passwd_id = pmk.passwd_id INNER JOIN essid ON essid.essid_id = pmk.essid_id WHERE pmk.pmk != PMK(essid,passwd);\00"
@str = [46 x i8] c"Checking all PMKs. This could take a while...\00"
@str.4 = [41 x i8] c"Checking ~10 000 randomly chosen PMKs...\00"
define void @verify(i32* %0, i32 %1) {
%3 = icmp eq i32 %1, 1
%4 = select i1 %3, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @str, i64 0, i64 0), i8* getelementptr inbounds ([41 x i8], [41 x i8]* @str.4, i64 0, i64 0)
%5 = select i1 %3, i8* getelementptr inbounds ([244 x i8], [244 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([364 x i8], [364 x i8]* @.str.1, i64 0, i64 0)
%6 = tail call i32 @puts(i8* dereferenceable(1) %4)
%7 = tail call i32 @sql_stdout(i32* %0, i8* %5, i32 0)
ret void
}