#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 */
struct esb_s {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ esb_append(struct esb_s *, char *);
int hexpairtochar(char const *, char *);
void translate_from_uri(const char *input, struct esb_s *out) {
  const char *cp = input;
  char tempstr[2];
  for (; *cp; ++cp) {
    char c = *cp;
    if (c == '%') {
      int increment = 0;
      char c2 = cp[1];
      if (c2 == '%') {
        tempstr[0] = c;
        tempstr[1] = 0;
        esb_append(out, tempstr);
        ++cp;
        continue;
      }
      increment = hexpairtochar(cp + 1, &c);
      tempstr[0] = c;
      tempstr[1] = 0;
      esb_append(out, tempstr);
      cp += increment;
      continue;
    }
    tempstr[0] = c;
    tempstr[1] = 0;
    esb_append(out, tempstr);
  }
}


x86 assembly (clang, -O0):
<translate_from_uri>:
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    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
je     120a <translate_from_uri+0xea>
mov    -0x18(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x1b(%rbp)
movsbl -0x1b(%rbp),%eax
cmp    $0x25,%eax
jne    11e2 <translate_from_uri+0xc2>
movl   $0x0,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    0x1(%rax),%al
mov    %al,-0x21(%rbp)
movsbl -0x21(%rbp),%eax
cmp    $0x25,%eax
jne    11a1 <translate_from_uri+0x81>
mov    -0x1b(%rbp),%al
mov    %al,-0x1a(%rbp)
movb   $0x0,-0x19(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x1a(%rbp),%rsi
call   1040 <esb_append@plt>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    11f9 <translate_from_uri+0xd9>
mov    -0x18(%rbp),%rdi
add    $0x1,%rdi
lea    -0x1b(%rbp),%rsi
call   1030 <hexpairtochar@plt>
mov    %eax,-0x20(%rbp)
mov    -0x1b(%rbp),%al
mov    %al,-0x1a(%rbp)
movb   $0x0,-0x19(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x1a(%rbp),%rsi
call   1040 <esb_append@plt>
mov    -0x20(%rbp),%ecx
mov    -0x18(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
jmp    11f9 <translate_from_uri+0xd9>
mov    -0x1b(%rbp),%al
mov    %al,-0x1a(%rbp)
movb   $0x0,-0x19(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x1a(%rbp),%rsi
call   1040 <esb_append@plt>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1138 <translate_from_uri+0x18>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<translate_from_uri>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    (%rdi),%al
test   %al,%al
je     11ce <translate_from_uri+0xae>
mov    %rsi,%r12
mov    %rdi,%r13
lea    0xe(%rsp),%r14
lea    0xd(%rsp),%r15
jmp    1176 <translate_from_uri+0x56>
nopl   0x0(%rax)
mov    %al,0xe(%rsp)
movb   $0x0,0xf(%rsp)
mov    %r12,%rdi
mov    %r14,%rsi
call   1040 <esb_append@plt>
mov    %r13,%rbx
movzbl 0x1(%rbx),%eax
add    $0x1,%rbx
mov    %rbx,%r13
test   %al,%al
je     11ce <translate_from_uri+0xae>
mov    %al,0xd(%rsp)
cmp    $0x25,%al
jne    1150 <translate_from_uri+0x30>
lea    0x1(%r13),%rbx
cmpb   $0x25,0x1(%r13)
jne    11a0 <translate_from_uri+0x80>
movw   $0x25,0xe(%rsp)
mov    %r12,%rdi
mov    %r14,%rsi
call   1040 <esb_append@plt>
jmp    1167 <translate_from_uri+0x47>
nopl   (%rax)
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <hexpairtochar@plt>
mov    %eax,%ebx
movzbl 0xd(%rsp),%eax
mov    %al,0xe(%rsp)
movb   $0x0,0xf(%rsp)
mov    %r12,%rdi
mov    %r14,%rsi
call   1040 <esb_append@plt>
movslq %ebx,%rax
add    %rax,%r13
jmp    1164 <translate_from_uri+0x44>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
%struct.esb_s = type { i32 }
define void @translate_from_uri(i8* %0, %struct.esb_s* %1) {
%3 = alloca [2 x i8]
%4 = alloca i8
%5 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 0
%6 = load i8, i8* %0
%7 = icmp eq i8 %6, 0
br i1 %7, label %33, label %8
8: ; preds = %2
%9 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 1
br label %10
10: ; preds = %8, %28
%11 = phi i8 [ %6, %8 ], [ %31, %28 ]
%12 = phi i8* [ %0, %8 ], [ %30, %28 ]
store i8 %11, i8* %4
%13 = icmp eq i8 %11, 37
br i1 %13, label %14, label %26
14: ; preds = %10
%15 = getelementptr inbounds i8, i8* %12, i64 1
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 37
br i1 %17, label %18, label %20
18: ; preds = %14
store i8 37, i8* %5
store i8 0, i8* %9
%19 = call i32 @esb_append(%struct.esb_s* %1, i8* %5)
br label %28
20: ; preds = %14
%21 = call i32 @hexpairtochar(i8* %15, i8* %4)
%22 = load i8, i8* %4
store i8 %22, i8* %5
store i8 0, i8* %9
%23 = call i32 @esb_append(%struct.esb_s* %1, i8* %5)
%24 = sext i32 %21 to i64
%25 = getelementptr inbounds i8, i8* %12, i64 %24
br label %28
26: ; preds = %10
store i8 %11, i8* %5
store i8 0, i8* %9
%27 = call i32 @esb_append(%struct.esb_s* %1, i8* %5)
br label %28
28: ; preds = %18, %20, %26
%29 = phi i8* [ %12, %26 ], [ %15, %18 ], [ %25, %20 ]
%30 = getelementptr inbounds i8, i8* %29, i64 1
%31 = load i8, i8* %30
%32 = icmp eq i8 %31, 0
br i1 %32, label %33, label %10
33: ; preds = %28, %2
ret void
}