#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 ldap_int_unhex(char);
void ldap_pvt_hex_unescape(char *s) {
  char *p;
  for (p = s; *s != '\0'; ++s) {
    if (*s == '%') {
      if (*++s == '\0') {
        break;
      }
      *p = ldap_int_unhex(*s) << 4;
      if (*++s == '\0') {
        break;
      }
      *p++ += ldap_int_unhex(*s);
    } else {
      *p++ = *s;
    }
  }
  *p = '\0';
}


x86 assembly (clang, -O0):
<ldap_pvt_hex_unescape>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11f3 <ldap_pvt_hex_unescape+0xe3>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x25,%eax
jne    11c6 <ldap_pvt_hex_unescape+0xb6>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movsbl 0x1(%rax),%eax
cmp    $0x0,%eax
jne    1165 <ldap_pvt_hex_unescape+0x55>
jmp    11f3 <ldap_pvt_hex_unescape+0xe3>
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1030 <ldap_int_unhex@plt>
shl    $0x4,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movsbl 0x1(%rax),%eax
cmp    $0x0,%eax
jne    119d <ldap_pvt_hex_unescape+0x8d>
jmp    11f3 <ldap_pvt_hex_unescape+0xe3>
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1030 <ldap_int_unhex@plt>
mov    %eax,%edx
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movsbl (%rax),%ecx
add    %edx,%ecx
mov    %cl,(%rax)
jmp    11dd <ldap_pvt_hex_unescape+0xcd>
mov    -0x8(%rbp),%rax
mov    (%rax),%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
jmp    11e2 <ldap_pvt_hex_unescape+0xd2>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1124 <ldap_pvt_hex_unescape+0x14>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ldap_pvt_hex_unescape>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    %rdi,%r14
jmp    112f <ldap_pvt_hex_unescape+0x1f>
nopl   0x0(%rax)
test   %al,%al
je     1165 <ldap_pvt_hex_unescape+0x55>
mov    %al,(%r14)
add    $0x1,%r14
add    $0x1,%rbx
movzbl (%rbx),%eax
cmp    $0x25,%al
jne    1120 <ldap_pvt_hex_unescape+0x10>
movzbl 0x1(%rbx),%eax
test   %al,%al
je     1165 <ldap_pvt_hex_unescape+0x55>
movsbl %al,%edi
call   1030 <ldap_int_unhex@plt>
shl    $0x4,%al
mov    %al,(%r14)
movzbl 0x2(%rbx),%eax
test   %al,%al
je     1165 <ldap_pvt_hex_unescape+0x55>
add    $0x2,%rbx
movsbl %al,%edi
call   1030 <ldap_int_unhex@plt>
add    (%r14),%al
jmp    1124 <ldap_pvt_hex_unescape+0x14>
movb   $0x0,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define void @ldap_pvt_hex_unescape(i8* nocapture %0) {
br label %2
2: ; preds = %22, %1
%3 = phi i8* [ %0, %1 ], [ %26, %22 ]
%4 = phi i8* [ %0, %1 ], [ %25, %22 ]
%5 = load i8, i8* %3
switch i8 %5, label %22 [
i8 0, label %27
i8 37, label %6
]
6: ; preds = %2
%7 = getelementptr inbounds i8, i8* %3, i64 1
%8 = load i8, i8* %7
%9 = icmp eq i8 %8, 0
br i1 %9, label %27, label %10
10: ; preds = %6
%11 = tail call i32 @ldap_int_unhex(i8 signext %8)
%12 = trunc i32 %11 to i8
%13 = shl i8 %12, 4
store i8 %13, i8* %4
%14 = getelementptr inbounds i8, i8* %3, i64 2
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 0
br i1 %16, label %27, label %17
17: ; preds = %10
%18 = tail call i32 @ldap_int_unhex(i8 signext %15)
%19 = load i8, i8* %4
%20 = trunc i32 %18 to i8
%21 = add i8 %19, %20
br label %22
22: ; preds = %2, %17
%23 = phi i8 [ %21, %17 ], [ %5, %2 ]
%24 = phi i8* [ %14, %17 ], [ %3, %2 ]
%25 = getelementptr inbounds i8, i8* %4, i64 1
store i8 %23, i8* %4
%26 = getelementptr inbounds i8, i8* %24, i64 1
br label %2
27: ; preds = %2, %10, %6
store i8 0, i8* %4
ret void
}