#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 */
char *calloc(unsigned int, int);
int /*<<< orphan*/ fatal(char *, char *);
scalar_t__ strlen(char *);
char *copys(char *s) {
  register char *t, *t0;
  if ((t0 = t = calloc((unsigned)(strlen(s) + 1), sizeof(*t))) == NULL)
    fatal("Cannot allocate memory", (char *)NULL);
  while ((*t++ = *s++))
    ;
  return (t0);
}


x86 assembly (clang, -O0):
<copys>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
add    $0x1,%rax
mov    %eax,%edi
mov    $0x1,%esi
call   1040 <calloc@plt>
mov    %rax,-0x10(%rbp)
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1177 <copys+0x47>
lea    0xe92(%rip),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <fatal@plt>
jmp    117c <copys+0x4c>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%al
mov    -0x10(%rbp),%rcx
mov    %rcx,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %al,(%rcx)
cmp    $0x0,%al
je     11ab <copys+0x7b>
jmp    117c <copys+0x4c>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<copys>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1030 <strlen@plt>
lea    0x1(%rax),%edi
mov    $0x1,%esi
call   1040 <calloc@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    115f <copys+0x2f>
lea    0xea8(%rip),%rdi
xor    %esi,%esi
call   1050 <fatal@plt>
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movzbl (%r14,%rax,1),%ecx
mov    %cl,(%rbx,%rax,1)
add    $0x1,%rax
test   %cl,%cl
jne    1170 <copys+0x40>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [23 x i8] c"Cannot allocate memory\00"
define i8* @copys(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i64 @strlen(i8* %5)
%7 = add nsw i64 %6, 1
%8 = trunc i64 %7 to i32
%9 = call i8* @calloc(i32 %8, i32 1)
store i8* %9, i8** %3
store i8* %9, i8** %4
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %13
11: ; preds = %1
%12 = call i32 @fatal(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* null)
br label %13
13: ; preds = %11, %1
br label %14
14: ; preds = %21, %13
%15 = load i8*, i8** %2
%16 = getelementptr inbounds i8, i8* %15, i32 1
store i8* %16, i8** %2
%17 = load i8, i8* %15
%18 = load i8*, i8** %3
%19 = getelementptr inbounds i8, i8* %18, i32 1
store i8* %19, i8** %3
store i8 %17, i8* %18
%20 = icmp ne i8 %17, 0
br i1 %20, label %21, label %22
21: ; preds = %14
br label %14
22: ; preds = %14
%23 = load i8*, i8** %4
ret i8* %23
}

LLVM IR (-O2):
@.str = [23 x i8] c"Cannot allocate memory\00"
define noalias i8* @copys(i8* nocapture %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = trunc i64 %2 to i32
%4 = add i32 %3, 1
%5 = tail call i8* @calloc(i32 %4, i32 1)
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = tail call i32 @fatal(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* null)
br label %9
9: ; preds = %7, %1
br label %10
10: ; preds = %9, %10
%11 = phi i8* [ %15, %10 ], [ %5, %9 ]
%12 = phi i8* [ %13, %10 ], [ %0, %9 ]
%13 = getelementptr inbounds i8, i8* %12, i64 1
%14 = load i8, i8* %12
%15 = getelementptr inbounds i8, i8* %11, i64 1
store i8 %14, i8* %11
%16 = icmp eq i8 %14, 0
br i1 %16, label %17, label %10
17: ; preds = %10
ret i8* %5
}