#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*/ EXIT_SUCCESS;
char *astrcpy(char *);
char *astrleft(char *, int);
char *astrmid(char *, int, int);
char *astrright(char *, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  char testString[] = "This is a test";
  char *aCopy = NULL;
  char *leftBit = NULL;
  char *midBit = NULL;
  char *rightBit = NULL;
  aCopy = astrcpy(testString);
  if (aCopy != NULL) {
    leftBit = astrleft(testString, 4);
    if (leftBit != NULL) {
      printf("Left(4): \"%s\"\n", leftBit);
    } else {
      printf("Error calling astrleft()\n");
    }
    midBit = astrmid(aCopy, 2, 6);
    if (midBit != NULL) {
      printf("Mid(2, 6): \"%s\"\n", midBit);
    } else {
      printf("Error calling astrmid()\n");
    }
    rightBit = astrright(aCopy, 2);
    if (rightBit != NULL) {
      printf("Right(2): \"%s\"\n", rightBit);
    } else {
      printf("Error calling astrright()\n");
    }
  }
  if (aCopy != NULL)
    free(aCopy);
  if (leftBit != NULL)
    free(leftBit);
  if (midBit != NULL)
    free(midBit);
  if (rightBit != NULL)
    free(rightBit);
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xe73(%rip),%rax
mov    %rax,-0x1f(%rbp)
mov    0xe71(%rip),%eax
mov    %eax,-0x17(%rbp)
mov    0xe6b(%rip),%ax
mov    %ax,-0x13(%rbp)
mov    0xe63(%rip),%al
mov    %al,-0x11(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
lea    -0x1f(%rbp),%rdi
call   1060 <astrcpy@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     12b6 <main+0x146>
lea    -0x1f(%rbp),%rdi
mov    $0x4,%esi
call   1050 <astrleft@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     121a <main+0xaa>
mov    -0x30(%rbp),%rsi
lea    0xe01(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1228 <main+0xb8>
lea    0xdfd(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%rdi
mov    $0x2,%esi
mov    $0x6,%edx
call   1070 <astrmid@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     1261 <main+0xf1>
mov    -0x38(%rbp),%rsi
lea    0xde3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    126f <main+0xff>
lea    0xde1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%rdi
mov    $0x2,%esi
call   1080 <astrright@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
je     12a3 <main+0x133>
mov    -0x40(%rbp),%rsi
lea    0xdcb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12b1 <main+0x141>
lea    0xdc8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12b6 <main+0x146>
cmpq   $0x0,-0x28(%rbp)
je     12ca <main+0x15a>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x30(%rbp)
je     12de <main+0x16e>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x38(%rbp)
je     12f2 <main+0x182>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x40(%rbp)
je     1306 <main+0x196>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    0x2cd3(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
movabs $0x74736574206120,%rax
mov    %rax,0xf(%rsp)
movabs $0x2073692073696854,%rax
69 73 20
mov    %rax,0x8(%rsp)
lea    0x8(%rsp),%rdi
call   1070 <astrcpy@plt>
test   %rax,%rax
je     1281 <main+0x101>
mov    %rax,%rbx
lea    0x8(%rsp),%rdi
mov    $0x4,%esi
call   1060 <astrleft@plt>
mov    %rax,%r14
test   %rax,%rax
jne    11e4 <main+0x64>
lea    0xe62(%rip),%rdi
call   1040 <puts@plt>
jmp    11f5 <main+0x75>
lea    0xe24(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0x2,%esi
mov    $0x6,%edx
call   1080 <astrmid@plt>
mov    %rax,%r15
test   %rax,%rax
jne    121d <main+0x9d>
lea    0xe42(%rip),%rdi
call   1040 <puts@plt>
jmp    122e <main+0xae>
lea    0xdfa(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0x2,%esi
call   1090 <astrright@plt>
mov    %rax,%r12
test   %rax,%rax
jne    1251 <main+0xd1>
lea    0xe26(%rip),%rdi
call   1040 <puts@plt>
jmp    1262 <main+0xe2>
lea    0xdd7(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
test   %r14,%r14
jne    128f <main+0x10f>
test   %r15,%r15
jne    129c <main+0x11c>
test   %r12,%r12
je     1281 <main+0x101>
mov    %r12,%rdi
call   1030 <free@plt>
mov    0x2d58(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    %r14,%rdi
call   1030 <free@plt>
test   %r15,%r15
je     1274 <main+0xf4>
mov    %r15,%rdi
call   1030 <free@plt>
test   %r12,%r12
jne    1279 <main+0xf9>
jmp    1281 <main+0x101>

LLVM IR (-O0):
@__const.main.testString = [15 x i8] c"This is a test\00"
@.str = [15 x i8] c"Left(4): \22%s\22\0A\00"
@.str.1 = [26 x i8] c"Error calling astrleft()\0A\00"
@.str.2 = [17 x i8] c"Mid(2, 6): \22%s\22\0A\00"
@.str.3 = [25 x i8] c"Error calling astrmid()\0A\00"
@.str.4 = [16 x i8] c"Right(2): \22%s\22\0A\00"
@.str.5 = [27 x i8] c"Error calling astrright()\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [15 x i8]
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = bitcast [15 x i8]* %6 to i8*
store i8* null, i8** %7
store i8* null, i8** %8
store i8* null, i8** %9
store i8* null, i8** %10
%12 = getelementptr inbounds [15 x i8], [15 x i8]* %6, i64 0, i64 0
%13 = call i8* @astrcpy(i8* %12)
store i8* %13, i8** %7
%14 = load i8*, i8** %7
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %47
16: ; preds = %2
%17 = getelementptr inbounds [15 x i8], [15 x i8]* %6, i64 0, i64 0
%18 = call i8* @astrleft(i8* %17, i32 4)
store i8* %18, i8** %8
%19 = load i8*, i8** %8
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %24
21: ; preds = %16
%22 = load i8*, i8** %8
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %22)
br label %26
24: ; preds = %16
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
br label %26
26: ; preds = %24, %21
%27 = load i8*, i8** %7
%28 = call i8* @astrmid(i8* %27, i32 2, i32 6)
store i8* %28, i8** %9
%29 = load i8*, i8** %9
%30 = icmp ne i8* %29, null
br i1 %30, label %31, label %34
31: ; preds = %26
%32 = load i8*, i8** %9
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %32)
br label %36
34: ; preds = %26
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
br label %36
36: ; preds = %34, %31
%37 = load i8*, i8** %7
%38 = call i8* @astrright(i8* %37, i32 2)
store i8* %38, i8** %10
%39 = load i8*, i8** %10
%40 = icmp ne i8* %39, null
br i1 %40, label %41, label %44
41: ; preds = %36
%42 = load i8*, i8** %10
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i8* %42)
br label %46
44: ; preds = %36
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0))
br label %46
46: ; preds = %44, %41
br label %47
47: ; preds = %46, %2
%48 = load i8*, i8** %7
%49 = icmp ne i8* %48, null
br i1 %49, label %50, label %53
50: ; preds = %47
%51 = load i8*, i8** %7
%52 = call i32 @free(i8* %51)
br label %53
53: ; preds = %50, %47
%54 = load i8*, i8** %8
%55 = icmp ne i8* %54, null
br i1 %55, label %56, label %59
56: ; preds = %53
%57 = load i8*, i8** %8
%58 = call i32 @free(i8* %57)
br label %59
59: ; preds = %56, %53
%60 = load i8*, i8** %9
%61 = icmp ne i8* %60, null
br i1 %61, label %62, label %65
62: ; preds = %59
%63 = load i8*, i8** %9
%64 = call i32 @free(i8* %63)
br label %65
65: ; preds = %62, %59
%66 = load i8*, i8** %10
%67 = icmp ne i8* %66, null
br i1 %67, label %68, label %71
68: ; preds = %65
%69 = load i8*, i8** %10
%70 = call i32 @free(i8* %69)
br label %71
71: ; preds = %68, %65
%72 = load i32, i32* @EXIT_SUCCESS
%73 = call i32 @exit(i32 %72)
unreachable
}

LLVM IR (-O2):
@__const.main.testString = [15 x i8] c"This is a test\00"
@.str = [15 x i8] c"Left(4): \22%s\22\0A\00"
@.str.2 = [17 x i8] c"Mid(2, 6): \22%s\22\0A\00"
@.str.4 = [16 x i8] c"Right(2): \22%s\22\0A\00"
@EXIT_SUCCESS = global i32 0
@str = [25 x i8] c"Error calling astrleft()\00"
@str.6 = [24 x i8] c"Error calling astrmid()\00"
@str.7 = [26 x i8] c"Error calling astrright()\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [15 x i8]
%4 = getelementptr inbounds [15 x i8], [15 x i8]* %3, i64 0, i64 0
%5 = call i8* @astrcpy(i8* %4)
%6 = icmp eq i8* %5, null
br i1 %6, label %38, label %7
7: ; preds = %2
%8 = call i8* @astrleft(i8* %4, i32 4)
%9 = icmp eq i8* %8, null
br i1 %9, label %12, label %10
10: ; preds = %7
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %8)
br label %14
12: ; preds = %7
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
br label %14
14: ; preds = %12, %10
%15 = call i8* @astrmid(i8* %5, i32 2, i32 6)
%16 = icmp eq i8* %15, null
br i1 %16, label %19, label %17
17: ; preds = %14
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %15)
br label %21
19: ; preds = %14
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.6, i64 0, i64 0))
br label %21
21: ; preds = %19, %17
%22 = call i8* @astrright(i8* %5, i32 2)
%23 = icmp eq i8* %22, null
br i1 %23, label %26, label %24
24: ; preds = %21
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i8* %22)
br label %28
26: ; preds = %21
%27 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.7, i64 0, i64 0))
br label %28
28: ; preds = %26, %24
%29 = call i32 @free(i8* %5)
br i1 %9, label %32, label %30
30: ; preds = %28
%31 = call i32 @free(i8* %8)
br label %32
32: ; preds = %30, %28
br i1 %16, label %35, label %33
33: ; preds = %32
%34 = call i32 @free(i8* %15)
br label %35
35: ; preds = %33, %32
br i1 %23, label %38, label %36
36: ; preds = %35
%37 = call i32 @free(i8* %22)
br label %38
38: ; preds = %2, %36, %35
%39 = load i32, i32* @EXIT_SUCCESS
%40 = call i32 @exit(i32 %39)
unreachable
}