#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 scalar_t__ uint32_t;
struct hashtable {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ hashtable_get_val(struct hashtable *, scalar_t__);
scalar_t__ hashtable_insert_alloc(struct hashtable *, char *, size_t, int);
scalar_t__ hashtable_lookup(struct hashtable *, char *, size_t);
int /*<<< orphan*/ http_uri_decode(char *, int /*<<< orphan*/);
char *strchrnul(char *, char);
void http_uri_decode_query_params(char *query_params,
                                  struct hashtable *params) {
  while (*query_params) {
    char saved_char[2] = {0, 0};
    char *key = query_params;
    char *p1 = strchrnul(query_params, '&');
    if (*p1) {
      saved_char[0] = *p1;
      *p1 = 0;
      query_params = p1 + 1;
    } else
      query_params = p1;
    char *p2 = strchrnul(key, '='), *val = p2;
    size_t key_len = val - key;
    if (*val) {
      saved_char[1] = *val;
      *val++ = 0;
    }
    uint32_t htofs = hashtable_lookup(params, key, key_len);
    if (!htofs) {
      htofs = hashtable_insert_alloc(params, key, key_len, p1 - val + 1);
      http_uri_decode(val, hashtable_get_val(params, htofs));
    }
    *p2 = saved_char[1];
    *p1 = saved_char[0];
  }
}


x86 assembly (clang, -O0):
<http_uri_decode_query_params>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     12ab <http_uri_decode_query_params+0x14b>
lea    -0x12(%rbp),%rdi
xor    %esi,%esi
mov    $0x2,%edx
call   1060 <memset@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x26,%esi
call   1030 <strchrnul@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmpb   $0x0,(%rax)
je     11d5 <http_uri_decode_query_params+0x75>
mov    -0x28(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x12(%rbp)
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    11dd <http_uri_decode_query_params+0x7d>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0x3d,%esi
call   1030 <strchrnul@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x40(%rbp)
mov    -0x38(%rbp),%rax
cmpb   $0x0,(%rax)
je     122e <http_uri_decode_query_params+0xce>
mov    -0x38(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x11(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x38(%rbp)
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x40(%rbp),%rdx
call   1080 <hashtable_lookup@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    1294 <http_uri_decode_query_params+0x134>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x40(%rbp),%rdx
mov    -0x28(%rbp),%rax
mov    -0x38(%rbp),%rcx
sub    %rcx,%rax
add    $0x1,%rax
mov    %eax,%ecx
call   1050 <hashtable_insert_alloc@plt>
mov    %rax,-0x48(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x48(%rbp),%rsi
call   1070 <hashtable_get_val@plt>
mov    -0x50(%rbp),%rdi
mov    %eax,%esi
call   1040 <http_uri_decode@plt>
mov    -0x11(%rbp),%cl
mov    -0x30(%rbp),%rax
mov    %cl,(%rax)
mov    -0x12(%rbp),%cl
mov    -0x28(%rbp),%rax
mov    %cl,(%rax)
jmp    1170 <http_uri_decode_query_params+0x10>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<http_uri_decode_query_params>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,0x10(%rsp)
cmpb   $0x0,(%rdi)
je     1241 <http_uri_decode_query_params+0xf1>
mov    %rdi,%r12
jmp    119c <http_uri_decode_query_params+0x4c>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movzbl 0xe(%rsp),%eax
mov    %al,(%rbx)
movzbl 0xf(%rsp),%eax
mov    %al,(%r15)
cmpb   $0x0,(%r14)
mov    %r14,%r12
je     1241 <http_uri_decode_query_params+0xf1>
mov    %r12,%rdi
mov    $0x26,%esi
call   1030 <strchrnul@plt>
mov    %rax,%r15
movzbl (%rax),%eax
mov    %r15,%r14
mov    %al,0xf(%rsp)
test   %al,%al
je     11c5 <http_uri_decode_query_params+0x75>
movb   $0x0,(%r15)
mov    %r15,%r14
add    $0x1,%r14
mov    %r12,%rdi
mov    $0x3d,%esi
call   1030 <strchrnul@plt>
mov    %rax,%rbx
mov    %rax,%rbp
sub    %r12,%rbp
movzbl (%rax),%eax
mov    %rbx,%r13
mov    %al,0xe(%rsp)
test   %al,%al
je     11f3 <http_uri_decode_query_params+0xa3>
mov    %rbx,%r13
add    $0x1,%r13
movb   $0x0,(%rbx)
mov    0x10(%rsp),%rdi
mov    %r12,%rsi
mov    %rbp,%rdx
call   1070 <hashtable_lookup@plt>
test   %rax,%rax
jne    1180 <http_uri_decode_query_params+0x30>
mov    %r15d,%ecx
sub    %r13d,%ecx
add    $0x1,%ecx
mov    0x10(%rsp),%rdi
mov    %r12,%rsi
mov    %rbp,%rdx
call   1050 <hashtable_insert_alloc@plt>
mov    0x10(%rsp),%rdi
mov    %rax,%rsi
call   1060 <hashtable_get_val@plt>
mov    %r13,%rdi
mov    %eax,%esi
call   1040 <http_uri_decode@plt>
jmp    1180 <http_uri_decode_query_params+0x30>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.hashtable = type { i32 }
define void @http_uri_decode_query_params(i8* %0, %struct.hashtable* %1) {
%3 = alloca i8*
%4 = alloca %struct.hashtable*
%5 = alloca [2 x i8]
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i64
store i8* %0, i8** %3
store %struct.hashtable* %1, %struct.hashtable** %4
br label %12
12: ; preds = %75, %2
%13 = load i8*, i8** %3
%14 = load i8, i8* %13
%15 = icmp ne i8 %14, 0
br i1 %15, label %16, label %82
16: ; preds = %12
%17 = bitcast [2 x i8]* %5 to i8*
%18 = load i8*, i8** %3
store i8* %18, i8** %6
%19 = load i8*, i8** %3
%20 = call i8* @strchrnul(i8* %19, i8 signext 38)
store i8* %20, i8** %7
%21 = load i8*, i8** %7
%22 = load i8, i8* %21
%23 = icmp ne i8 %22, 0
br i1 %23, label %24, label %31
24: ; preds = %16
%25 = load i8*, i8** %7
%26 = load i8, i8* %25
%27 = getelementptr inbounds [2 x i8], [2 x i8]* %5, i64 0, i64 0
store i8 %26, i8* %27
%28 = load i8*, i8** %7
store i8 0, i8* %28
%29 = load i8*, i8** %7
%30 = getelementptr inbounds i8, i8* %29, i64 1
store i8* %30, i8** %3
br label %33
31: ; preds = %16
%32 = load i8*, i8** %7
store i8* %32, i8** %3
br label %33
33: ; preds = %31, %24
%34 = load i8*, i8** %6
%35 = call i8* @strchrnul(i8* %34, i8 signext 61)
store i8* %35, i8** %8
%36 = load i8*, i8** %8
store i8* %36, i8** %9
%37 = load i8*, i8** %9
%38 = load i8*, i8** %6
%39 = ptrtoint i8* %37 to i64
%40 = ptrtoint i8* %38 to i64
%41 = sub i64 %39, %40
store i64 %41, i64* %10
%42 = load i8*, i8** %9
%43 = load i8, i8* %42
%44 = icmp ne i8 %43, 0
br i1 %44, label %45, label %51
45: ; preds = %33
%46 = load i8*, i8** %9
%47 = load i8, i8* %46
%48 = getelementptr inbounds [2 x i8], [2 x i8]* %5, i64 0, i64 1
store i8 %47, i8* %48
%49 = load i8*, i8** %9
%50 = getelementptr inbounds i8, i8* %49, i32 1
store i8* %50, i8** %9
store i8 0, i8* %49
br label %51
51: ; preds = %45, %33
%52 = load %struct.hashtable*, %struct.hashtable** %4
%53 = load i8*, i8** %6
%54 = load i64, i64* %10
%55 = call i64 @hashtable_lookup(%struct.hashtable* %52, i8* %53, i64 %54)
store i64 %55, i64* %11
%56 = load i64, i64* %11
%57 = icmp ne i64 %56, 0
br i1 %57, label %75, label %58
58: ; preds = %51
%59 = load %struct.hashtable*, %struct.hashtable** %4
%60 = load i8*, i8** %6
%61 = load i64, i64* %10
%62 = load i8*, i8** %7
%63 = load i8*, i8** %9
%64 = ptrtoint i8* %62 to i64
%65 = ptrtoint i8* %63 to i64
%66 = sub i64 %64, %65
%67 = add nsw i64 %66, 1
%68 = trunc i64 %67 to i32
%69 = call i64 @hashtable_insert_alloc(%struct.hashtable* %59, i8* %60, i64 %61, i32 %68)
store i64 %69, i64* %11
%70 = load i8*, i8** %9
%71 = load %struct.hashtable*, %struct.hashtable** %4
%72 = load i64, i64* %11
%73 = call i32 @hashtable_get_val(%struct.hashtable* %71, i64 %72)
%74 = call i32 @http_uri_decode(i8* %70, i32 %73)
br label %75
75: ; preds = %58, %51
%76 = getelementptr inbounds [2 x i8], [2 x i8]* %5, i64 0, i64 1
%77 = load i8, i8* %76
%78 = load i8*, i8** %8
store i8 %77, i8* %78
%79 = getelementptr inbounds [2 x i8], [2 x i8]* %5, i64 0, i64 0
%80 = load i8, i8* %79
%81 = load i8*, i8** %7
store i8 %80, i8* %81
br label %12
82: ; preds = %12
ret void
}

LLVM IR (-O2):
%struct.hashtable = type { i32 }
define void @http_uri_decode_query_params(i8* %0, %struct.hashtable* %1) {
%3 = load i8, i8* %0
%4 = icmp eq i8 %3, 0
br i1 %4, label %38, label %5
5: ; preds = %2, %35
%6 = phi i8* [ %13, %35 ], [ %0, %2 ]
%7 = tail call i8* @strchrnul(i8* %6, i8 signext 38)
%8 = load i8, i8* %7
%9 = icmp eq i8 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %5
store i8 0, i8* %7
%11 = getelementptr inbounds i8, i8* %7, i64 1
br label %12
12: ; preds = %5, %10
%13 = phi i8* [ %11, %10 ], [ %7, %5 ]
%14 = tail call i8* @strchrnul(i8* %6, i8 signext 61)
%15 = ptrtoint i8* %14 to i64
%16 = ptrtoint i8* %6 to i64
%17 = sub i64 %15, %16
%18 = load i8, i8* %14
%19 = icmp eq i8 %18, 0
br i1 %19, label %22, label %20
20: ; preds = %12
%21 = getelementptr inbounds i8, i8* %14, i64 1
store i8 0, i8* %14
br label %22
22: ; preds = %20, %12
%23 = phi i8* [ %21, %20 ], [ %14, %12 ]
%24 = tail call i64 @hashtable_lookup(%struct.hashtable* %1, i8* %6, i64 %17)
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %35
26: ; preds = %22
%27 = ptrtoint i8* %7 to i64
%28 = ptrtoint i8* %23 to i64
%29 = sub i64 %27, %28
%30 = trunc i64 %29 to i32
%31 = add i32 %30, 1
%32 = tail call i64 @hashtable_insert_alloc(%struct.hashtable* %1, i8* %6, i64 %17, i32 %31)
%33 = tail call i32 @hashtable_get_val(%struct.hashtable* %1, i64 %32)
%34 = tail call i32 @http_uri_decode(i8* %23, i32 %33)
br label %35
35: ; preds = %26, %22
store i8 %18, i8* %14
store i8 %8, i8* %7
%36 = load i8, i8* %13
%37 = icmp eq i8 %36, 0
br i1 %37, label %38, label %5
38: ; preds = %35, %2
ret void
}