#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 */
typedef int /*<<< orphan*/ cpArray;

/* Variables and functions */
int /*<<< orphan*/ free(char *);
int iFunStrlen(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
int main(int argc, char **argv) {
  char cArray[] = "good morning";
  char *cpArray = NULL;
  int iCount = iFunStrlen(cArray);
  printf("The string is %s\n", cArray);
  printf("String iArray lenght is %d\n", iCount);
  printf("Now I want to test the string copy\n");
  cpArray = (char *)malloc(iCount);
  strcpy(cpArray, cArray);
  printf("Now I change the first element , g -> a in the string\n");
  cArray[0] = 'a';
  if (strcmp(cArray, cpArray) != 0) {
    printf("cArray has been changed, now there is :\n%s\n", cArray);
  }
  printf("Before free, cpArray length is %d\n", (int)strlen(cpArray));
  free(cpArray);
  printf("After free, the cpArray length is %d\n", (int)strlen(cpArray));
  if (sizeof(cpArray) != 0) {
    printf("cpArray size is %ld\n", sizeof(cpArray));
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xe73(%rip),%rax
mov    %rax,-0x1d(%rbp)
mov    0xe71(%rip),%eax
mov    %eax,-0x15(%rbp)
mov    0xe6c(%rip),%al
mov    %al,-0x11(%rbp)
movq   $0x0,-0x28(%rbp)
lea    -0x1d(%rbp),%rdi
call   1080 <iFunStrlen@plt>
mov    %eax,-0x2c(%rbp)
lea    -0x1d(%rbp),%rsi
lea    0xe4b(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x2c(%rbp),%esi
lea    0xe4c(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xe5a(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x2c(%rbp),%edi
call   1090 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
lea    -0x1d(%rbp),%rsi
call   1040 <strcpy@plt>
lea    0xe57(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movb   $0x61,-0x1d(%rbp)
lea    -0x1d(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     123c <main+0xcc>
lea    -0x1d(%rbp),%rsi
lea    0xe61(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%esi
lea    0xe74(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%esi
lea    0xe75(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xe8d(%rip),%rdi
mov    $0x8,%esi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
movabs $0x676e696e726f6d,%rax
mov    %rax,0xd(%rsp)
movabs $0x726f6d20646f6f67,%rax
6d 6f 72
mov    %rax,0x8(%rsp)
lea    0x8(%rsp),%r14
mov    %r14,%rdi
call   1090 <iFunStrlen@plt>
mov    %eax,%ebx
lea    0xe52(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xe53(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xee9(%rip),%rdi
call   1050 <puts@plt>
mov    %ebx,%edi
call   10a0 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1040 <strcpy@plt>
lea    0xeeb(%rip),%rdi
call   1050 <puts@plt>
movb   $0x61,0x8(%rsp)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
je     122a <main+0xaa>
lea    0xe1d(%rip),%rdi
lea    0x8(%rsp),%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
call   1060 <strlen@plt>
lea    0xe2e(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1060 <strlen@plt>
lea    0xe31(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xe47(%rip),%rdi
mov    $0x8,%esi
xor    %eax,%eax
call   1070 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.main.cArray = [13 x i8] c"good morning\00"
@.str = [18 x i8] c"The string is %s\0A\00"
@.str.1 = [28 x i8] c"String iArray lenght is %d\0A\00"
@.str.2 = [36 x i8] c"Now I want to test the string copy\0A\00"
@.str.3 = [55 x i8] c"Now I change the first element , g -> a in the string\0A\00"
@.str.4 = [44 x i8] c"cArray has been changed, now there is :\0A%s\0A\00"
@.str.5 = [35 x i8] c"Before free, cpArray length is %d\0A\00"
@.str.6 = [38 x i8] c"After free, the cpArray length is %d\0A\00"
@.str.7 = [21 x i8] c"cpArray size is %ld\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [13 x i8]
%7 = alloca i8*
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = bitcast [13 x i8]* %6 to i8*
store i8* null, i8** %7
%10 = getelementptr inbounds [13 x i8], [13 x i8]* %6, i64 0, i64 0
%11 = call i32 @iFunStrlen(i8* %10)
store i32 %11, i32* %8
%12 = getelementptr inbounds [13 x i8], [13 x i8]* %6, i64 0, i64 0
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %12)
%14 = load i32, i32* %8
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %14)
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
%17 = load i32, i32* %8
%18 = call i64 @malloc(i32 %17)
%19 = inttoptr i64 %18 to i8*
store i8* %19, i8** %7
%20 = load i8*, i8** %7
%21 = getelementptr inbounds [13 x i8], [13 x i8]* %6, i64 0, i64 0
%22 = call i32 @strcpy(i8* %20, i8* %21)
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.3, i64 0, i64 0))
%24 = getelementptr inbounds [13 x i8], [13 x i8]* %6, i64 0, i64 0
store i8 97, i8* %24
%25 = getelementptr inbounds [13 x i8], [13 x i8]* %6, i64 0, i64 0
%26 = load i8*, i8** %7
%27 = call i64 @strcmp(i8* %25, i8* %26)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %2
%30 = getelementptr inbounds [13 x i8], [13 x i8]* %6, i64 0, i64 0
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.4, i64 0, i64 0), i8* %30)
br label %32
32: ; preds = %29, %2
%33 = load i8*, i8** %7
%34 = call i64 @strlen(i8* %33)
%35 = trunc i64 %34 to i32
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0), i32 %35)
%37 = load i8*, i8** %7
%38 = call i32 @free(i8* %37)
%39 = load i8*, i8** %7
%40 = call i64 @strlen(i8* %39)
%41 = trunc i64 %40 to i32
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.6, i64 0, i64 0), i32 %41)
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.7, i64 0, i64 0), i64 8)
ret i32 0
}

LLVM IR (-O2):
@__const.main.cArray = [13 x i8] c"good morning\00"
@.str = [18 x i8] c"The string is %s\0A\00"
@.str.1 = [28 x i8] c"String iArray lenght is %d\0A\00"
@.str.4 = [44 x i8] c"cArray has been changed, now there is :\0A%s\0A\00"
@.str.5 = [35 x i8] c"Before free, cpArray length is %d\0A\00"
@.str.6 = [38 x i8] c"After free, the cpArray length is %d\0A\00"
@.str.7 = [21 x i8] c"cpArray size is %ld\0A\00"
@str = [35 x i8] c"Now I want to test the string copy\00"
@str.8 = [54 x i8] c"Now I change the first element , g -> a in the string\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [13 x i8]
%4 = getelementptr inbounds [13 x i8], [13 x i8]* %3, i64 0, i64 0
%5 = call i32 @iFunStrlen(i8* %4)
%6 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %4)
%7 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %5)
%8 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str, i64 0, i64 0))
%9 = call i64 @malloc(i32 %5)
%10 = inttoptr i64 %9 to i8*
%11 = call i32 @strcpy(i8* %10, i8* %4)
%12 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([54 x i8], [54 x i8]* @str.8, i64 0, i64 0))
store i8 97, i8* %4
%13 = call i64 @strcmp(i8* %4, i8* %10)
%14 = icmp eq i64 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %2
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.4, i64 0, i64 0), i8* %4)
br label %17
17: ; preds = %15, %2
%18 = call i64 @strlen(i8* dereferenceable(1) %10)
%19 = trunc i64 %18 to i32
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0), i32 %19)
%21 = call i32 @free(i8* %10)
%22 = call i64 @strlen(i8* dereferenceable(1) %10)
%23 = trunc i64 %22 to i32
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.6, i64 0, i64 0), i32 %23)
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.7, i64 0, i64 0), i64 8)
ret i32 0
}