#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__ malloc(scalar_t__);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ replace_space(char *);
scalar_t__ strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, scalar_t__);
int main() {
  char *s1 = (char *)malloc(strlen("danie l") + 1);
  strncpy(s1, "danie l", strlen("danie l") + 1);
  char *s2 = (char *)malloc(strlen("dan            i    el") + 1);
  strncpy(s2, "dan            i    el", strlen("dan            i    el") + 1);
  char *s3 = (char *)malloc(strlen(" daniel   ") + 1);
  strncpy(s3, " daniel   ", strlen(" daniel   ") + 1);
  printf("s1=%s\n", s1);
  replace_space(s1);
  printf("s1_new=%s\n", s1);
  printf("s2=%s\n", s2);
  replace_space(s2);
  printf("s2_new=%s\n", s2);
  printf("s3=%s\n", s3);
  replace_space(s3);
  printf("s3_new=%s\n", s3);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
call   1040 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1070 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
lea    0xe76(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x38(%rbp),%rdi
mov    %rax,%rdx
add    $0x1,%rdx
lea    0xe5f(%rip),%rsi
call   1030 <strncpy@plt>
lea    0xe5b(%rip),%rdi
call   1040 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
lea    0xe37(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x30(%rbp),%rdi
mov    %rax,%rdx
add    $0x1,%rdx
lea    0xe20(%rip),%rsi
call   1030 <strncpy@plt>
lea    0xe2b(%rip),%rdi
call   1040 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
lea    0xe07(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x28(%rbp),%rdi
mov    %rax,%rdx
add    $0x1,%rdx
lea    0xdf0(%rip),%rsi
call   1030 <strncpy@plt>
mov    -0x10(%rbp),%rsi
lea    0xdeb(%rip),%rdi
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1060 <replace_space@plt>
mov    -0x10(%rbp),%rsi
lea    0xdd9(%rip),%rdi
call   1050 <printf@plt>
mov    -0x18(%rbp),%rsi
lea    0xdd4(%rip),%rdi
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1060 <replace_space@plt>
mov    -0x18(%rbp),%rsi
lea    0xdc2(%rip),%rdi
call   1050 <printf@plt>
mov    -0x20(%rbp),%rsi
lea    0xdbd(%rip),%rdi
call   1050 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1060 <replace_space@plt>
mov    -0x20(%rbp),%rsi
lea    0xdab(%rip),%rdi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    $0x8,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
lea    0xea7(%rip),%rsi
mov    $0x8,%edx
mov    %rax,%rdi
call   1030 <strncpy@plt>
mov    $0x17,%edi
call   1060 <malloc@plt>
mov    %rax,%r15
lea    0xe8e(%rip),%rsi
mov    $0x17,%edx
mov    %rax,%rdi
call   1030 <strncpy@plt>
mov    $0xb,%edi
call   1060 <malloc@plt>
mov    %rax,%r14
lea    0xe84(%rip),%rsi
mov    $0xb,%edx
mov    %rax,%rdi
call   1030 <strncpy@plt>
lea    0xe7b(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1050 <replace_space@plt>
lea    0xe6b(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
lea    0xe67(%rip),%rdi
mov    %r15,%rsi
call   1040 <printf@plt>
mov    %r15,%rdi
call   1050 <replace_space@plt>
lea    0xe57(%rip),%rdi
mov    %r15,%rsi
call   1040 <printf@plt>
lea    0xe53(%rip),%rdi
mov    %r14,%rsi
call   1040 <printf@plt>
mov    %r14,%rdi
call   1050 <replace_space@plt>
lea    0xe43(%rip),%rdi
mov    %r14,%rsi
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [8 x i8] c"danie l\00"
@.str.1 = [23 x i8] c"dan i el\00"
@.str.2 = [11 x i8] c" daniel \00"
@.str.3 = [7 x i8] c"s1=%s\0A\00"
@.str.4 = [11 x i8] c"s1_new=%s\0A\00"
@.str.5 = [7 x i8] c"s2=%s\0A\00"
@.str.6 = [11 x i8] c"s2_new=%s\0A\00"
@.str.7 = [7 x i8] c"s3=%s\0A\00"
@.str.8 = [11 x i8] c"s3_new=%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i32 0, i32* %1
%5 = call i64 @strlen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%6 = add nsw i64 %5, 1
%7 = call i64 @malloc(i64 %6)
%8 = inttoptr i64 %7 to i8*
store i8* %8, i8** %2
%9 = load i8*, i8** %2
%10 = call i64 @strlen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%11 = add nsw i64 %10, 1
%12 = call i32 @strncpy(i8* %9, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i64 %11)
%13 = call i64 @strlen(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
%14 = add nsw i64 %13, 1
%15 = call i64 @malloc(i64 %14)
%16 = inttoptr i64 %15 to i8*
store i8* %16, i8** %3
%17 = load i8*, i8** %3
%18 = call i64 @strlen(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
%19 = add nsw i64 %18, 1
%20 = call i32 @strncpy(i8* %17, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i64 %19)
%21 = call i64 @strlen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%22 = add nsw i64 %21, 1
%23 = call i64 @malloc(i64 %22)
%24 = inttoptr i64 %23 to i8*
store i8* %24, i8** %4
%25 = load i8*, i8** %4
%26 = call i64 @strlen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%27 = add nsw i64 %26, 1
%28 = call i32 @strncpy(i8* %25, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i64 %27)
%29 = load i8*, i8** %2
%30 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* %29)
%31 = load i8*, i8** %2
%32 = call i32 @replace_space(i8* %31)
%33 = load i8*, i8** %2
%34 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* %33)
%35 = load i8*, i8** %3
%36 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i8* %35)
%37 = load i8*, i8** %3
%38 = call i32 @replace_space(i8* %37)
%39 = load i8*, i8** %3
%40 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i8* %39)
%41 = load i8*, i8** %4
%42 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0), i8* %41)
%43 = load i8*, i8** %4
%44 = call i32 @replace_space(i8* %43)
%45 = load i8*, i8** %4
%46 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i64 0, i64 0), i8* %45)
ret i32 0
}

LLVM IR (-O2):
@.str = [8 x i8] c"danie l\00"
@.str.1 = [23 x i8] c"dan i el\00"
@.str.2 = [11 x i8] c" daniel \00"
@.str.3 = [7 x i8] c"s1=%s\0A\00"
@.str.4 = [11 x i8] c"s1_new=%s\0A\00"
@.str.5 = [7 x i8] c"s2=%s\0A\00"
@.str.6 = [11 x i8] c"s2_new=%s\0A\00"
@.str.7 = [7 x i8] c"s3=%s\0A\00"
@.str.8 = [11 x i8] c"s3_new=%s\0A\00"
define i32 @main() {
%1 = tail call i64 @malloc(i64 8)
%2 = inttoptr i64 %1 to i8*
%3 = tail call i32 @strncpy(i8* %2, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i64 8)
%4 = tail call i64 @malloc(i64 23)
%5 = inttoptr i64 %4 to i8*
%6 = tail call i32 @strncpy(i8* %5, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i64 23)
%7 = tail call i64 @malloc(i64 11)
%8 = inttoptr i64 %7 to i8*
%9 = tail call i32 @strncpy(i8* %8, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i64 11)
%10 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* %2)
%11 = tail call i32 @replace_space(i8* %2)
%12 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* %2)
%13 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i8* %5)
%14 = tail call i32 @replace_space(i8* %5)
%15 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i8* %5)
%16 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0), i8* %8)
%17 = tail call i32 @replace_space(i8* %8)
%18 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i64 0, i64 0), i8* %8)
ret i32 0
}