#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*/ fatal(char const *, char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ strcpy(char *, char const *);
int strlen(char const *);
char *astrcpy(const char *src) {
  static const char fnName[] __attribute__((unused)) = "astrcpy()";
  char *inputCopy = NULL;
  if ((inputCopy = (char *)malloc((strlen(src) + 1) * sizeof(char))) == NULL) {
    fatal(fnName, "Out of memory!");
  } else {
    strcpy(inputCopy, src);
  }
  return inputCopy;
}


x86 assembly (clang, -O0):
<astrcpy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    1193 <astrcpy+0x53>
lea    0xe7e(%rip),%rdi
lea    0xe81(%rip),%rsi
call   1060 <fatal@plt>
jmp    11a0 <astrcpy+0x60>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<astrcpy>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1040 <strlen@plt>
lea    0x1(%rax),%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1169 <astrcpy+0x29>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
jmp    117c <astrcpy+0x3c>
lea    0xe90(%rip),%rdi
lea    0xe93(%rip),%rsi
call   1060 <fatal@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@astrcpy.fnName = internal constant [10 x i8] c"astrcpy()\00"
@.str = [15 x i8] c"Out of memory!\00"
define i8* @astrcpy(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
store i8* %0, i8** %2
store i8* null, i8** %3
%4 = load i8*, i8** %2
%5 = call i32 @strlen(i8* %4)
%6 = add nsw i32 %5, 1
%7 = sext i32 %6 to i64
%8 = mul i64 %7, 1
%9 = trunc i64 %8 to i32
%10 = call i64 @malloc(i32 %9)
%11 = inttoptr i64 %10 to i8*
store i8* %11, i8** %3
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %15
13: ; preds = %1
%14 = call i32 @fatal(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @astrcpy.fnName, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %19
15: ; preds = %1
%16 = load i8*, i8** %3
%17 = load i8*, i8** %2
%18 = call i32 @strcpy(i8* %16, i8* %17)
br label %19
19: ; preds = %15, %13
%20 = load i8*, i8** %3
ret i8* %20
}

LLVM IR (-O2):
@astrcpy.fnName = internal constant [10 x i8] c"astrcpy()\00"
@.str = [15 x i8] c"Out of memory!\00"
define i8* @astrcpy(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = add nsw i32 %2, 1
%4 = tail call i64 @malloc(i32 %3)
%5 = inttoptr i64 %4 to i8*
%6 = icmp eq i64 %4, 0
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = tail call i32 @fatal(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @astrcpy.fnName, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %11
9: ; preds = %1
%10 = tail call i32 @strcpy(i8* %5, i8* %0)
br label %11
11: ; preds = %9, %7
ret i8* %5
}