#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*/ assert_equal_str(char *, char *, char *, char *);
scalar_t__ calloc(scalar_t__, int);
int /*<<< orphan*/ free(char *);
char *pl_cpy(char *, char *);
scalar_t__ strlen(char *);
void test_strcpy_pre_alloc() {
  char the_string[] = "spam, eggs, and ham";
  char *ret_val;
  ret_val = (char *)calloc(strlen(the_string) + 1, sizeof(char));
  ret_val = pl_cpy(the_string, ret_val);
  assert_equal_str("spam, eggs, and ham", ret_val, "test_strcpy_pre_alloc",
                   "The strings are not equal.");
  free(ret_val);
}


x86 assembly (clang, -O0):
<test_strcpy_pre_alloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    0xea1(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xe9e(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xe9c(%rip),%eax
mov    %eax,-0x10(%rbp)
lea    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,-0x28(%rbp)
lea    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1070 <pl_cpy@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rsi
lea    0xe63(%rip),%rdi
lea    0xe70(%rip),%rdx
lea    0xe7f(%rip),%rcx
call   1040 <assert_equal_str@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_strcpy_pre_alloc>:
push   %r14
push   %rbx
sub    $0x18,%rsp
movaps 0xea2(%rip),%xmm0
movaps %xmm0,(%rsp)
movl   $0x6d6168,0x10(%rsp)
lea    0xe8f(%rip),%r14
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%rdi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
call   1070 <pl_cpy@plt>
mov    %rax,%rbx
lea    0xe75(%rip),%rdx
lea    0xe84(%rip),%rcx
mov    %r14,%rdi
mov    %rax,%rsi
call   1040 <assert_equal_str@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.test_strcpy_pre_alloc.the_string = [20 x i8] c"spam, eggs, and ham\00"
@.str = [20 x i8] c"spam, eggs, and ham\00"
@.str.1 = [22 x i8] c"test_strcpy_pre_alloc\00"
@.str.2 = [27 x i8] c"The strings are not equal.\00"
define void @test_strcpy_pre_alloc() {
%1 = alloca [20 x i8]
%2 = alloca i8*
%3 = bitcast [20 x i8]* %1 to i8*
%4 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 0
%5 = call i64 @strlen(i8* %4)
%6 = add nsw i64 %5, 1
%7 = call i64 @calloc(i64 %6, i32 1)
%8 = inttoptr i64 %7 to i8*
store i8* %8, i8** %2
%9 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 0
%10 = load i8*, i8** %2
%11 = call i8* @pl_cpy(i8* %9, i8* %10)
store i8* %11, i8** %2
%12 = load i8*, i8** %2
%13 = call i32 @assert_equal_str(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %12, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%14 = load i8*, i8** %2
%15 = call i32 @free(i8* %14)
ret void
}

LLVM IR (-O2):
@.str = [20 x i8] c"spam, eggs, and ham\00"
@.str.1 = [22 x i8] c"test_strcpy_pre_alloc\00"
@.str.2 = [27 x i8] c"The strings are not equal.\00"
define void @test_strcpy_pre_alloc() {
%1 = alloca [20 x i8]
%2 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 0
%3 = call i64 @strlen(i8* %2)
%4 = add nsw i64 %3, 1
%5 = tail call i64 @calloc(i64 %4, i32 1)
%6 = inttoptr i64 %5 to i8*
%7 = call i8* @pl_cpy(i8* %2, i8* %6)
%8 = call i32 @assert_equal_str(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %7, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%9 = call i32 @free(i8* %7)
ret void
}