#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*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *, int *);
int /*<<< orphan*/ substring(char const *, int, int, char *);
int main(void) {
  const char test[] = "character";
  char sub[20];
  int start, count;
  printf("Enter the starting index and number of characters: ");
  scanf("%d %d", &start, &count);
  substring(test, start, count, sub);
  printf("The selected substring is %s.\n", sub);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xeba(%rip),%rax
mov    %rax,-0xe(%rbp)
mov    0xeb7(%rip),%ax
mov    %ax,-0x6(%rbp)
lea    0xeae(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xed4(%rip),%rdi
lea    -0x34(%rbp),%rsi
lea    -0x38(%rbp),%rdx
call   1050 <scanf@plt>
lea    -0xe(%rbp),%rdi
mov    -0x34(%rbp),%esi
mov    -0x38(%rbp),%edx
lea    -0x30(%rbp),%rcx
call   1040 <substring@plt>
lea    -0x30(%rbp),%rsi
lea    0xeaf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x40,%rsp
movabs $0x6574636172616863,%rax
63 74 65
mov    %rax,0x10(%rsp)
movw   $0x72,0x18(%rsp)
lea    0xeb8(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xede(%rip),%rdi
lea    0xc(%rsp),%rsi
lea    0x8(%rsp),%rdx
call   1050 <scanf@plt>
mov    0xc(%rsp),%esi
mov    0x8(%rsp),%edx
lea    0x10(%rsp),%rdi
lea    0x20(%rsp),%rbx
mov    %rbx,%rcx
call   1040 <substring@plt>
lea    0xeb4(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.main.test = [10 x i8] c"character\00"
@.str = [52 x i8] c"Enter the starting index and number of characters: \00"
@.str.1 = [6 x i8] c"%d %d\00"
@.str.2 = [31 x i8] c"The selected substring is %s.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [10 x i8]
%3 = alloca [20 x i8]
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = bitcast [10 x i8]* %2 to i8*
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32* %4, i32* %5)
%9 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%10 = load i32, i32* %4
%11 = load i32, i32* %5
%12 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%13 = call i32 @substring(i8* %9, i32 %10, i32 %11, i8* %12)
%14 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i8* %14)
ret i32 0
}

LLVM IR (-O2):
@__const.main.test = [10 x i8] c"character\00"
@.str = [52 x i8] c"Enter the starting index and number of characters: \00"
@.str.1 = [6 x i8] c"%d %d\00"
@.str.2 = [31 x i8] c"The selected substring is %s.\0A\00"
define i32 @main() {
%1 = alloca [10 x i8]
%2 = alloca [20 x i8]
%3 = alloca i32
%4 = alloca i32
%5 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 0
%6 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%7 = bitcast i32* %3 to i8*
%8 = bitcast i32* %4 to i8*
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32* %3, i32* %4)
%11 = load i32, i32* %3
%12 = load i32, i32* %4
%13 = call i32 @substring(i8* %5, i32 %11, i32 %12, i8* %6)
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i8* %6)
ret i32 0
}