#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 */
#define EOF 128
int read_char();
int read_hex();
size_t read_item(char *str, size_t maxlen) {
  int c;
  size_t pos = 0;
  while (1) {
    c = read_char();
    switch (c) {
    case EOF:
    case '=':
    case '&':
      str[pos] = '\0';
      return pos;
    case '%':
      c = read_hex();
      break;
    case '+':
      c = ' ';
      break;
    }
    if (pos < maxlen - 1) {
      str[pos] = c;
      pos += 1;
    }
  }
}


x86 assembly (clang, -O0):
<read_item>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
xor    %eax,%eax
call   1040 <read_char@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
sub    $0x25,%eax
je     11b2 <read_item+0x92>
jmp    1156 <read_item+0x36>
mov    -0x24(%rbp),%eax
sub    $0x26,%eax
je     119c <read_item+0x7c>
jmp    1167 <read_item+0x47>
mov    -0x24(%rbp),%eax
sub    $0x2b,%eax
je     11c1 <read_item+0xa1>
jmp    1178 <read_item+0x58>
mov    -0x24(%rbp),%eax
sub    $0x3d,%eax
je     119c <read_item+0x7c>
jmp    1189 <read_item+0x69>
mov    -0x24(%rbp),%eax
sub    $0x80,%eax
jne    11c8 <read_item+0xa8>
jmp    119c <read_item+0x7c>
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret
mov    $0x0,%al
call   1030 <read_hex@plt>
mov    %eax,-0x14(%rbp)
jmp    11c8 <read_item+0xa8>
movl   $0x20,-0x14(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    $0x1,%rcx
cmp    %rcx,%rax
jae    11f9 <read_item+0xd9>
mov    -0x14(%rbp),%eax
mov    %al,%dl
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1138 <read_item+0x18>

x86 assembly (clang, -O2):
<read_item>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%r14
add    $0xffffffffffffffff,%r15
lea    0xec7(%rip),%r12
xor    %ebx,%ebx
jmp    114a <read_item+0x2a>
nopl   (%rax)
mov    $0x20,%eax
cmp    %r15,%rbx
jb     1174 <read_item+0x54>
xor    %eax,%eax
call   1040 <read_char@plt>
lea    -0x25(%rax),%ecx
cmp    $0x18,%ecx
ja     116b <read_item+0x4b>
movslq (%r12,%rcx,4),%rcx
add    %r12,%rcx
jmp    *%rcx
xor    %eax,%eax
call   1030 <read_hex@plt>
jmp    1145 <read_item+0x25>
cmp    $0x80,%eax
jne    1145 <read_item+0x25>
jmp    117e <read_item+0x5e>
mov    %al,(%r14,%rbx,1)
add    $0x1,%rbx
jmp    114a <read_item+0x2a>
movb   $0x0,(%r14,%rbx,1)
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i64 @read_item(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
%6 = alloca i64
store i8* %0, i8** %3
store i64 %1, i64* %4
store i64 0, i64* %6
br label %7
7: ; preds = %2, %31
%8 = call i32 (...) @read_char()
store i32 %8, i32* %5
%9 = load i32, i32* %5
switch i32 %9, label %18 [
i32 128, label %10
i32 61, label %10
i32 38, label %10
i32 37, label %15
i32 43, label %17
]
10: ; preds = %7, %7, %7
%11 = load i8*, i8** %3
%12 = load i64, i64* %6
%13 = getelementptr inbounds i8, i8* %11, i64 %12
store i8 0, i8* %13
%14 = load i64, i64* %6
ret i64 %14
15: ; preds = %7
%16 = call i32 (...) @read_hex()
store i32 %16, i32* %5
br label %18
17: ; preds = %7
store i32 32, i32* %5
br label %18
18: ; preds = %7, %17, %15
%19 = load i64, i64* %6
%20 = load i64, i64* %4
%21 = sub i64 %20, 1
%22 = icmp ult i64 %19, %21
br i1 %22, label %23, label %31
23: ; preds = %18
%24 = load i32, i32* %5
%25 = trunc i32 %24 to i8
%26 = load i8*, i8** %3
%27 = load i64, i64* %6
%28 = getelementptr inbounds i8, i8* %26, i64 %27
store i8 %25, i8* %28
%29 = load i64, i64* %6
%30 = add i64 %29, 1
store i64 %30, i64* %6
br label %31
31: ; preds = %23, %18
br label %7
}

LLVM IR (-O2):
define i64 @read_item(i8* nocapture writeonly %0, i64 %1) {
%3 = add i64 %1, -1
br label %4
4: ; preds = %16, %2
%5 = phi i64 [ %19, %16 ], [ 0, %2 ]
%6 = icmp ult i64 %5, %3
br label %7
7: ; preds = %4, %14
%8 = tail call i32 (...) @read_char()
switch i32 %8, label %14 [
i32 128, label %9
i32 61, label %9
i32 38, label %9
i32 37, label %11
i32 43, label %13
]
9: ; preds = %7, %7, %7
%10 = getelementptr inbounds i8, i8* %0, i64 %5
store i8 0, i8* %10
ret i64 %5
11: ; preds = %7
%12 = tail call i32 (...) @read_hex()
br label %14
13: ; preds = %7
br label %14
14: ; preds = %7, %13, %11
%15 = phi i32 [ %8, %7 ], [ 32, %13 ], [ %12, %11 ]
br i1 %6, label %16, label %7
16: ; preds = %14
%17 = trunc i32 %15 to i8
%18 = getelementptr inbounds i8, i8* %0, i64 %5
store i8 %17, i8* %18
%19 = add nuw i64 %5, 1
br label %4
}