#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 GetStringLength(char *);
char *ReturnNullMallocStack(char *);
char *Substring(char *, char *, int const, int);
char *Substring2(char *output, char *input, const int start) {
  int length = GetStringLength(input);
  if (length < 1 || start < 0 || start > length - 1) {
    return ReturnNullMallocStack(output);
  }
  return Substring(output, input, start, length - start);
}


x86 assembly (clang, -O0):
<Substring2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <GetStringLength@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x1,-0x20(%rbp)
jl     1174 <Substring2+0x44>
cmpl   $0x0,-0x1c(%rbp)
jl     1174 <Substring2+0x44>
mov    -0x1c(%rbp),%eax
mov    -0x20(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jle    1186 <Substring2+0x56>
mov    -0x10(%rbp),%rdi
call   1030 <ReturnNullMallocStack@plt>
mov    %rax,-0x8(%rbp)
jmp    11a0 <Substring2+0x70>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    -0x20(%rbp),%ecx
sub    -0x1c(%rbp),%ecx
call   1040 <Substring@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Substring2>:
push   %r15
push   %r14
push   %rbx
mov    %edx,%ebx
mov    %rsi,%r14
mov    %rdi,%r15
mov    %rsi,%rdi
call   1050 <GetStringLength@plt>
mov    %eax,%ecx
sub    %ebx,%ecx
jle    1165 <Substring2+0x35>
test   %ebx,%ebx
js     1165 <Substring2+0x35>
test   %eax,%eax
jle    1165 <Substring2+0x35>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <Substring@plt>
mov    %r15,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <ReturnNullMallocStack@plt>

LLVM IR (-O0):
define i8* @Substring2(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%9 = load i8*, i8** %6
%10 = call i32 @GetStringLength(i8* %9)
store i32 %10, i32* %8
%11 = load i32, i32* %8
%12 = icmp slt i32 %11, 1
br i1 %12, label %21, label %13
13: ; preds = %3
%14 = load i32, i32* %7
%15 = icmp slt i32 %14, 0
br i1 %15, label %21, label %16
16: ; preds = %13
%17 = load i32, i32* %7
%18 = load i32, i32* %8
%19 = sub nsw i32 %18, 1
%20 = icmp sgt i32 %17, %19
br i1 %20, label %21, label %24
21: ; preds = %16, %13, %3
%22 = load i8*, i8** %5
%23 = call i8* @ReturnNullMallocStack(i8* %22)
store i8* %23, i8** %4
br label %32
24: ; preds = %16
%25 = load i8*, i8** %5
%26 = load i8*, i8** %6
%27 = load i32, i32* %7
%28 = load i32, i32* %8
%29 = load i32, i32* %7
%30 = sub nsw i32 %28, %29
%31 = call i8* @Substring(i8* %25, i8* %26, i32 %27, i32 %30)
store i8* %31, i8** %4
br label %32
32: ; preds = %24, %21
%33 = load i8*, i8** %4
ret i8* %33
}

LLVM IR (-O2):
define i8* @Substring2(i8* %0, i8* %1, i32 %2) {
%4 = tail call i32 @GetStringLength(i8* %1)
%5 = icmp sgt i32 %4, 0
%6 = icmp sgt i32 %2, -1
%7 = and i1 %6, %5
%8 = icmp sgt i32 %4, %2
%9 = and i1 %8, %7
br i1 %9, label %12, label %10
10: ; preds = %3
%11 = tail call i8* @ReturnNullMallocStack(i8* %0)
br label %15
12: ; preds = %3
%13 = sub nsw i32 %4, %2
%14 = tail call i8* @Substring(i8* %0, i8* %1, i32 %2, i32 %13)
br label %15
15: ; preds = %12, %10
%16 = phi i8* [ %11, %10 ], [ %14, %12 ]
ret i8* %16
}