#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_value;
typedef int /*<<< orphan*/ sqlite3_context;

/* Variables and functions */
int /*<<< orphan*/ SQLITE_TRANSIENT;
int /*<<< orphan*/ calc_pmk(char *, char *, unsigned char *);
int /*<<< orphan*/ sqlite3_result_blob(int /*<<< orphan*/ *, unsigned char *,
                                       int, int /*<<< orphan*/);
int /*<<< orphan*/ sqlite3_result_error(int /*<<< orphan*/ *, char *, int);
scalar_t__ sqlite3_value_blob(int /*<<< orphan*/ *);
void sql_calcpmk(sqlite3_context *context, int argc, sqlite3_value **values) {
  unsigned char pmk[40];
  char *passwd = (char *)sqlite3_value_blob(values[1]);
  char *essid = (char *)sqlite3_value_blob(values[0]);
  if (argc < 2 || passwd == 0 || essid == 0) {
    sqlite3_result_error(
        context, "SQL function PMK() called with invalid arguments.\n", -1);
    return;
  }
  calc_pmk(passwd, essid, pmk);
  sqlite3_result_blob(context, pmk, 32, SQLITE_TRANSIENT);
}


x86 assembly (clang, -O0):
<sql_calcpmk>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <sqlite3_value_blob@plt>
mov    %rax,-0x48(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   1060 <sqlite3_value_blob@plt>
mov    %rax,-0x50(%rbp)
cmpl   $0x2,-0xc(%rbp)
jl     1194 <sql_calcpmk+0x54>
cmpq   $0x0,-0x48(%rbp)
je     1194 <sql_calcpmk+0x54>
cmpq   $0x0,-0x50(%rbp)
jne    11ae <sql_calcpmk+0x6e>
mov    -0x8(%rbp),%rdi
lea    0xe61(%rip),%rsi
mov    $0xffffffff,%edx
call   1030 <sqlite3_result_error@plt>
jmp    11da <sql_calcpmk+0x9a>
mov    -0x48(%rbp),%rdi
mov    -0x50(%rbp),%rsi
lea    -0x40(%rbp),%rdx
call   1040 <calc_pmk@plt>
mov    -0x8(%rbp),%rdi
lea    -0x40(%rbp),%rsi
mov    0x2e12(%rip),%rax
mov    (%rax),%ecx
mov    $0x20,%edx
call   1050 <sqlite3_result_blob@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sql_calcpmk>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rdx,%rbx
mov    %esi,%ebp
mov    %rdi,%r14
mov    0x8(%rdx),%rdi
call   1060 <sqlite3_value_blob@plt>
mov    %rax,%r15
mov    (%rbx),%rdi
call   1060 <sqlite3_value_blob@plt>
cmp    $0x2,%ebp
jl     11aa <sql_calcpmk+0x6a>
test   %r15,%r15
je     11aa <sql_calcpmk+0x6a>
test   %rax,%rax
je     11aa <sql_calcpmk+0x6a>
mov    %rsp,%rbx
mov    %r15,%rdi
mov    %rax,%rsi
mov    %rbx,%rdx
call   1040 <calc_pmk@plt>
mov    0x2e53(%rip),%rax
mov    (%rax),%ecx
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x20,%edx
call   1050 <sqlite3_result_blob@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe4f(%rip),%rsi
mov    %r14,%rdi
mov    $0xffffffff,%edx
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <sqlite3_result_error@plt>

LLVM IR (-O0):
@.str = [51 x i8] c"SQL function PMK() called with invalid arguments.\0A\00"
@SQLITE_TRANSIENT = global i32 0
define void @sql_calcpmk(i32* %0, i32 %1, i32** %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32**
%7 = alloca [40 x i8]
%8 = alloca i8*
%9 = alloca i8*
store i32* %0, i32** %4
store i32 %1, i32* %5
store i32** %2, i32*** %6
%10 = load i32**, i32*** %6
%11 = getelementptr inbounds i32*, i32** %10, i64 1
%12 = load i32*, i32** %11
%13 = call i64 @sqlite3_value_blob(i32* %12)
%14 = inttoptr i64 %13 to i8*
store i8* %14, i8** %8
%15 = load i32**, i32*** %6
%16 = getelementptr inbounds i32*, i32** %15, i64 0
%17 = load i32*, i32** %16
%18 = call i64 @sqlite3_value_blob(i32* %17)
%19 = inttoptr i64 %18 to i8*
store i8* %19, i8** %9
%20 = load i32, i32* %5
%21 = icmp slt i32 %20, 2
br i1 %21, label %28, label %22
22: ; preds = %3
%23 = load i8*, i8** %8
%24 = icmp eq i8* %23, null
br i1 %24, label %28, label %25
25: ; preds = %22
%26 = load i8*, i8** %9
%27 = icmp eq i8* %26, null
br i1 %27, label %28, label %31
28: ; preds = %25, %22, %3
%29 = load i32*, i32** %4
%30 = call i32 @sqlite3_result_error(i32* %29, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0), i32 -1)
br label %40
31: ; preds = %25
%32 = load i8*, i8** %8
%33 = load i8*, i8** %9
%34 = getelementptr inbounds [40 x i8], [40 x i8]* %7, i64 0, i64 0
%35 = call i32 @calc_pmk(i8* %32, i8* %33, i8* %34)
%36 = load i32*, i32** %4
%37 = getelementptr inbounds [40 x i8], [40 x i8]* %7, i64 0, i64 0
%38 = load i32, i32* @SQLITE_TRANSIENT
%39 = call i32 @sqlite3_result_blob(i32* %36, i8* %37, i32 32, i32 %38)
br label %40
40: ; preds = %31, %28
ret void
}

LLVM IR (-O2):
@.str = [51 x i8] c"SQL function PMK() called with invalid arguments.\0A\00"
@SQLITE_TRANSIENT = global i32 0
define void @sql_calcpmk(i32* %0, i32 %1, i32** nocapture %2) {
%4 = alloca [40 x i8]
%5 = getelementptr inbounds [40 x i8], [40 x i8]* %4, i64 0, i64 0
%6 = getelementptr inbounds i32*, i32** %2, i64 1
%7 = load i32*, i32** %6
%8 = tail call i64 @sqlite3_value_blob(i32* %7)
%9 = load i32*, i32** %2
%10 = tail call i64 @sqlite3_value_blob(i32* %9)
%11 = icmp slt i32 %1, 2
%12 = icmp eq i64 %8, 0
%13 = select i1 %11, i1 true, i1 %12
%14 = icmp eq i64 %10, 0
%15 = select i1 %13, i1 true, i1 %14
br i1 %15, label %16, label %18
16: ; preds = %3
%17 = tail call i32 @sqlite3_result_error(i32* %0, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0), i32 -1)
br label %24
18: ; preds = %3
%19 = inttoptr i64 %10 to i8*
%20 = inttoptr i64 %8 to i8*
%21 = call i32 @calc_pmk(i8* %20, i8* %19, i8* %5)
%22 = load i32, i32* @SQLITE_TRANSIENT
%23 = call i32 @sqlite3_result_blob(i32* %0, i8* %5, i32 32, i32 %22)
br label %24
24: ; preds = %18, %16
ret void
}