#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*/ gets(char *);
int len(char *);
int /*<<< orphan*/ printf(char *, char *, int);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ replaceStr(char *, char *, char *);
int main() {
  char buffer[128];
  char *string;
  string = buffer;
  puts("Input string:");
  gets(string);
  replaceStr(string, " ", "%20");
  printf("%s %d\n", string, len(string));
  replaceStr(string, "%20", "_");
  printf("%s %d\n", string, len(string));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x90(%rbp),%rax
mov    %rax,-0x98(%rbp)
lea    0xe89(%rip),%rdi
call   1050 <puts@plt>
mov    -0x98(%rbp),%rdi
call   1070 <gets@plt>
mov    -0x98(%rbp),%rdi
lea    0xe78(%rip),%rsi
lea    0xe73(%rip),%rdx
call   1040 <replaceStr@plt>
mov    -0x98(%rbp),%rax
mov    %rax,-0xa8(%rbp)
mov    -0x98(%rbp),%rdi
call   1030 <len@plt>
mov    -0xa8(%rbp),%rsi
mov    %eax,%edx
lea    0xe48(%rip),%rdi
call   1060 <printf@plt>
mov    -0x98(%rbp),%rdi
lea    0xe31(%rip),%rsi
lea    0xe35(%rip),%rdx
call   1040 <replaceStr@plt>
mov    -0x98(%rbp),%rax
mov    %rax,-0xa0(%rbp)
mov    -0x98(%rbp),%rdi
call   1030 <len@plt>
mov    -0xa0(%rbp),%rsi
mov    %eax,%edx
lea    0xdff(%rip),%rdi
call   1060 <printf@plt>
xor    %eax,%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x80,%rsp
lea    0xe9d(%rip),%rdi
call   1050 <puts@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1070 <gets@plt>
lea    0xe94(%rip),%rsi
lea    0xe8f(%rip),%r14
mov    %rbx,%rdi
mov    %r14,%rdx
call   1040 <replaceStr@plt>
mov    %rbx,%rdi
call   1030 <len@plt>
lea    0xe79(%rip),%r15
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1060 <printf@plt>
lea    0xe6c(%rip),%rdx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <replaceStr@plt>
mov    %rbx,%rdi
call   1030 <len@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [14 x i8] c"Input string:\00"
@.str.1 = [2 x i8] c" \00"
@.str.2 = [4 x i8] c"%20\00"
@.str.3 = [7 x i8] c"%s %d\0A\00"
@.str.4 = [2 x i8] c"_\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [128 x i8]
%3 = alloca i8*
store i32 0, i32* %1
%4 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
store i8* %4, i8** %3
%5 = call i32 @puts(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%6 = load i8*, i8** %3
%7 = call i32 @gets(i8* %6)
%8 = load i8*, i8** %3
%9 = call i32 @replaceStr(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%10 = load i8*, i8** %3
%11 = load i8*, i8** %3
%12 = call i32 @len(i8* %11)
%13 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* %10, i32 %12)
%14 = load i8*, i8** %3
%15 = call i32 @replaceStr(i8* %14, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%16 = load i8*, i8** %3
%17 = load i8*, i8** %3
%18 = call i32 @len(i8* %17)
%19 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* %16, i32 %18)
ret i32 0
}

LLVM IR (-O2):
@.str = [14 x i8] c"Input string:\00"
@.str.1 = [2 x i8] c" \00"
@.str.2 = [4 x i8] c"%20\00"
@.str.3 = [7 x i8] c"%s %d\0A\00"
@.str.4 = [2 x i8] c"_\00"
define i32 @main() {
%1 = alloca [128 x i8]
%2 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @gets(i8* %2)
%5 = call i32 @replaceStr(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%6 = call i32 @len(i8* %2)
%7 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* %2, i32 %6)
%8 = call i32 @replaceStr(i8* %2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%9 = call i32 @len(i8* %2)
%10 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* %2, i32 %9)
ret i32 0
}