#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 */
char *strdup(char *);
char *getSubString(char *str, int start, int lenght) {
  char ret[lenght];
  int i;
  for (i = 0; i < lenght; i++)
    ret[i] = str[start + i];
  ret[lenght] = '\0';
  return strdup(ret);
}


x86 assembly (clang, -O0):
<getSubString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1184 <getSubString+0x74>
mov    -0x30(%rbp),%rax
mov    -0x8(%rbp),%rcx
mov    -0xc(%rbp),%edx
add    -0x24(%rbp),%edx
movslq %edx,%rdx
mov    (%rcx,%rdx,1),%dl
movslq -0x24(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    114f <getSubString+0x3f>
mov    -0x30(%rbp),%rdi
movslq -0x10(%rbp),%rax
movb   $0x0,(%rdi,%rax,1)
call   1030 <strdup@plt>
mov    -0x18(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getSubString>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
mov    %edx,%r14d
mov    %edx,%edx
mov    %rsp,%rbx
lea    0xf(%rdx),%rcx
and    $0xfffffffffffffff0,%rcx
sub    %rcx,%rbx
mov    %rbx,%rsp
test   %r14d,%r14d
jle    1156 <getSubString+0x36>
mov    %rdi,%rax
movslq %esi,%rcx
add    %rcx,%rax
mov    %rbx,%rdi
mov    %rax,%rsi
call   1030 <memcpy@plt>
movslq %r14d,%rax
movb   $0x0,(%rbx,%rax,1)
mov    %rbx,%rdi
call   1040 <strdup@plt>
lea    -0x10(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i8* @getSubString(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%10 = load i32, i32* %6
%11 = zext i32 %10 to i64
%12 = call i8* @llvm.stacksave()
store i8* %12, i8** %7
%13 = alloca i8, i64 %11
store i64 %11, i64* %8
store i32 0, i32* %9
br label %14
14: ; preds = %29, %3
%15 = load i32, i32* %9
%16 = load i32, i32* %6
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %32
18: ; preds = %14
%19 = load i8*, i8** %4
%20 = load i32, i32* %5
%21 = load i32, i32* %9
%22 = add nsw i32 %20, %21
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %19, i64 %23
%25 = load i8, i8* %24
%26 = load i32, i32* %9
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %13, i64 %27
store i8 %25, i8* %28
br label %29
29: ; preds = %18
%30 = load i32, i32* %9
%31 = add nsw i32 %30, 1
store i32 %31, i32* %9
br label %14
32: ; preds = %14
%33 = load i32, i32* %6
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %13, i64 %34
store i8 0, i8* %35
%36 = call i8* @strdup(i8* %13)
%37 = load i8*, i8** %7
ret i8* %36
}

LLVM IR (-O2):
define noalias i8* @getSubString(i8* nocapture %0, i32 %1, i32 %2) {
%4 = zext i32 %2 to i64
%5 = alloca i8, i64 %4
%6 = icmp sgt i32 %2, 0
br i1 %6, label %7, label %10
7: ; preds = %3
%8 = sext i32 %1 to i64
%9 = getelementptr i8, i8* %0, i64 %8
br label %10
10: ; preds = %7, %3
%11 = sext i32 %2 to i64
%12 = getelementptr inbounds i8, i8* %5, i64 %11
store i8 0, i8* %12
%13 = call i8* @strdup(i8* %5)
ret i8* %13
}