#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 EXIT_SUCCESS;
char *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int strlen(char *);
int main(int argc, char *argv[]) {
  char *default_string = "Take a walk on the wild side";
  char *ptr = default_string;
  int defstr_size = 0;
  char *bkp_copy = NULL;
  while (*ptr++ != '\0')
    defstr_size++;
  printf("Size of the default string: %d\n", defstr_size);
  bkp_copy = malloc(defstr_size + 1);
  bkp_copy[defstr_size] = '\0';
  ptr = default_string;
  int i = 0;
  while (*ptr != '\0')
    bkp_copy[i++] = *ptr++;
  printf("Def.str: %s (%d byte)\n", default_string, strlen(default_string));
  printf("Bkp-str: %s (%d byte)\n", bkp_copy, strlen(bkp_copy));
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xeb3(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1191 <main+0x61>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1168 <main+0x38>
mov    -0x24(%rbp),%esi
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x24(%rbp),%edi
add    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
movslq -0x24(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1207 <main+0xd7>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
mov    (%rax),%dl
mov    -0x30(%rbp),%rax
mov    -0x34(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x34(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
jmp    11cc <main+0x9c>
mov    -0x18(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x48(%rbp),%rsi
mov    %eax,%edx
lea    0xe18(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x30(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x40(%rbp),%rsi
mov    %eax,%edx
lea    0xe0a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2d88(%rip),%rax
mov    (%rax),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xef2(%rip),%rdi
mov    $0x1c,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1d,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
movb   $0x0,0x1c(%rax)
movaps 0xea1(%rip),%xmm0
movups %xmm0,(%rax)
movabs $0x20646c6977206568,%rax
6c 64 20
mov    %rax,0x10(%rbx)
movl   $0x65646973,0x18(%rbx)
lea    0xe92(%rip),%r14
mov    %r14,%rdi
call   1030 <strlen@plt>
lea    0xec0(%rip),%rdi
mov    %r14,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
lea    0xebc(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2e25(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [29 x i8] c"Take a walk on the wild side\00"
@.str.1 = [32 x i8] c"Size of the default string: %d\0A\00"
@.str.2 = [23 x i8] c"Def.str: %s (%d byte)\0A\00"
@.str.3 = [23 x i8] c"Bkp-str: %s (%d byte)\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8** %6
%11 = load i8*, i8** %6
store i8* %11, i8** %7
store i32 0, i32* %8
store i8* null, i8** %9
br label %12
12: ; preds = %18, %2
%13 = load i8*, i8** %7
%14 = getelementptr inbounds i8, i8* %13, i32 1
store i8* %14, i8** %7
%15 = load i8, i8* %13
%16 = sext i8 %15 to i32
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %12
%19 = load i32, i32* %8
%20 = add nsw i32 %19, 1
store i32 %20, i32* %8
br label %12
21: ; preds = %12
%22 = load i32, i32* %8
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i32 %22)
%24 = load i32, i32* %8
%25 = add nsw i32 %24, 1
%26 = call i8* @malloc(i32 %25)
store i8* %26, i8** %9
%27 = load i8*, i8** %9
%28 = load i32, i32* %8
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
store i8 0, i8* %30
%31 = load i8*, i8** %6
store i8* %31, i8** %7
store i32 0, i32* %10
br label %32
32: ; preds = %37, %21
%33 = load i8*, i8** %7
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp ne i32 %35, 0
br i1 %36, label %37, label %46
37: ; preds = %32
%38 = load i8*, i8** %7
%39 = getelementptr inbounds i8, i8* %38, i32 1
store i8* %39, i8** %7
%40 = load i8, i8* %38
%41 = load i8*, i8** %9
%42 = load i32, i32* %10
%43 = add nsw i32 %42, 1
store i32 %43, i32* %10
%44 = sext i32 %42 to i64
%45 = getelementptr inbounds i8, i8* %41, i64 %44
store i8 %40, i8* %45
br label %32
46: ; preds = %32
%47 = load i8*, i8** %6
%48 = load i8*, i8** %6
%49 = call i32 @strlen(i8* %48)
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %47, i32 %49)
%51 = load i8*, i8** %9
%52 = load i8*, i8** %9
%53 = call i32 @strlen(i8* %52)
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i8* %51, i32 %53)
%55 = load i32, i32* @EXIT_SUCCESS
ret i32 %55
}

LLVM IR (-O2):
@.str = [29 x i8] c"Take a walk on the wild side\00"
@.str.1 = [32 x i8] c"Size of the default string: %d\0A\00"
@.str.2 = [23 x i8] c"Def.str: %s (%d byte)\0A\00"
@.str.3 = [23 x i8] c"Bkp-str: %s (%d byte)\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i32 28)
%4 = tail call dereferenceable_or_null(29) i8* @malloc(i32 29)
%5 = getelementptr inbounds i8, i8* %4, i64 28
store i8 0, i8* %5
%6 = bitcast i8* %4 to <16 x i8>*
store <16 x i8> <i8 84, i8 97, i8 107, i8 101, i8 32, i8 97, i8 32, i8 119, i8 97, i8 108, i8 107, i8 32, i8 111, i8 110, i8 32, i8 116>, <16 x i8>* %6
%7 = getelementptr inbounds i8, i8* %4, i64 16
store i8 104, i8* %7
%8 = getelementptr inbounds i8, i8* %4, i64 17
store i8 101, i8* %8
%9 = getelementptr inbounds i8, i8* %4, i64 18
store i8 32, i8* %9
%10 = getelementptr inbounds i8, i8* %4, i64 19
store i8 119, i8* %10
%11 = getelementptr inbounds i8, i8* %4, i64 20
store i8 105, i8* %11
%12 = getelementptr inbounds i8, i8* %4, i64 21
store i8 108, i8* %12
%13 = getelementptr inbounds i8, i8* %4, i64 22
store i8 100, i8* %13
%14 = getelementptr inbounds i8, i8* %4, i64 23
store i8 32, i8* %14
%15 = getelementptr inbounds i8, i8* %4, i64 24
store i8 115, i8* %15
%16 = getelementptr inbounds i8, i8* %4, i64 25
store i8 105, i8* %16
%17 = getelementptr inbounds i8, i8* %4, i64 26
store i8 100, i8* %17
%18 = getelementptr inbounds i8, i8* %4, i64 27
store i8 101, i8* %18
%19 = tail call i32 @strlen(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %19)
%21 = tail call i32 @strlen(i8* %4)
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i8* %4, i32 %21)
%23 = load i32, i32* @EXIT_SUCCESS
ret i32 %23
}