#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*/ strcpy(char *, char *);
int strlen(char *);
char *StrUtil_copyString(char **to, char *from, int Start) {
  char *cp;
  int Len;
  if ((Len = strlen(from)) - 1 < Start) {
    if ((*to = (char *)calloc(1, sizeof(char))) == NULL) {
      Error_write(12, "StrUtil_copyString", 2, "to");
      return NULL;
    }
    (*to)[0] = '\0';
  } else {
    Len -= Start;
    cp = &from[Start];
    if ((*to = (char *)calloc(Len + 3, sizeof(char))) == NULL) {
      Error_write(12, "StrUtil_copyString", 2, "to");
      return NULL;
    }
    strcpy(*to, cp);
  }
  return *to;
}


x86 assembly (clang, -O0):
<StrUtil_copyString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x2c(%rbp)
sub    $0x1,%eax
cmp    -0x1c(%rbp),%eax
jge    11c1 <StrUtil_copyString+0x81>
mov    $0x1,%esi
mov    %esi,%edi
call   1060 <calloc@plt>
mov    -0x10(%rbp),%rcx
mov    %rax,(%rcx)
cmp    $0x0,%rax
jne    11b2 <StrUtil_copyString+0x72>
mov    $0xc,%edi
lea    0xe6c(%rip),%rsi
mov    $0x2,%edx
lea    0xe73(%rip),%rcx
call   1050 <Error_write@plt>
movq   $0x0,-0x8(%rbp)
jmp    1241 <StrUtil_copyString+0x101>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movb   $0x0,(%rax)
jmp    1236 <StrUtil_copyString+0xf6>
mov    -0x1c(%rbp),%ecx
mov    -0x2c(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x2c(%rbp),%edi
add    $0x3,%edi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    -0x10(%rbp),%rcx
mov    %rax,(%rcx)
cmp    $0x0,%rax
jne    1226 <StrUtil_copyString+0xe6>
mov    $0xc,%edi
lea    0xdf8(%rip),%rsi
mov    $0x2,%edx
lea    0xdff(%rip),%rcx
call   1050 <Error_write@plt>
movq   $0x0,-0x8(%rbp)
jmp    1241 <StrUtil_copyString+0x101>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x28(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<StrUtil_copyString>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebp
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
call   1040 <strlen@plt>
sub    %ebp,%eax
jle    1182 <StrUtil_copyString+0x42>
add    $0x3,%eax
mov    %eax,%edi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,(%r14)
test   %rax,%rax
je     11a1 <StrUtil_copyString+0x61>
movslq %ebp,%rcx
add    %rcx,%rbx
mov    %rax,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
jmp    119c <StrUtil_copyString+0x5c>
mov    $0x1,%edi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,(%r14)
test   %rax,%rax
je     11a1 <StrUtil_copyString+0x61>
movb   $0x0,(%rax)
mov    (%r14),%rax
jmp    11c0 <StrUtil_copyString+0x80>
lea    0xe58(%rip),%rsi
lea    0xe64(%rip),%rcx
mov    $0xc,%edi
mov    $0x2,%edx
call   1050 <Error_write@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [19 x i8] c"StrUtil_copyString\00"
@.str.1 = [3 x i8] c"to\00"
define i8* @StrUtil_copyString(i8** %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
store i8** %0, i8*** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%10 = load i8*, i8** %6
%11 = call i32 @strlen(i8* %10)
store i32 %11, i32* %9
%12 = sub nsw i32 %11, 1
%13 = load i32, i32* %7
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %26
15: ; preds = %3
%16 = call i64 @calloc(i32 1, i32 1)
%17 = inttoptr i64 %16 to i8*
%18 = load i8**, i8*** %5
store i8* %17, i8** %18
%19 = icmp eq i8* %17, null
br i1 %19, label %20, label %22
20: ; preds = %15
%21 = call i32 @Error_write(i32 12, i8* getelementptr inbounds ([19 x i8], [19 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 %50
22: ; preds = %15
%23 = load i8**, i8*** %5
%24 = load i8*, i8** %23
%25 = getelementptr inbounds i8, i8* %24, i64 0
store i8 0, i8* %25
br label %47
26: ; preds = %3
%27 = load i32, i32* %7
%28 = load i32, i32* %9
%29 = sub nsw i32 %28, %27
store i32 %29, i32* %9
%30 = load i8*, i8** %6
%31 = load i32, i32* %7
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %30, i64 %32
store i8* %33, i8** %8
%34 = load i32, i32* %9
%35 = add nsw i32 %34, 3
%36 = call i64 @calloc(i32 %35, i32 1)
%37 = inttoptr i64 %36 to i8*
%38 = load i8**, i8*** %5
store i8* %37, i8** %38
%39 = icmp eq i8* %37, null
br i1 %39, label %40, label %42
40: ; preds = %26
%41 = call i32 @Error_write(i32 12, i8* getelementptr inbounds ([19 x i8], [19 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 %50
42: ; preds = %26
%43 = load i8**, i8*** %5
%44 = load i8*, i8** %43
%45 = load i8*, i8** %8
%46 = call i32 @strcpy(i8* %44, i8* %45)
br label %47
47: ; preds = %42, %22
%48 = load i8**, i8*** %5
%49 = load i8*, i8** %48
store i8* %49, i8** %4
br label %50
50: ; preds = %47, %40, %20
%51 = load i8*, i8** %4
ret i8* %51
}

LLVM IR (-O2):
@.str = [19 x i8] c"StrUtil_copyString\00"
@.str.1 = [3 x i8] c"to\00"
define i8* @StrUtil_copyString(i8** nocapture %0, i8* %1, i32 %2) {
%4 = tail call i32 @strlen(i8* %1)
%5 = icmp sgt i32 %4, %2
br i1 %5, label %13, label %6
6: ; preds = %3
%7 = tail call i64 @calloc(i32 1, i32 1)
%8 = inttoptr i64 %7 to i8*
store i8* %8, i8** %0
%9 = icmp eq i64 %7, 0
br i1 %9, label %10, label %12
10: ; preds = %6
%11 = tail call i32 @Error_write(i32 12, i8* getelementptr inbounds ([19 x i8], [19 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 %27
12: ; preds = %6
store i8 0, i8* %8
br label %25
13: ; preds = %3
%14 = sub i32 3, %2
%15 = add i32 %14, %4
%16 = tail call i64 @calloc(i32 %15, i32 1)
%17 = inttoptr i64 %16 to i8*
store i8* %17, i8** %0
%18 = icmp eq i64 %16, 0
br i1 %18, label %19, label %21
19: ; preds = %13
%20 = tail call i32 @Error_write(i32 12, i8* getelementptr inbounds ([19 x i8], [19 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 %27
21: ; preds = %13
%22 = sext i32 %2 to i64
%23 = getelementptr inbounds i8, i8* %1, i64 %22
%24 = tail call i32 @strcpy(i8* %17, i8* %23)
br label %25
25: ; preds = %21, %12
%26 = load i8*, i8** %0
br label %27
27: ; preds = %25, %19, %10
%28 = phi i8* [ null, %10 ], [ %26, %25 ], [ null, %19 ]
ret i8* %28
}