#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*/ assert(int);
int sscanf(char *, char *, int *);
scalar_t__ tolower(int);
void preprocessor_convertURNHex(char *str) {
  char *src = str;
  char *dst = str;
  char c;
  while ((c = *src) != '\0') {
    if (c == '%') {
      char hex[3];
      hex[0] = (char)tolower((int)*(src + 1));
      assert(hex[0]);
      hex[1] = (char)tolower((int)*(src + 2));
      assert(hex[1]);
      hex[2] = '\0';
      int i;
      int n = sscanf(hex, "%x", &i);
      assert(n == 1);
      src += 2;
      *src = (char)i;
    }
    *dst = *src;
    src++;
    dst++;
  }
  *dst = '\0';
}


x86 assembly (clang, -O0):
<preprocessor_convertURNHex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x19(%rbp)
movsbl %al,%eax
cmp    $0x0,%eax
je     120c <preprocessor_convertURNHex+0xdc>
movsbl -0x19(%rbp),%eax
cmp    $0x25,%eax
jne    11e3 <preprocessor_convertURNHex+0xb3>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%edi
call   1040 <tolower@plt>
mov    %al,-0x1c(%rbp)
movsbl -0x1c(%rbp),%edi
call   1030 <assert@plt>
mov    -0x10(%rbp),%rax
movsbl 0x2(%rax),%edi
call   1040 <tolower@plt>
mov    %al,-0x1b(%rbp)
movsbl -0x1b(%rbp),%edi
call   1030 <assert@plt>
movb   $0x0,-0x1a(%rbp)
lea    -0x1c(%rbp),%rdi
lea    0xe51(%rip),%rsi
lea    -0x20(%rbp),%rdx
call   1050 <sscanf@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x1,-0x24(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x10(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x10(%rbp)
mov    -0x20(%rbp),%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    114c <preprocessor_convertURNHex+0x1c>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<preprocessor_convertURNHex>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r13
lea    0xebb(%rip),%r14
lea    0x1(%rsp),%r15
lea    0x4(%rsp),%r12
mov    %rdi,%rbx
jmp    11ca <preprocessor_convertURNHex+0x9a>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsbl 0x1(%rbx),%edi
call   1040 <tolower@plt>
mov    %al,0x1(%rsp)
movsbl %al,%edi
call   1030 <assert@plt>
lea    0x2(%rbx),%rbp
movsbl 0x2(%rbx),%edi
call   1040 <tolower@plt>
mov    %al,0x2(%rsp)
movsbl %al,%edi
call   1030 <assert@plt>
movb   $0x0,0x3(%rsp)
mov    %r15,%rdi
mov    %r14,%rsi
mov    %r12,%rdx
call   1050 <sscanf@plt>
xor    %edi,%edi
cmp    $0x1,%eax
sete   %dil
call   1030 <assert@plt>
movzbl 0x4(%rsp),%eax
mov    %al,0x2(%rbx)
movzbl 0x2(%rbx),%eax
mov    %rbp,%rbx
mov    %al,0x0(%r13)
add    $0x1,%rbx
add    $0x1,%r13
movzbl (%rbx),%eax
cmp    $0x25,%al
je     1160 <preprocessor_convertURNHex+0x30>
test   %al,%al
jne    11be <preprocessor_convertURNHex+0x8e>
movb   $0x0,0x0(%r13)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%x\00"
define void @preprocessor_convertURNHex(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8
%6 = alloca [3 x i8]
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %2
%9 = load i8*, i8** %2
store i8* %9, i8** %3
%10 = load i8*, i8** %2
store i8* %10, i8** %4
br label %11
11: ; preds = %55, %1
%12 = load i8*, i8** %3
%13 = load i8, i8* %12
store i8 %13, i8* %5
%14 = sext i8 %13 to i32
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %63
16: ; preds = %11
%17 = load i8, i8* %5
%18 = sext i8 %17 to i32
%19 = icmp eq i32 %18, 37
br i1 %19, label %20, label %55
20: ; preds = %16
%21 = load i8*, i8** %3
%22 = getelementptr inbounds i8, i8* %21, i64 1
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = call i64 @tolower(i32 %24)
%26 = trunc i64 %25 to i8
%27 = getelementptr inbounds [3 x i8], [3 x i8]* %6, i64 0, i64 0
store i8 %26, i8* %27
%28 = getelementptr inbounds [3 x i8], [3 x i8]* %6, i64 0, i64 0
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = call i32 @assert(i32 %30)
%32 = load i8*, i8** %3
%33 = getelementptr inbounds i8, i8* %32, i64 2
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = call i64 @tolower(i32 %35)
%37 = trunc i64 %36 to i8
%38 = getelementptr inbounds [3 x i8], [3 x i8]* %6, i64 0, i64 1
store i8 %37, i8* %38
%39 = getelementptr inbounds [3 x i8], [3 x i8]* %6, i64 0, i64 1
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = call i32 @assert(i32 %41)
%43 = getelementptr inbounds [3 x i8], [3 x i8]* %6, i64 0, i64 2
store i8 0, i8* %43
%44 = getelementptr inbounds [3 x i8], [3 x i8]* %6, i64 0, i64 0
%45 = call i32 @sscanf(i8* %44, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %7)
store i32 %45, i32* %8
%46 = load i32, i32* %8
%47 = icmp eq i32 %46, 1
%48 = zext i1 %47 to i32
%49 = call i32 @assert(i32 %48)
%50 = load i8*, i8** %3
%51 = getelementptr inbounds i8, i8* %50, i64 2
store i8* %51, i8** %3
%52 = load i32, i32* %7
%53 = trunc i32 %52 to i8
%54 = load i8*, i8** %3
store i8 %53, i8* %54
br label %55
55: ; preds = %20, %16
%56 = load i8*, i8** %3
%57 = load i8, i8* %56
%58 = load i8*, i8** %4
store i8 %57, i8* %58
%59 = load i8*, i8** %3
%60 = getelementptr inbounds i8, i8* %59, i32 1
store i8* %60, i8** %3
%61 = load i8*, i8** %4
%62 = getelementptr inbounds i8, i8* %61, i32 1
store i8* %62, i8** %4
br label %11
63: ; preds = %11
%64 = load i8*, i8** %4
store i8 0, i8* %64
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%x\00"
define void @preprocessor_convertURNHex(i8* nocapture %0) {
%2 = alloca [3 x i8]
%3 = alloca i32
%4 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 1
%6 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 2
%7 = bitcast i32* %3 to i8*
br label %8
8: ; preds = %34, %1
%9 = phi i8* [ %0, %1 ], [ %38, %34 ]
%10 = phi i8* [ %0, %1 ], [ %37, %34 ]
%11 = load i8, i8* %10
switch i8 %11, label %34 [
i8 0, label %39
i8 37, label %12
]
12: ; preds = %8
%13 = getelementptr inbounds i8, i8* %10, i64 1
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = call i64 @tolower(i32 %15)
%17 = trunc i64 %16 to i8
store i8 %17, i8* %4
%18 = sext i8 %17 to i32
%19 = call i32 @assert(i32 %18)
%20 = getelementptr inbounds i8, i8* %10, i64 2
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = call i64 @tolower(i32 %22)
%24 = trunc i64 %23 to i8
store i8 %24, i8* %5
%25 = sext i8 %24 to i32
%26 = call i32 @assert(i32 %25)
store i8 0, i8* %6
%27 = call i32 @sscanf(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%28 = icmp eq i32 %27, 1
%29 = zext i1 %28 to i32
%30 = call i32 @assert(i32 %29)
%31 = load i32, i32* %3
%32 = trunc i32 %31 to i8
store i8 %32, i8* %20
%33 = load i8, i8* %20
br label %34
34: ; preds = %8, %12
%35 = phi i8 [ %33, %12 ], [ %11, %8 ]
%36 = phi i8* [ %20, %12 ], [ %10, %8 ]
store i8 %35, i8* %9
%37 = getelementptr inbounds i8, i8* %36, i64 1
%38 = getelementptr inbounds i8, i8* %9, i64 1
br label %8
39: ; preds = %8
store i8 0, i8* %9
ret void
}