#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*/ printf(char *);
int stretch(char *, int);
bool percencode(char *input) {
  unsigned int i = 0;
  while (input[i] != '\0') {
    if (input[i] == ' ') {
      if (stretch(&input[i], 2) != true) {
        printf("Error: ran out of memory limit.");
        return false;
      }
      input[i] = '%';
      input[i + 1] = '2';
      input[i + 2] = '0';
      i += 3;
    } else
      ++i;
  }
  return true;
}


x86 assembly (clang, -O0):
<percencode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     11d7 <percencode+0xb7>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
movsbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
jne    11c9 <percencode+0xa9>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%eax
add    %rax,%rdi
mov    $0x2,%esi
call   1040 <stretch@plt>
cmp    $0x1,%eax
je     1190 <percencode+0x70>
lea    0xe81(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11de <percencode+0xbe>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
movb   $0x25,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,%ecx
movb   $0x32,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x2,%ecx
mov    %ecx,%ecx
movb   $0x30,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
add    $0x3,%eax
mov    %eax,-0x14(%rbp)
jmp    11d2 <percencode+0xb2>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1133 <percencode+0x13>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<percencode>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
xor    %r15d,%r15d
jmp    113c <percencode+0x1c>
nopl   (%rax)
mov    $0x1,%eax
test   %cl,%cl
je     117a <percencode+0x5a>
add    %eax,%r15d
mov    %r15d,%ebx
movzbl (%r14,%rbx,1),%ecx
cmp    $0x20,%cl
jne    1130 <percencode+0x10>
add    %r14,%rbx
mov    %rbx,%rdi
mov    $0x2,%esi
call   1040 <stretch@plt>
cmp    $0x1,%eax
jne    1181 <percencode+0x61>
movb   $0x25,(%rbx)
lea    0x1(%r15),%eax
movb   $0x32,(%r14,%rax,1)
lea    0x2(%r15),%eax
movb   $0x30,(%r14,%rax,1)
mov    $0x3,%eax
jmp    1139 <percencode+0x19>
mov    $0x1,%eax
jmp    118f <percencode+0x6f>
lea    0xe78(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [32 x i8] c"Error: ran out of memory limit.\00"
define i32 @percencode(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
store i32 0, i32* %4
br label %5
5: ; preds = %50, %1
%6 = load i8*, i8** %3
%7 = load i32, i32* %4
%8 = zext i32 %7 to i64
%9 = getelementptr inbounds i8, i8* %6, i64 %8
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %51
13: ; preds = %5
%14 = load i8*, i8** %3
%15 = load i32, i32* %4
%16 = zext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %14, i64 %16
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp eq i32 %19, 32
br i1 %20, label %21, label %47
21: ; preds = %13
%22 = load i8*, i8** %3
%23 = load i32, i32* %4
%24 = zext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %22, i64 %24
%26 = call i32 @stretch(i8* %25, i32 2)
%27 = icmp ne i32 %26, 1
br i1 %27, label %28, label %30
28: ; preds = %21
%29 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %2
br label %52
30: ; preds = %21
%31 = load i8*, i8** %3
%32 = load i32, i32* %4
%33 = zext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %31, i64 %33
store i8 37, i8* %34
%35 = load i8*, i8** %3
%36 = load i32, i32* %4
%37 = add i32 %36, 1
%38 = zext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %35, i64 %38
store i8 50, i8* %39
%40 = load i8*, i8** %3
%41 = load i32, i32* %4
%42 = add i32 %41, 2
%43 = zext i32 %42 to i64
%44 = getelementptr inbounds i8, i8* %40, i64 %43
store i8 48, i8* %44
%45 = load i32, i32* %4
%46 = add i32 %45, 3
store i32 %46, i32* %4
br label %50
47: ; preds = %13
%48 = load i32, i32* %4
%49 = add i32 %48, 1
store i32 %49, i32* %4
br label %50
50: ; preds = %47, %30
br label %5
51: ; preds = %5
store i32 1, i32* %2
br label %52
52: ; preds = %51, %28
%53 = load i32, i32* %2
ret i32 %53
}

LLVM IR (-O2):
@.str = [32 x i8] c"Error: ran out of memory limit.\00"
define i32 @percencode(i8* %0) {
br label %2
2: ; preds = %19, %1
%3 = phi i32 [ 0, %1 ], [ %21, %19 ]
%4 = zext i32 %3 to i64
%5 = getelementptr inbounds i8, i8* %0, i64 %4
%6 = load i8, i8* %5
switch i8 %6, label %19 [
i8 0, label %22
i8 32, label %7
]
7: ; preds = %2
%8 = tail call i32 @stretch(i8* %5, i32 2)
%9 = icmp eq i32 %8, 1
br i1 %9, label %12, label %10
10: ; preds = %7
%11 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
br label %22
12: ; preds = %7
store i8 37, i8* %5
%13 = add i32 %3, 1
%14 = zext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %0, i64 %14
store i8 50, i8* %15
%16 = add i32 %3, 2
%17 = zext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %0, i64 %17
store i8 48, i8* %18
br label %19
19: ; preds = %2, %12
%20 = phi i32 [ 3, %12 ], [ 1, %2 ]
%21 = add i32 %3, %20
br label %2
22: ; preds = %2, %10
%23 = phi i32 [ 0, %10 ], [ 1, %2 ]
ret i32 %23
}