#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 *);
int StrUtil_rmEndSpaces(char *);
scalar_t__ calloc(int, int);
scalar_t__ realloc(char *, int);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *StrUtil_copyTString(char **to, char *from, int Start) {
  int lenTo;
  int lenFrom = strlen(from);
  if (lenFrom - 1 < Start) {
    if ((*to = (char *)calloc(1, sizeof(char))) == NULL) {
      Error_write(13, "StrUtil_copyTString", 2, "to");
      return NULL;
    }
    (*to)[0] = '\0';
  } else {
    if ((*to = (char *)calloc(lenFrom + 1, sizeof(char))) == NULL) {
      Error_write(13, "StrUtil_copyTString", 2, "*to");
      return NULL;
    }
    strcpy(*to, &(from[Start]));
    lenTo = StrUtil_rmEndSpaces(*to);
    if ((*to = (char *)realloc(*to, (lenTo + 1) * sizeof(char))) == NULL) {
      Error_write(15, "StrUtil_copyTString", 2, "to");
      return NULL;
    }
  }
  return *to;
}


x86 assembly (clang, -O0):
<StrUtil_copyTString>:
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   1050 <strlen@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
sub    $0x1,%eax
cmp    -0x1c(%rbp),%eax
jge    11e4 <StrUtil_copyTString+0x84>
mov    $0x1,%esi
mov    %esi,%edi
call   1070 <calloc@plt>
mov    -0x10(%rbp),%rcx
mov    %rax,(%rcx)
cmp    $0x0,%rax
jne    11d5 <StrUtil_copyTString+0x75>
mov    $0xd,%edi
lea    0xe49(%rip),%rsi
mov    $0x2,%edx
lea    0xe52(%rip),%rcx
call   1060 <Error_write@plt>
movq   $0x0,-0x8(%rbp)
jmp    12ba <StrUtil_copyTString+0x15a>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movb   $0x0,(%rax)
jmp    12af <StrUtil_copyTString+0x14f>
mov    -0x24(%rbp),%edi
add    $0x1,%edi
mov    $0x1,%esi
call   1070 <calloc@plt>
mov    -0x10(%rbp),%rcx
mov    %rax,(%rcx)
cmp    $0x0,%rax
jne    122f <StrUtil_copyTString+0xcf>
mov    $0xd,%edi
lea    0xdef(%rip),%rsi
mov    $0x2,%edx
lea    0xdf7(%rip),%rcx
call   1060 <Error_write@plt>
movq   $0x0,-0x8(%rbp)
jmp    12ba <StrUtil_copyTString+0x15a>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x18(%rbp),%rsi
movslq -0x1c(%rbp),%rax
add    %rax,%rsi
call   1040 <strcpy@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1030 <StrUtil_rmEndSpaces@plt>
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x20(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%esi
call   1080 <realloc@plt>
mov    -0x10(%rbp),%rcx
mov    %rax,(%rcx)
cmp    $0x0,%rax
jne    12aa <StrUtil_copyTString+0x14a>
mov    $0xf,%edi
lea    0xd74(%rip),%rsi
mov    $0x2,%edx
lea    0xd7d(%rip),%rcx
call   1060 <Error_write@plt>
movq   $0x0,-0x8(%rbp)
jmp    12ba <StrUtil_copyTString+0x15a>
jmp    12af <StrUtil_copyTString+0x14f>
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_copyTString>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebp
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
call   1050 <strlen@plt>
cmp    %ebp,%eax
jle    11d0 <StrUtil_copyTString+0x70>
add    $0x1,%eax
mov    %eax,%edi
mov    $0x1,%esi
call   1070 <calloc@plt>
mov    %rax,(%r14)
test   %rax,%rax
je     11ef <StrUtil_copyTString+0x8f>
movslq %ebp,%rcx
add    %rcx,%rbx
mov    %rax,%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
mov    (%r14),%rdi
call   1030 <StrUtil_rmEndSpaces@plt>
mov    (%r14),%rdi
lea    0x1(%rax),%esi
call   1080 <realloc@plt>
mov    %rax,(%r14)
test   %rax,%rax
jne    121e <StrUtil_copyTString+0xbe>
lea    0xe3e(%rip),%rsi
lea    0xe4c(%rip),%rcx
mov    $0xf,%edi
jmp    1212 <StrUtil_copyTString+0xb2>
mov    $0x1,%edi
mov    $0x1,%esi
call   1070 <calloc@plt>
mov    %rax,(%r14)
test   %rax,%rax
je     11ff <StrUtil_copyTString+0x9f>
movb   $0x0,(%rax)
mov    (%r14),%rax
jmp    121e <StrUtil_copyTString+0xbe>
lea    0xe0a(%rip),%rsi
lea    0xe17(%rip),%rcx
jmp    120d <StrUtil_copyTString+0xad>
lea    0xdfa(%rip),%rsi
lea    0xe08(%rip),%rcx
mov    $0xd,%edi
mov    $0x2,%edx
call   1060 <Error_write@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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