#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 main() {
  char str[80], substr[80];
  int start, end, i, j;
  printf("Enter a string: ");
  scanf("%s", str);
  printf("Enter start and end positions to extract\nthe substring (index "
         "starting from 0) : ");
  scanf("%d %d", &start, &end);
  for (i = start, j = 0; i <= end; i++, j++)
    substr[j] = str[i];
  substr[j] = '\0';
  printf("Extraxted substring: %s\n", substr);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xec7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x60(%rbp),%rsi
lea    0xec6(%rip),%rdi
mov    $0x0,%al
call   1040 <scanf@plt>
lea    0xebb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeff(%rip),%rdi
lea    -0xb4(%rbp),%rsi
lea    -0xb8(%rbp),%rdx
mov    $0x0,%al
call   1040 <scanf@plt>
mov    -0xb4(%rbp),%eax
mov    %eax,-0xbc(%rbp)
movl   $0x0,-0xc0(%rbp)
mov    -0xbc(%rbp),%eax
cmp    -0xb8(%rbp),%eax
jg     11e0 <main+0xc0>
movslq -0xbc(%rbp),%rax
mov    -0x60(%rbp,%rax,1),%cl
movslq -0xc0(%rbp),%rax
mov    %cl,-0xb0(%rbp,%rax,1)
mov    -0xbc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xbc(%rbp)
mov    -0xc0(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc0(%rbp)
jmp    1192 <main+0x72>
movslq -0xc0(%rbp),%rax
movb   $0x0,-0xb0(%rbp,%rax,1)
lea    -0xb0(%rbp),%rsi
lea    0xe6f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0xb8,%rsp
lea    0xebf(%rip),%rdi
xor    %r14d,%r14d
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xebf(%rip),%rdi
lea    0x60(%rsp),%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
lea    0xeaf(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xef3(%rip),%rdi
lea    0xc(%rsp),%rsi
lea    0x8(%rsp),%rdx
xor    %eax,%eax
call   1050 <scanf@plt>
movslq 0xc(%rsp),%rax
mov    0x8(%rsp),%ebx
cmp    %eax,%ebx
jl     11af <main+0x7f>
lea    (%rsp,%rax,1),%rsi
add    $0x60,%rsi
sub    %eax,%ebx
add    $0x1,%rbx
lea    0x10(%rsp),%rdi
mov    %rbx,%rdx
call   1040 <memcpy@plt>
mov    %ebx,%r14d
movb   $0x0,0x10(%rsp,%r14,1)
lea    0xeb0(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0xb8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [17 x i8] c"Enter a string: \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [82 x i8] c"Enter start and end positions to extract\0Athe substring (index starting from 0) : \00"
@.str.3 = [6 x i8] c"%d %d\00"
@.str.4 = [25 x i8] c"Extraxted substring: %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [80 x i8]
%3 = alloca [80 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%9 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%10 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %9)
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([82 x i8], [82 x i8]* @.str.2, i64 0, i64 0))
%12 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32* %4, i32* %5)
%13 = load i32, i32* %4
store i32 %13, i32* %6
store i32 0, i32* %7
br label %14
14: ; preds = %26, %0
%15 = load i32, i32* %6
%16 = load i32, i32* %5
%17 = icmp sle i32 %15, %16
br i1 %17, label %18, label %31
18: ; preds = %14
%19 = load i32, i32* %6
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 %20
%22 = load i8, i8* %21
%23 = load i32, i32* %7
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 %24
store i8 %22, i8* %25
br label %26
26: ; preds = %18
%27 = load i32, i32* %6
%28 = add nsw i32 %27, 1
store i32 %28, i32* %6
%29 = load i32, i32* %7
%30 = add nsw i32 %29, 1
store i32 %30, i32* %7
br label %14
31: ; preds = %14
%32 = load i32, i32* %7
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 %33
store i8 0, i8* %34
%35 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i8* %35)
%37 = load i32, i32* %1
ret i32 %37
}

LLVM IR (-O2):
@.str = [17 x i8] c"Enter a string: \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [82 x i8] c"Enter start and end positions to extract\0Athe substring (index starting from 0) : \00"
@.str.3 = [6 x i8] c"%d %d\00"
@.str.4 = [25 x i8] c"Extraxted substring: %s\0A\00"
define i32 @main() {
%1 = alloca [80 x i8]
%2 = alloca [80 x i8]
%3 = alloca i32
%4 = alloca i32
%5 = getelementptr inbounds [80 x i8], [80 x i8]* %1, i64 0, i64 0
%6 = getelementptr inbounds [80 x i8], [80 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 ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%10 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %5)
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([82 x i8], [82 x i8]* @.str.2, i64 0, i64 0))
%12 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32* %3, i32* %4)
%13 = load i32, i32* %3
%14 = load i32, i32* %4
%15 = icmp slt i32 %14, %13
br i1 %15, label %24, label %16
16: ; preds = %0
%17 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%18 = sext i32 %13 to i64
%19 = getelementptr [80 x i8], [80 x i8]* %1, i64 0, i64 %18
%20 = sub i32 %14, %13
%21 = zext i32 %20 to i64
%22 = add nuw nsw i64 %21, 1
%23 = and i64 %22, 4294967295
br label %24
24: ; preds = %16, %0
%25 = phi i64 [ 0, %0 ], [ %23, %16 ]
%26 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 %25
store i8 0, i8* %26
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i8* %6)
ret i32 0
}