#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*/ Error_write(int, char *, int, char *);
scalar_t__ calloc(int, int);
int /*<<< orphan*/ memcpy(char *, char *, int);
char *StrUtil_fastCopyString(char **to, char *from, int length) {
  if ((*to = (char *)calloc(length + 1, sizeof(char))) == NULL) {
    Error_write(13, "StrUtil_copyLString", 2, "to");
    return NULL;
  }
  memcpy(*to, from, length + 1);
  return *to;
}


x86 assembly (clang, -O0):
<StrUtil_fastCopyString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
add    $0x1,%edi
mov    $0x1,%esi
call   1040 <calloc@plt>
mov    -0x10(%rbp),%rcx
mov    %rax,(%rcx)
cmp    $0x0,%rax
jne    118e <StrUtil_fastCopyString+0x5e>
mov    $0xd,%edi
lea    0xe90(%rip),%rsi
mov    $0x2,%edx
lea    0xe98(%rip),%rcx
call   1030 <Error_write@plt>
movq   $0x0,-0x8(%rbp)
jmp    11af <StrUtil_fastCopyString+0x7f>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
add    $0x1,%edx
call   1050 <memcpy@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<StrUtil_fastCopyString>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebp
mov    %rsi,%r14
mov    %rdi,%rbx
add    $0x1,%ebp
mov    %ebp,%edi
mov    $0x1,%esi
call   1040 <calloc@plt>
mov    %rax,(%rbx)
test   %rax,%rax
je     1165 <StrUtil_fastCopyString+0x35>
mov    %rax,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
call   1050 <memcpy@plt>
mov    (%rbx),%rax
jmp    1184 <StrUtil_fastCopyString+0x54>
lea    0xe94(%rip),%rsi
lea    0xea1(%rip),%rcx
mov    $0xd,%edi
mov    $0x2,%edx
call   1030 <Error_write@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [20 x i8] c"StrUtil_copyLString\00"
@.str.1 = [3 x i8] c"to\00"
define i8* @StrUtil_fastCopyString(i8** nocapture %0, i8* %1, i32 %2) {
%4 = add nsw i32 %2, 1
%5 = tail call i64 @calloc(i32 %4, i32 1)
%6 = inttoptr i64 %5 to i8*
store i8* %6, i8** %0
%7 = icmp eq i64 %5, 0
br i1 %7, label %8, label %10
8: ; preds = %3
%9 = tail call i32 @Error_write(i32 13, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %13
10: ; preds = %3
%11 = tail call i32 @memcpy(i8* %6, i8* %1, i32 %4)
%12 = load i8*, i8** %0
br label %13
13: ; preds = %10, %8
%14 = phi i8* [ null, %8 ], [ %12, %10 ]
ret i8* %14
}