#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 *calloc(unsigned int, int);
char *substr(char *src, unsigned int begin, unsigned int cnt) {
  char *ret;
  int i;
  ret = calloc(cnt + 1, sizeof(char));
  for (i = begin; i < (begin + cnt); i++)
    ret[i - begin] = src[i];
  return ret;
}


x86 assembly (clang, -O0):
<substr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x10(%rbp),%edi
add    $0x1,%edi
mov    $0x1,%esi
call   1030 <calloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0xc(%rbp),%ecx
add    -0x10(%rbp),%ecx
cmp    %ecx,%eax
jae    1175 <substr+0x65>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    -0xc(%rbp),%ecx
mov    %ecx,%ecx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    113c <substr+0x2c>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<substr>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %edx,%ebx
mov    %esi,%r12d
mov    %rdi,%r14
lea    0x1(%rbx),%edi
mov    $0x1,%esi
call   1030 <calloc@plt>
mov    %rax,%r15
lea    (%rbx,%r12,1),%eax
cmp    %r12d,%eax
jbe    1164 <substr+0x44>
movslq %r12d,%rax
add    %rax,%r14
add    $0xffffffff,%ebx
add    $0x1,%rbx
mov    %r15,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1040 <memcpy@plt>
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define noalias i8* @substr(i8* nocapture %0, i32 %1, i32 %2) {
%4 = add i32 %2, 1
%5 = tail call i8* @calloc(i32 %4, i32 1)
%6 = add i32 %2, %1
%7 = icmp ugt i32 %6, %1
br i1 %7, label %8, label %14
8: ; preds = %3
%9 = sext i32 %1 to i64
%10 = getelementptr i8, i8* %0, i64 %9
%11 = add i32 %2, -1
%12 = zext i32 %11 to i64
%13 = add nuw nsw i64 %12, 1
br label %14
14: ; preds = %8, %3
ret i8* %5
}