#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 *index(char *, char);
int /*<<< orphan*/ memmove(char *, char *, int);
int /*<<< orphan*/ strlen(char *);
char strtol(char *, char **, int);
char *utf8parsing(char *p_buffer) {
  char *ptr = p_buffer;
  char *end = p_buffer;
  if (!p_buffer)
    return p_buffer;
  end += strlen(p_buffer);
  while ((ptr = index(ptr, '%')) != NULL) {
    char value;
    char *next;
    value = strtol(ptr + 1, &next, 16);
    *ptr = value;
    ptr++;
    memmove(ptr, next, end - next);
    end -= next - ptr;
    *end = 0;
  }
  return p_buffer;
}


x86 assembly (clang, -O0):
<utf8parsing>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1174 <utf8parsing+0x34>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1220 <utf8parsing+0xe0>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x25,%esi
call   1040 <index@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     1218 <utf8parsing+0xd8>
mov    -0x18(%rbp),%rdi
add    $0x1,%rdi
lea    -0x30(%rbp),%rsi
mov    $0x10,%edx
call   1050 <strtol@plt>
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x20(%rbp),%rax
mov    -0x30(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
call   1060 <memmove@plt>
mov    -0x30(%rbp),%rdx
mov    -0x18(%rbp),%rax
sub    %rax,%rdx
mov    -0x20(%rbp),%rax
xor    %ecx,%ecx
sub    %rdx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
jmp    118d <utf8parsing+0x4d>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<utf8parsing>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
test   %rdi,%rdi
je     11d1 <utf8parsing+0x91>
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebp
mov    %r14,%rdi
mov    $0x25,%esi
call   1040 <index@plt>
test   %rax,%rax
je     11d1 <utf8parsing+0x91>
mov    %rax,%rbx
movslq %ebp,%r12
add    %r14,%r12
mov    %rsp,%r15
nopl   0x0(%rax,%rax,1)
lea    0x1(%rbx),%rbp
mov    %rbp,%rdi
mov    %r15,%rsi
mov    $0x10,%edx
call   1050 <strtol@plt>
mov    %al,(%rbx)
mov    (%rsp),%rbx
mov    %r12d,%edx
sub    %ebx,%edx
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1060 <memmove@plt>
mov    %rbp,%rax
sub    %rbx,%rax
lea    (%r12,%rax,1),%r13
movb   $0x0,(%r12,%rax,1)
mov    %rbp,%rdi
mov    $0x25,%esi
call   1040 <index@plt>
mov    %rax,%rbx
mov    %r13,%r12
test   %rax,%rax
jne    1180 <utf8parsing+0x40>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @utf8parsing(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8
%7 = alloca i8*
store i8* %0, i8** %3
%8 = load i8*, i8** %3
store i8* %8, i8** %4
%9 = load i8*, i8** %3
store i8* %9, i8** %5
%10 = load i8*, i8** %3
%11 = icmp ne i8* %10, null
br i1 %11, label %14, label %12
12: ; preds = %1
%13 = load i8*, i8** %3
store i8* %13, i8** %2
br label %52
14: ; preds = %1
%15 = load i8*, i8** %3
%16 = call i32 @strlen(i8* %15)
%17 = load i8*, i8** %5
%18 = sext i32 %16 to i64
%19 = getelementptr inbounds i8, i8* %17, i64 %18
store i8* %19, i8** %5
br label %20
20: ; preds = %24, %14
%21 = load i8*, i8** %4
%22 = call i8* @index(i8* %21, i8 signext 37)
store i8* %22, i8** %4
%23 = icmp ne i8* %22, null
br i1 %23, label %24, label %50
24: ; preds = %20
%25 = load i8*, i8** %4
%26 = getelementptr inbounds i8, i8* %25, i64 1
%27 = call signext i8 @strtol(i8* %26, i8** %7, i32 16)
store i8 %27, i8* %6
%28 = load i8, i8* %6
%29 = load i8*, i8** %4
store i8 %28, i8* %29
%30 = load i8*, i8** %4
%31 = getelementptr inbounds i8, i8* %30, i32 1
store i8* %31, i8** %4
%32 = load i8*, i8** %4
%33 = load i8*, i8** %7
%34 = load i8*, i8** %5
%35 = load i8*, i8** %7
%36 = ptrtoint i8* %34 to i64
%37 = ptrtoint i8* %35 to i64
%38 = sub i64 %36, %37
%39 = trunc i64 %38 to i32
%40 = call i32 @memmove(i8* %32, i8* %33, i32 %39)
%41 = load i8*, i8** %7
%42 = load i8*, i8** %4
%43 = ptrtoint i8* %41 to i64
%44 = ptrtoint i8* %42 to i64
%45 = sub i64 %43, %44
%46 = load i8*, i8** %5
%47 = sub i64 0, %45
%48 = getelementptr inbounds i8, i8* %46, i64 %47
store i8* %48, i8** %5
%49 = load i8*, i8** %5
store i8 0, i8* %49
br label %20
50: ; preds = %20
%51 = load i8*, i8** %3
store i8* %51, i8** %2
br label %52
52: ; preds = %50, %12
%53 = load i8*, i8** %2
ret i8* %53
}

LLVM IR (-O2):
define i8* @utf8parsing(i8* returned %0) {
%2 = alloca i8*
%3 = icmp eq i8* %0, null
br i1 %3, label %28, label %4
4: ; preds = %1
%5 = tail call i32 @strlen(i8* %0)
%6 = tail call i8* @index(i8* %0, i8 signext 37)
%7 = icmp eq i8* %6, null
br i1 %7, label %28, label %8
8: ; preds = %4
%9 = sext i32 %5 to i64
%10 = getelementptr inbounds i8, i8* %0, i64 %9
%11 = bitcast i8** %2 to i8*
br label %12
12: ; preds = %8, %12
%13 = phi i8* [ %6, %8 ], [ %26, %12 ]
%14 = phi i8* [ %10, %8 ], [ %25, %12 ]
%15 = getelementptr inbounds i8, i8* %13, i64 1
%16 = call signext i8 @strtol(i8* %15, i8** %2, i32 16)
store i8 %16, i8* %13
%17 = load i8*, i8** %2
%18 = ptrtoint i8* %14 to i64
%19 = ptrtoint i8* %17 to i64
%20 = sub i64 %18, %19
%21 = trunc i64 %20 to i32
%22 = tail call i32 @memmove(i8* %15, i8* %17, i32 %21)
%23 = ptrtoint i8* %15 to i64
%24 = sub i64 %23, %19
%25 = getelementptr inbounds i8, i8* %14, i64 %24
store i8 0, i8* %25
%26 = tail call i8* @index(i8* %15, i8 signext 37)
%27 = icmp eq i8* %26, null
br i1 %27, label %28, label %12
28: ; preds = %12, %4, %1
ret i8* %0
}