#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*/ gets(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *, int *);
int /*<<< orphan*/ substring(char *, char *, int, int);
int main() {
  char string[1000], sub[1000];
  int position, length, c = 0;
  printf("Input a string\n");
  gets(string);
  printf("Enter the position and length of substring\n");
  scanf("%d%d", &position, &length);
  substring(string, sub, position, length);
  printf("Required substring is \"%s\"\n", sub);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x7f0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x7ec(%rbp)
lea    0xe9d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x3f0(%rbp),%rdi
call   1050 <gets@plt>
lea    0xe93(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeb1(%rip),%rdi
lea    -0x7e4(%rbp),%rsi
lea    -0x7e8(%rbp),%rdx
call   1060 <scanf@plt>
lea    -0x3f0(%rbp),%rdi
lea    -0x7e0(%rbp),%rsi
mov    -0x7e4(%rbp),%edx
mov    -0x7e8(%rbp),%ecx
call   1040 <substring@plt>
lea    -0x7e0(%rbp),%rsi
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x7f0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x7e8,%rsp
lea    0xec0(%rip),%rdi
call   1030 <puts@plt>
lea    0x400(%rsp),%r14
mov    %r14,%rdi
call   1060 <gets@plt>
lea    0xeb3(%rip),%rdi
call   1030 <puts@plt>
lea    0xe77(%rip),%rdi
lea    0xc(%rsp),%rsi
lea    0x8(%rsp),%rdx
call   1070 <scanf@plt>
mov    0xc(%rsp),%edx
mov    0x8(%rsp),%ecx
lea    0x10(%rsp),%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <substring@plt>
lea    0xe4e(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x7e8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [16 x i8] c"Input a string\0A\00"
@.str.1 = [44 x i8] c"Enter the position and length of substring\0A\00"
@.str.2 = [5 x i8] c"%d%d\00"
@.str.3 = [28 x i8] c"Required substring is \22%s\22\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [1000 x i8]
%3 = alloca [1000 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %6
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%8 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 0
%9 = call i32 @gets(i8* %8)
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32* %4, i32* %5)
%12 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 0
%13 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%14 = load i32, i32* %4
%15 = load i32, i32* %5
%16 = call i32 @substring(i8* %12, i8* %13, i32 %14, i32 %15)
%17 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i8* %17)
ret i32 0
}

LLVM IR (-O2):
@.str.2 = [5 x i8] c"%d%d\00"
@.str.3 = [28 x i8] c"Required substring is \22%s\22\0A\00"
@str = [15 x i8] c"Input a string\00"
@str.4 = [43 x i8] c"Enter the position and length of substring\00"
define i32 @main() {
%1 = alloca [1000 x i8]
%2 = alloca [1000 x i8]
%3 = alloca i32
%4 = alloca i32
%5 = getelementptr inbounds [1000 x i8], [1000 x i8]* %1, i64 0, i64 0
%6 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 0
%7 = bitcast i32* %3 to i8*
%8 = bitcast i32* %4 to i8*
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
%10 = call i32 @gets(i8* %5)
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @str.4, i64 0, i64 0))
%12 = call i32 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32* %3, i32* %4)
%13 = load i32, i32* %3
%14 = load i32, i32* %4
%15 = call i32 @substring(i8* %5, i8* %6, i32 %13, i32 %14)
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i8* %6)
ret i32 0
}