#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 */
int /*<<< orphan*/ hex_val(char **);
size_t http_uri_decode(char *uri, char *target) {
  char *p1 = uri, *p2 = target;
  const char SPACE = ' ';
  while (*p1) {
    switch (*p1) {
    case '%':
      ++p1;
      *p2++ = hex_val(&p1);
      break;
    case '+':
      *p2++ = SPACE;
      ++p1;
      break;
    default:
      *p2++ = *p1++;
    }
  }
  *p2 = 0;
  return p2 - target + 1;
}


x86 assembly (clang, -O0):
<http_uri_decode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
movb   $0x20,-0x21(%rbp)
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
je     11e1 <http_uri_decode+0xd1>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x28(%rbp)
sub    $0x25,%eax
je     116a <http_uri_decode+0x5a>
jmp    1159 <http_uri_decode+0x49>
mov    -0x28(%rbp),%eax
sub    $0x2b,%eax
je     1197 <http_uri_decode+0x87>
jmp    11ba <http_uri_decode+0xaa>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
lea    -0x18(%rbp),%rdi
call   1030 <hex_val@plt>
mov    %al,%cl
mov    -0x20(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x20(%rbp)
mov    %cl,(%rax)
jmp    11dc <http_uri_decode+0xcc>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movb   $0x20,(%rax)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    11dc <http_uri_decode+0xcc>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
mov    (%rax),%cl
mov    -0x20(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x20(%rbp)
mov    %cl,(%rax)
jmp    1134 <http_uri_decode+0x24>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
add    $0x1,%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<http_uri_decode>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    (%rdi),%al
mov    %rsi,%rbx
test   %al,%al
je     118e <http_uri_decode+0x7e>
lea    0x8(%rsp),%r15
mov    %r14,%rbx
jmp    114c <http_uri_decode+0x3c>
nop
lea    0x1(%rdi),%rax
mov    %rax,0x8(%rsp)
movzbl (%rdi),%ecx
mov    %cl,(%rbx)
mov    %rax,%rdi
add    $0x1,%rbx
movzbl (%rdi),%eax
test   %al,%al
je     118e <http_uri_decode+0x7e>
movsbl %al,%eax
cmp    $0x2b,%eax
je     1180 <http_uri_decode+0x70>
cmp    $0x25,%eax
jne    1130 <http_uri_decode+0x20>
add    $0x1,%rdi
mov    %rdi,0x8(%rsp)
mov    %r15,%rdi
call   1030 <hex_val@plt>
mov    %al,(%rbx)
mov    0x8(%rsp),%rdi
jmp    1141 <http_uri_decode+0x31>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movb   $0x20,(%rbx)
add    $0x1,%rdi
mov    %rdi,0x8(%rsp)
jmp    1141 <http_uri_decode+0x31>
movb   $0x0,(%rbx)
sub    %r14,%rbx
add    $0x1,%rbx
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i64 @http_uri_decode(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8
store i8* %0, i8** %3
store i8* %1, i8** %4
%8 = load i8*, i8** %3
store i8* %8, i8** %5
%9 = load i8*, i8** %4
store i8* %9, i8** %6
store i8 32, i8* %7
br label %10
10: ; preds = %36, %2
%11 = load i8*, i8** %5
%12 = load i8, i8* %11
%13 = icmp ne i8 %12, 0
br i1 %13, label %14, label %37
14: ; preds = %10
%15 = load i8*, i8** %5
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
switch i32 %17, label %30 [
i32 37, label %18
i32 43, label %25
]
18: ; preds = %14
%19 = load i8*, i8** %5
%20 = getelementptr inbounds i8, i8* %19, i32 1
store i8* %20, i8** %5
%21 = call i32 @hex_val(i8** %5)
%22 = trunc i32 %21 to i8
%23 = load i8*, i8** %6
%24 = getelementptr inbounds i8, i8* %23, i32 1
store i8* %24, i8** %6
store i8 %22, i8* %23
br label %36
25: ; preds = %14
%26 = load i8*, i8** %6
%27 = getelementptr inbounds i8, i8* %26, i32 1
store i8* %27, i8** %6
store i8 32, i8* %26
%28 = load i8*, i8** %5
%29 = getelementptr inbounds i8, i8* %28, i32 1
store i8* %29, i8** %5
br label %36
30: ; preds = %14
%31 = load i8*, i8** %5
%32 = getelementptr inbounds i8, i8* %31, i32 1
store i8* %32, i8** %5
%33 = load i8, i8* %31
%34 = load i8*, i8** %6
%35 = getelementptr inbounds i8, i8* %34, i32 1
store i8* %35, i8** %6
store i8 %33, i8* %34
br label %36
36: ; preds = %30, %25, %18
br label %10
37: ; preds = %10
%38 = load i8*, i8** %6
store i8 0, i8* %38
%39 = load i8*, i8** %6
%40 = load i8*, i8** %4
%41 = ptrtoint i8* %39 to i64
%42 = ptrtoint i8* %40 to i64
%43 = sub i64 %41, %42
%44 = add nsw i64 %43, 1
ret i64 %44
}

LLVM IR (-O2):
define i64 @http_uri_decode(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = load i8, i8* %0
%6 = icmp eq i8 %5, 0
br i1 %6, label %27, label %7
7: ; preds = %2, %22
%8 = phi i8 [ %25, %22 ], [ %5, %2 ]
%9 = phi i8* [ %23, %22 ], [ %0, %2 ]
%10 = phi i8* [ %24, %22 ], [ %1, %2 ]
%11 = sext i8 %8 to i32
switch i32 %11, label %19 [
i32 37, label %12
i32 43, label %17
]
12: ; preds = %7
%13 = getelementptr inbounds i8, i8* %9, i64 1
store i8* %13, i8** %3
%14 = call i32 @hex_val(i8** %3)
%15 = trunc i32 %14 to i8
store i8 %15, i8* %10
%16 = load i8*, i8** %3
br label %22
17: ; preds = %7
store i8 32, i8* %10
%18 = getelementptr inbounds i8, i8* %9, i64 1
store i8* %18, i8** %3
br label %22
19: ; preds = %7
%20 = getelementptr inbounds i8, i8* %9, i64 1
store i8* %20, i8** %3
%21 = load i8, i8* %9
store i8 %21, i8* %10
br label %22
22: ; preds = %19, %17, %12
%23 = phi i8* [ %20, %19 ], [ %18, %17 ], [ %16, %12 ]
%24 = getelementptr inbounds i8, i8* %10, i64 1
%25 = load i8, i8* %23
%26 = icmp eq i8 %25, 0
br i1 %26, label %27, label %7
27: ; preds = %22, %2
%28 = phi i8* [ %1, %2 ], [ %24, %22 ]
store i8 0, i8* %28
%29 = ptrtoint i8* %28 to i64
%30 = ptrtoint i8* %1 to i64
%31 = sub i64 1, %30
%32 = add i64 %31, %29
ret i64 %32
}