#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 */
scalar_t__ isspace(char);
int /*<<< orphan*/ shift_right(int, char *);
int strlen(char *);
void replace_spaces(char *str) {
  int i;
  int length = strlen(str);
  for (i = 0; i < length; i++) {
    if (isspace(str[i])) {
      shift_right(i, str);
      shift_right(i + 1, str);
      shift_right(i + 2, str);
      str[i] = '%';
      str[i + 1] = '2';
      str[i + 2] = '0';
    }
  }
}


x86 assembly (clang, -O0):
<replace_spaces>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x10(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11e1 <replace_spaces+0xb1>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1050 <isspace@plt>
cmp    $0x0,%rax
je     11ce <replace_spaces+0x9e>
mov    -0xc(%rbp),%edi
mov    -0x8(%rbp),%rsi
call   1030 <shift_right@plt>
mov    -0xc(%rbp),%edi
add    $0x1,%edi
mov    -0x8(%rbp),%rsi
call   1030 <shift_right@plt>
mov    -0xc(%rbp),%edi
add    $0x2,%edi
mov    -0x8(%rbp),%rsi
call   1030 <shift_right@plt>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movb   $0x25,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x32,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
movb   $0x30,(%rax,%rcx,1)
jmp    11d3 <replace_spaces+0xa3>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    114f <replace_spaces+0x1f>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<replace_spaces>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
call   1040 <strlen@plt>
test   %eax,%eax
jle    11a2 <replace_spaces+0x72>
mov    %eax,%r12d
xor    %ebx,%ebx
jmp    118a <replace_spaces+0x5a>
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    %r14,%rsi
call   1030 <shift_right@plt>
lea    0x1(%rbx),%r15
mov    %r15d,%edi
mov    %r14,%rsi
call   1030 <shift_right@plt>
lea    0x2(%rbx),%rdi
mov    %r14,%rsi
call   1030 <shift_right@plt>
movw   $0x3225,(%r14,%rbx,1)
movb   $0x30,0x2(%r14,%rbx,1)
mov    %r15,%rbx
cmp    %r12,%rbx
je     11a2 <replace_spaces+0x72>
movsbl (%r14,%rbx,1),%edi
call   1050 <isspace@plt>
test   %rax,%rax
jne    1150 <replace_spaces+0x20>
add    $0x1,%rbx
cmp    %r12,%rbx
jne    118a <replace_spaces+0x5a>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define void @replace_spaces(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = icmp sgt i32 %2, 0
br i1 %3, label %4, label %28
4: ; preds = %1
%5 = zext i32 %2 to i64
br label %6
6: ; preds = %4, %25
%7 = phi i64 [ 0, %4 ], [ %26, %25 ]
%8 = getelementptr inbounds i8, i8* %0, i64 %7
%9 = load i8, i8* %8
%10 = tail call i64 @isspace(i8 signext %9)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %6
%13 = add nuw nsw i64 %7, 1
br label %25
14: ; preds = %6
%15 = trunc i64 %7 to i32
%16 = tail call i32 @shift_right(i32 %15, i8* %0)
%17 = add nuw nsw i64 %7, 1
%18 = trunc i64 %17 to i32
%19 = tail call i32 @shift_right(i32 %18, i8* %0)
%20 = add nuw nsw i64 %7, 2
%21 = trunc i64 %20 to i32
%22 = tail call i32 @shift_right(i32 %21, i8* %0)
store i8 37, i8* %8
%23 = getelementptr inbounds i8, i8* %0, i64 %17
store i8 50, i8* %23
%24 = getelementptr inbounds i8, i8* %0, i64 %20
store i8 48, i8* %24
br label %25
25: ; preds = %12, %14
%26 = phi i64 [ %13, %12 ], [ %17, %14 ]
%27 = icmp eq i64 %26, %5
br i1 %27, label %28, label %6
28: ; preds = %25, %1
ret void
}