#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__ calloc(scalar_t__, int);
int /*<<< orphan*/ free(char *);
char *pl_cpy(char *, char *);
int /*<<< orphan*/ printf(char *, char *);
scalar_t__ strlen(char *);
int main() {
  char the_string[] = "This is a short string.";
  char *copied_str, *pre_alloc;
  copied_str = pl_cpy(the_string, NULL);
  if (copied_str != NULL) {
    printf("copied_str: %s\n", copied_str);
  }
  pre_alloc = (char *)calloc(strlen(the_string) + 1, sizeof(char));
  if (pre_alloc == NULL) {
    return 0;
  }
  if (pl_cpy(the_string, pre_alloc) != NULL) {
    printf("pre_alloc: %s\n", pre_alloc);
  }
  free(copied_str);
  free(pre_alloc);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xe9a(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xe97(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xe94(%rip),%rax
mov    %rax,-0x10(%rbp)
lea    -0x20(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1070 <pl_cpy@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11ac <main+0x5c>
mov    -0x28(%rbp),%rsi
lea    0xe71(%rip),%rdi
call   1050 <printf@plt>
lea    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11e1 <main+0x91>
movl   $0x0,-0x4(%rbp)
jmp    1221 <main+0xd1>
lea    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1070 <pl_cpy@plt>
cmp    $0x0,%rax
je     1208 <main+0xb8>
mov    -0x30(%rbp),%rsi
lea    0xe25(%rip),%rdi
call   1050 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
movaps 0xea2(%rip),%xmm0
movaps %xmm0,(%rsp)
movabs $0x2e676e69727473,%rax
mov    %rax,0x10(%rsp)
mov    %rsp,%rdi
xor    %esi,%esi
call   1070 <pl_cpy@plt>
mov    %rax,%r14
test   %rax,%rax
je     1192 <main+0x42>
lea    0xe8e(%rip),%rdi
mov    %r14,%rsi
call   1050 <printf@plt>
mov    %rsp,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%rdi
mov    $0x1,%esi
call   1060 <calloc@plt>
test   %rax,%rax
je     11df <main+0x8f>
mov    %rax,%rbx
mov    %rsp,%rdi
mov    %rax,%rsi
call   1070 <pl_cpy@plt>
test   %rax,%rax
je     11cf <main+0x7f>
lea    0xe61(%rip),%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.main.the_string = [24 x i8] c"This is a short string.\00"
@.str = [16 x i8] c"copied_str: %s\0A\00"
@.str.1 = [15 x i8] c"pre_alloc: %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [24 x i8]
%3 = alloca i8*
%4 = alloca i8*
store i32 0, i32* %1
%5 = bitcast [24 x i8]* %2 to i8*
%6 = getelementptr inbounds [24 x i8], [24 x i8]* %2, i64 0, i64 0
%7 = call i8* @pl_cpy(i8* %6, i8* null)
store i8* %7, i8** %3
%8 = load i8*, i8** %3
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %13
10: ; preds = %0
%11 = load i8*, i8** %3
%12 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %11)
br label %13
13: ; preds = %10, %0
%14 = getelementptr inbounds [24 x i8], [24 x i8]* %2, i64 0, i64 0
%15 = call i64 @strlen(i8* %14)
%16 = add nsw i64 %15, 1
%17 = call i64 @calloc(i64 %16, i32 1)
%18 = inttoptr i64 %17 to i8*
store i8* %18, i8** %4
%19 = load i8*, i8** %4
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %22
21: ; preds = %13
store i32 0, i32* %1
br label %35
22: ; preds = %13
%23 = getelementptr inbounds [24 x i8], [24 x i8]* %2, i64 0, i64 0
%24 = load i8*, i8** %4
%25 = call i8* @pl_cpy(i8* %23, i8* %24)
%26 = icmp ne i8* %25, null
br i1 %26, label %27, label %30
27: ; preds = %22
%28 = load i8*, i8** %4
%29 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %28)
br label %30
30: ; preds = %27, %22
%31 = load i8*, i8** %3
%32 = call i32 @free(i8* %31)
%33 = load i8*, i8** %4
%34 = call i32 @free(i8* %33)
store i32 0, i32* %1
br label %35
35: ; preds = %30, %21
%36 = load i32, i32* %1
ret i32 %36
}

LLVM IR (-O2):
@__const.main.the_string = [24 x i8] c"This is a short string.\00"
@.str = [16 x i8] c"copied_str: %s\0A\00"
@.str.1 = [15 x i8] c"pre_alloc: %s\0A\00"
define i32 @main() {
%1 = alloca [24 x i8]
%2 = getelementptr inbounds [24 x i8], [24 x i8]* %1, i64 0, i64 0
%3 = call i8* @pl_cpy(i8* %2, i8* null)
%4 = icmp eq i8* %3, null
br i1 %4, label %7, label %5
5: ; preds = %0
%6 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %3)
br label %7
7: ; preds = %5, %0
%8 = call i64 @strlen(i8* %2)
%9 = add nsw i64 %8, 1
%10 = call i64 @calloc(i64 %9, i32 1)
%11 = inttoptr i64 %10 to i8*
%12 = icmp eq i64 %10, 0
br i1 %12, label %21, label %13
13: ; preds = %7
%14 = call i8* @pl_cpy(i8* %2, i8* %11)
%15 = icmp eq i8* %14, null
br i1 %15, label %18, label %16
16: ; preds = %13
%17 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %11)
br label %18
18: ; preds = %16, %13
%19 = call i32 @free(i8* %3)
%20 = call i32 @free(i8* %11)
br label %21
21: ; preds = %7, %18
ret i32 0
}