#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 levenshtein(char *, char *);
int /*<<< orphan*/ sqlite3_result_int(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ sqlite3_result_null(int /*<<< orphan*/ *);
scalar_t__ sqlite3_value_text(int /*<<< orphan*/ *);
extern void sql_lev(sqlite3_context *context, int argc, sqlite3_value **argv) {
  int dist;
  char *s1;
  char *s2;
  s1 = (char *)sqlite3_value_text(argv[0]);
  s2 = (char *)sqlite3_value_text(argv[1]);
  if ((s1 == NULL) || (s2 == NULL)) {
    sqlite3_result_null(context);
  } else {
    dist = levenshtein(s1, s2);
    sqlite3_result_int(context, dist);
  }
}


x86 assembly (clang, -O0):
<sql_lev>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   1060 <sqlite3_value_text@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <sqlite3_value_text@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     118a <sql_lev+0x4a>
cmpq   $0x0,-0x30(%rbp)
jne    1198 <sql_lev+0x58>
mov    -0x8(%rbp),%rdi
call   1040 <sqlite3_result_null@plt>
jmp    11b4 <sql_lev+0x74>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1050 <levenshtein@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1030 <sqlite3_result_int@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sql_lev>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%rbx
mov    %rdi,%r14
mov    (%rdx),%rdi
call   1060 <sqlite3_value_text@plt>
mov    %rax,%r15
mov    0x8(%rbx),%rdi
call   1060 <sqlite3_value_text@plt>
test   %r15,%r15
je     1183 <sql_lev+0x43>
test   %rax,%rax
je     1183 <sql_lev+0x43>
mov    %r15,%rdi
mov    %rax,%rsi
call   1050 <levenshtein@plt>
mov    %r14,%rdi
mov    %eax,%esi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <sqlite3_result_int@plt>
mov    %r14,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <sqlite3_result_null@plt>

LLVM IR (-O0):
define void @sql_lev(i32* %0, i32 %1, i32** %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32**
%7 = alloca i32
%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 0
%12 = load i32*, i32** %11
%13 = call i64 @sqlite3_value_text(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 1
%17 = load i32*, i32** %16
%18 = call i64 @sqlite3_value_text(i32* %17)
%19 = inttoptr i64 %18 to i8*
store i8* %19, i8** %9
%20 = load i8*, i8** %8
%21 = icmp eq i8* %20, null
br i1 %21, label %25, label %22
22: ; preds = %3
%23 = load i8*, i8** %9
%24 = icmp eq i8* %23, null
br i1 %24, label %25, label %28
25: ; preds = %22, %3
%26 = load i32*, i32** %4
%27 = call i32 @sqlite3_result_null(i32* %26)
br label %35
28: ; preds = %22
%29 = load i8*, i8** %8
%30 = load i8*, i8** %9
%31 = call i32 @levenshtein(i8* %29, i8* %30)
store i32 %31, i32* %7
%32 = load i32*, i32** %4
%33 = load i32, i32* %7
%34 = call i32 @sqlite3_result_int(i32* %32, i32 %33)
br label %35
35: ; preds = %28, %25
ret void
}

LLVM IR (-O2):
define void @sql_lev(i32* %0, i32 %1, i32** nocapture %2) {
%4 = load i32*, i32** %2
%5 = tail call i64 @sqlite3_value_text(i32* %4)
%6 = getelementptr inbounds i32*, i32** %2, i64 1
%7 = load i32*, i32** %6
%8 = tail call i64 @sqlite3_value_text(i32* %7)
%9 = icmp eq i64 %5, 0
%10 = icmp eq i64 %8, 0
%11 = select i1 %9, i1 true, i1 %10
br i1 %11, label %12, label %14
12: ; preds = %3
%13 = tail call i32 @sqlite3_result_null(i32* %0)
br label %19
14: ; preds = %3
%15 = inttoptr i64 %8 to i8*
%16 = inttoptr i64 %5 to i8*
%17 = tail call i32 @levenshtein(i8* %16, i8* %15)
%18 = tail call i32 @sqlite3_result_int(i32* %0, i32 %17)
br label %19
19: ; preds = %14, %12
ret void
}