#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*/ free(char *);
int /*<<< orphan*/ printf(char *, char *);
char *substr(char *, int, int);
int main() {
  char *test = "averylongstring";
  char *result = substr(test, 2, 5);
  printf("%s \n", result);
  char *result2 = substr(test, 10, 15);
  printf("%s \n", result2);
  char *result3 = substr(test, 0, 8);
  printf("%s \n", result3);
  char *result4 = substr(test, 15, 18);
  printf("%s \n", result4);
  free(result);
  free(result2);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2,%esi
mov    $0x5,%edx
call   1040 <substr@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xea4(%rip),%rdi
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    $0xa,%esi
mov    $0xf,%edx
call   1040 <substr@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
lea    0xe7d(%rip),%rdi
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <substr@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rsi
lea    0xe59(%rip),%rdi
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    $0xf,%esi
mov    $0x12,%edx
call   1040 <substr@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rsi
lea    0xe32(%rip),%rdi
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xec1(%rip),%r14
mov    %r14,%rdi
mov    $0x2,%esi
mov    $0x5,%edx
call   1040 <substr@plt>
mov    %rax,%r12
lea    0xeb5(%rip),%r15
mov    %r15,%rdi
mov    %rax,%rsi
call   1050 <printf@plt>
mov    %r14,%rdi
mov    $0xa,%esi
mov    $0xf,%edx
call   1040 <substr@plt>
mov    %rax,%rbx
mov    %r15,%rdi
mov    %rax,%rsi
call   1050 <printf@plt>
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <substr@plt>
mov    %r15,%rdi
mov    %rax,%rsi
call   1050 <printf@plt>
mov    %r14,%rdi
mov    $0xf,%esi
mov    $0x12,%edx
call   1040 <substr@plt>
mov    %r15,%rdi
mov    %rax,%rsi
call   1050 <printf@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [16 x i8] c"averylongstring\00"
@.str.1 = [5 x i8] c"%s \0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i32 0, i32* %1
store i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8** %2
%7 = load i8*, i8** %2
%8 = call i8* @substr(i8* %7, i32 2, i32 5)
store i8* %8, i8** %3
%9 = load i8*, i8** %3
%10 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %9)
%11 = load i8*, i8** %2
%12 = call i8* @substr(i8* %11, i32 10, i32 15)
store i8* %12, i8** %4
%13 = load i8*, i8** %4
%14 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %13)
%15 = load i8*, i8** %2
%16 = call i8* @substr(i8* %15, i32 0, i32 8)
store i8* %16, i8** %5
%17 = load i8*, i8** %5
%18 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %17)
%19 = load i8*, i8** %2
%20 = call i8* @substr(i8* %19, i32 15, i32 18)
store i8* %20, i8** %6
%21 = load i8*, i8** %6
%22 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %21)
%23 = load i8*, i8** %3
%24 = call i32 @free(i8* %23)
%25 = load i8*, i8** %4
%26 = call i32 @free(i8* %25)
ret i32 0
}

LLVM IR (-O2):
@.str = [16 x i8] c"averylongstring\00"
@.str.1 = [5 x i8] c"%s \0A\00"
define i32 @main() {
%1 = tail call i8* @substr(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 2, i32 5)
%2 = tail call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %1)
%3 = tail call i8* @substr(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 10, i32 15)
%4 = tail call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%5 = tail call i8* @substr(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 0, i32 8)
%6 = tail call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %5)
%7 = tail call i8* @substr(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 15, i32 18)
%8 = tail call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %7)
%9 = tail call i32 @free(i8* %1)
%10 = tail call i32 @free(i8* %3)
ret i32 0
}