#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 */

/* Variables and functions */
char *convert_query_hexchar(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ printf(char *);
char *strdup(char const *);
void stub1(char const *, char const *);
void stub2(char const *, char const *);
int http_parse_querystring(const char *txt_,
                           void (*fn)(const char *name, const char *value)) {
  char *t, *txt, *value = NULL, c;
  if (!txt_)
    return 0;
  t = txt = strdup(txt_);
  if (t == NULL) {
    printf("Out of memory\n");
    exit(1);
  }
  while ((c = *t) != '\0') {
    if (c == '=') {
      *t = '\0';
      value = t + 1;
    } else if (c == '+') {
      *t = ' ';
    } else if (c == '%') {
      t = convert_query_hexchar(t);
    } else if (c == '&') {
      *t = '\0';
      (*fn)(txt, value);
      txt = t + 1;
      value = NULL;
    }
    t++;
  }
  if (t != txt)
    (*fn)(txt, value);
  return 0;
}


x86 assembly (clang, -O0):
<http_parse_querystring>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x30(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    116f <http_parse_querystring+0x2f>
movl   $0x0,-0x4(%rbp)
jmp    1291 <http_parse_querystring+0x151>
mov    -0x10(%rbp),%rdi
call   1060 <strdup@plt>
mov    %rax,-0x28(%rbp)
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11a1 <http_parse_querystring+0x61>
lea    0xe6e(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1040 <exit@plt>
jmp    11a6 <http_parse_querystring+0x66>
mov    -0x20(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x31(%rbp)
movsbl %al,%eax
cmp    $0x0,%eax
je     126e <http_parse_querystring+0x12e>
movsbl -0x31(%rbp),%eax
cmp    $0x3d,%eax
jne    11e0 <http_parse_querystring+0xa0>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    125d <http_parse_querystring+0x11d>
movsbl -0x31(%rbp),%eax
cmp    $0x2b,%eax
jne    11f9 <http_parse_querystring+0xb9>
mov    -0x20(%rbp),%rax
movb   $0x20,(%rax)
jmp    1258 <http_parse_querystring+0x118>
movsbl -0x31(%rbp),%eax
cmp    $0x25,%eax
jne    1218 <http_parse_querystring+0xd8>
mov    -0x20(%rbp),%rdi
call   1050 <convert_query_hexchar@plt>
mov    %rax,-0x20(%rbp)
jmp    1253 <http_parse_querystring+0x113>
movsbl -0x31(%rbp),%eax
cmp    $0x26,%eax
jne    124e <http_parse_querystring+0x10e>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   *%rax
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
jmp    1253 <http_parse_querystring+0x113>
jmp    1258 <http_parse_querystring+0x118>
jmp    125d <http_parse_querystring+0x11d>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    11a6 <http_parse_querystring+0x66>
mov    -0x20(%rbp),%rax
cmp    -0x28(%rbp),%rax
je     128a <http_parse_querystring+0x14a>
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   *%rax
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<http_parse_querystring>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
test   %rdi,%rdi
je     11dd <http_parse_querystring+0x9d>
mov    %rsi,%r14
call   1060 <strdup@plt>
test   %rax,%rax
je     11e9 <http_parse_querystring+0xa9>
mov    %rax,%rbx
xor    %r12d,%r12d
lea    0xe90(%rip),%r13
mov    %rax,%r15
jmp    118c <http_parse_querystring+0x4c>
movb   $0x0,(%rbx)
mov    %r15,%rdi
mov    %r12,%rsi
call   *%r14
lea    0x1(%rbx),%r15
xor    %r12d,%r12d
add    $0x1,%rbx
movzbl (%rbx),%eax
lea    -0x25(%rax),%ecx
cmp    $0x18,%cl
ja     11cb <http_parse_querystring+0x8b>
movzbl %cl,%eax
movslq 0x0(%r13,%rax,4),%rax
add    %r13,%rax
jmp    *%rax
mov    %rbx,%rdi
call   1050 <convert_query_hexchar@plt>
mov    %rax,%rbx
add    $0x1,%rbx
jmp    118c <http_parse_querystring+0x4c>
movb   $0x20,(%rbx)
add    $0x1,%rbx
jmp    118c <http_parse_querystring+0x4c>
movb   $0x0,(%rbx)
lea    0x1(%rbx),%r12
add    $0x1,%rbx
jmp    118c <http_parse_querystring+0x4c>
test   %al,%al
jne    1188 <http_parse_querystring+0x48>
cmp    %r15,%rbx
je     11dd <http_parse_querystring+0x9d>
mov    %r15,%rdi
mov    %r12,%rsi
call   *%r14
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
lea    0xe74(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1040 <exit@plt>

LLVM IR (-O0):
@.str = [15 x i8] c"Out of memory\0A\00"
define i32 @http_parse_querystring(i8* %0, void (i8*, i8*)* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca void (i8*, i8*)*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8
store i8* %0, i8** %4
store void (i8*, i8*)* %1, void (i8*, i8*)** %5
store i8* null, i8** %8
%10 = load i8*, i8** %4
%11 = icmp ne i8* %10, null
br i1 %11, label %13, label %12
12: ; preds = %2
store i32 0, i32* %3
br label %74
13: ; preds = %2
%14 = load i8*, i8** %4
%15 = call i8* @strdup(i8* %14)
store i8* %15, i8** %7
store i8* %15, i8** %6
%16 = load i8*, i8** %6
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %21
18: ; preds = %13
%19 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %13
br label %22
22: ; preds = %62, %21
%23 = load i8*, i8** %6
%24 = load i8, i8* %23
store i8 %24, i8* %9
%25 = sext i8 %24 to i32
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %65
27: ; preds = %22
%28 = load i8, i8* %9
%29 = sext i8 %28 to i32
%30 = icmp eq i32 %29, 61
br i1 %30, label %31, label %35
31: ; preds = %27
%32 = load i8*, i8** %6
store i8 0, i8* %32
%33 = load i8*, i8** %6
%34 = getelementptr inbounds i8, i8* %33, i64 1
store i8* %34, i8** %8
br label %62
35: ; preds = %27
%36 = load i8, i8* %9
%37 = sext i8 %36 to i32
%38 = icmp eq i32 %37, 43
br i1 %38, label %39, label %41
39: ; preds = %35
%40 = load i8*, i8** %6
store i8 32, i8* %40
br label %61
41: ; preds = %35
%42 = load i8, i8* %9
%43 = sext i8 %42 to i32
%44 = icmp eq i32 %43, 37
br i1 %44, label %45, label %48
45: ; preds = %41
%46 = load i8*, i8** %6
%47 = call i8* @convert_query_hexchar(i8* %46)
store i8* %47, i8** %6
br label %60
48: ; preds = %41
%49 = load i8, i8* %9
%50 = sext i8 %49 to i32
%51 = icmp eq i32 %50, 38
br i1 %51, label %52, label %59
52: ; preds = %48
%53 = load i8*, i8** %6
store i8 0, i8* %53
%54 = load void (i8*, i8*)*, void (i8*, i8*)** %5
%55 = load i8*, i8** %7
%56 = load i8*, i8** %8
%57 = load i8*, i8** %6
%58 = getelementptr inbounds i8, i8* %57, i64 1
store i8* %58, i8** %7
store i8* null, i8** %8
br label %59
59: ; preds = %52, %48
br label %60
60: ; preds = %59, %45
br label %61
61: ; preds = %60, %39
br label %62
62: ; preds = %61, %31
%63 = load i8*, i8** %6
%64 = getelementptr inbounds i8, i8* %63, i32 1
store i8* %64, i8** %6
br label %22
65: ; preds = %22
%66 = load i8*, i8** %6
%67 = load i8*, i8** %7
%68 = icmp ne i8* %66, %67
br i1 %68, label %69, label %73
69: ; preds = %65
%70 = load void (i8*, i8*)*, void (i8*, i8*)** %5
%71 = load i8*, i8** %7
%72 = load i8*, i8** %8
br label %73
73: ; preds = %69, %65
store i32 0, i32* %3
br label %74
74: ; preds = %73, %12
%75 = load i32, i32* %3
ret i32 %75
}

LLVM IR (-O2):
@str = [14 x i8] c"Out of memory\00"
define i32 @http_parse_querystring(i8* %0, void (i8*, i8*)* nocapture %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %30, label %4
4: ; preds = %2
%5 = tail call i8* @strdup(i8* %0)
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %10
7: ; preds = %4
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %4, %22
%11 = phi i8* [ %26, %22 ], [ %5, %4 ]
%12 = phi i8* [ %24, %22 ], [ %5, %4 ]
%13 = phi i8* [ %25, %22 ], [ null, %4 ]
%14 = load i8, i8* %11
switch i8 %14, label %22 [
i8 0, label %27
i8 61, label %15
i8 43, label %17
i8 37, label %18
i8 38, label %20
]
15: ; preds = %10
store i8 0, i8* %11
%16 = getelementptr inbounds i8, i8* %11, i64 1
br label %22
17: ; preds = %10
store i8 32, i8* %11
br label %22
18: ; preds = %10
%19 = tail call i8* @convert_query_hexchar(i8* %11)
br label %22
20: ; preds = %10
store i8 0, i8* %11
tail call void %1(i8* %12, i8* %13)
%21 = getelementptr inbounds i8, i8* %11, i64 1
br label %22
22: ; preds = %10, %17, %20, %18, %15
%23 = phi i8* [ %11, %15 ], [ %11, %17 ], [ %19, %18 ], [ %11, %20 ], [ %11, %10 ]
%24 = phi i8* [ %12, %15 ], [ %12, %17 ], [ %12, %18 ], [ %21, %20 ], [ %12, %10 ]
%25 = phi i8* [ %16, %15 ], [ %13, %17 ], [ %13, %18 ], [ null, %20 ], [ %13, %10 ]
%26 = getelementptr inbounds i8, i8* %23, i64 1
br label %10
27: ; preds = %10
%28 = icmp eq i8* %11, %12
br i1 %28, label %30, label %29
29: ; preds = %27
tail call void %1(i8* %12, i8* %13)
br label %30
30: ; preds = %27, %29, %2
ret i32 0
}