#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(scalar_t__, int);
int /*<<< orphan*/ fatal(char *, char *);
scalar_t__ strlen(char *);
char *copys(char *s) {
  register char *t, *t0;
  if ((t0 = t = calloc(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>
mov    %rax,%rdi
add    $0x1,%rdi
mov    $0x1,%esi
call   1040 <calloc@plt>
mov    %rax,-0x10(%rbp)
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1178 <copys+0x48>
lea    0xe91(%rip),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <fatal@plt>
jmp    117d <copys+0x4d>
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     11ac <copys+0x7c>
jmp    117d <copys+0x4d>
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),%rdi
mov    $0x1,%esi
call   1040 <calloc@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1160 <copys+0x30>
lea    0xea7(%rip),%rdi
xor    %esi,%esi
call   1050 <fatal@plt>
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
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 = call i8* @calloc(i64 %7, i32 1)
store i8* %8, i8** %3
store i8* %8, i8** %4
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %12
10: ; preds = %1
%11 = call i32 @fatal(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* null)
br label %12
12: ; preds = %10, %1
br label %13
13: ; preds = %20, %12
%14 = load i8*, i8** %2
%15 = getelementptr inbounds i8, i8* %14, i32 1
store i8* %15, i8** %2
%16 = load i8, i8* %14
%17 = load i8*, i8** %3
%18 = getelementptr inbounds i8, i8* %17, i32 1
store i8* %18, i8** %3
store i8 %16, i8* %17
%19 = icmp ne i8 %16, 0
br i1 %19, label %20, label %21
20: ; preds = %13
br label %13
21: ; preds = %13
%22 = load i8*, i8** %4
ret i8* %22
}

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