#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 cgltf_unhex(char);
void cgltf_decode_uri(char *uri) {
  char *write = uri;
  char *i = uri;
  while (*i) {
    if (*i == '%') {
      int ch1 = cgltf_unhex(i[1]);
      if (ch1 >= 0) {
        int ch2 = cgltf_unhex(i[2]);
        if (ch2 >= 0) {
          *write++ = (char)(ch1 * 16 + ch2);
          i += 3;
          continue;
        }
      }
    }
    *write++ = *i++;
  }
  *write = 0;
}


x86 assembly (clang, -O0):
<cgltf_decode_uri>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
je     11db <cgltf_decode_uri+0xcb>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x25,%eax
jne    11b4 <cgltf_decode_uri+0xa4>
mov    -0x18(%rbp),%rax
movsbl 0x1(%rax),%edi
call   1030 <cgltf_unhex@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jl     11af <cgltf_decode_uri+0x9f>
mov    -0x18(%rbp),%rax
movsbl 0x2(%rax),%edi
call   1030 <cgltf_unhex@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jl     11aa <cgltf_decode_uri+0x9a>
mov    -0x1c(%rbp),%eax
shl    $0x4,%eax
add    -0x20(%rbp),%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
mov    -0x18(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x18(%rbp)
jmp    112c <cgltf_decode_uri+0x1c>
jmp    11af <cgltf_decode_uri+0x9f>
jmp    11b4 <cgltf_decode_uri+0xa4>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
mov    (%rax),%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
jmp    112c <cgltf_decode_uri+0x1c>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cgltf_decode_uri>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
mov    %rdi,%rbp
jmp    1132 <cgltf_decode_uri+0x22>
nopl   0x0(%rax)
test   %al,%al
je     116a <cgltf_decode_uri+0x5a>
movzbl (%rbx),%eax
add    $0x1,%rbx
mov    %al,0x0(%rbp)
add    $0x1,%rbp
movzbl (%rbx),%eax
cmp    $0x25,%al
jne    1120 <cgltf_decode_uri+0x10>
movsbl 0x1(%rbx),%edi
call   1030 <cgltf_unhex@plt>
test   %eax,%eax
js     1124 <cgltf_decode_uri+0x14>
mov    %eax,%r14d
movsbl 0x2(%rbx),%edi
call   1030 <cgltf_unhex@plt>
test   %eax,%eax
js     1124 <cgltf_decode_uri+0x14>
shl    $0x4,%r14d
add    %r14d,%eax
mov    %al,0x0(%rbp)
add    $0x3,%rbx
add    $0x1,%rbp
jmp    1132 <cgltf_decode_uri+0x22>
movb   $0x0,0x0(%rbp)
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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