#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*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ stdin;
int substr(char *, char *, int, int);
int main(void) {
  char dest[100];
  char string[100];
  int start;
  int len;
  puts("Say something cool from which to copy:");
  fgets(string, 100, stdin);
  printf("Ok, now from which ch forward do you want me to copy?: ");
  scanf("%d", &start);
  printf("\nAnd at which ch would you like me to stop?: ");
  scanf("%d", &len);
  puts("\n\nCool!");
  printf("So you should have %d characters left..",
         substr(dest, string, start, len));
  puts("\n\tWhich should be..");
  puts(dest);
  puts("\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xf0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe97(%rip),%rdi
call   1030 <puts@plt>
lea    -0xe0(%rbp),%rdi
mov    0x2e6c(%rip),%rax
mov    (%rax),%edx
mov    $0x64,%esi
call   1060 <fgets@plt>
lea    0xe98(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xec2(%rip),%rdi
lea    -0xe4(%rbp),%rsi
call   1070 <scanf@plt>
lea    0xeb2(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xea1(%rip),%rdi
lea    -0xe8(%rbp),%rsi
call   1070 <scanf@plt>
lea    0xebf(%rip),%rdi
call   1030 <puts@plt>
lea    -0x70(%rbp),%rdi
lea    -0xe0(%rbp),%rsi
mov    -0xe4(%rbp),%edx
mov    -0xe8(%rbp),%ecx
call   1040 <substr@plt>
mov    %eax,%esi
lea    0xe9d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xeb7(%rip),%rdi
call   1030 <puts@plt>
lea    -0x70(%rbp),%rdi
call   1030 <puts@plt>
lea    0xeb6(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0xf0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0xe8,%rsp
lea    0xe9f(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e7b(%rip),%rax
mov    (%rax),%edx
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    $0x64,%esi
call   1060 <fgets@plt>
lea    0xe9f(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xec9(%rip),%rbx
lea    0xc(%rsp),%rsi
mov    %rbx,%rdi
call   1070 <scanf@plt>
lea    0xeb8(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1070 <scanf@plt>
lea    0xecb(%rip),%rdi
call   1030 <puts@plt>
mov    0xc(%rsp),%edx
mov    0x8(%rsp),%ecx
lea    0x80(%rsp),%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <substr@plt>
lea    0xeac(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xec4(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
lea    0xec4(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0xe8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [39 x i8] c"Say something cool from which to copy:\00"
@stdin = global i32 0
@.str.1 = [56 x i8] c"Ok, now from which ch forward do you want me to copy?: \00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [46 x i8] c"\0AAnd at which ch would you like me to stop?: \00"
@.str.4 = [8 x i8] c"\0A\0ACool!\00"
@.str.5 = [40 x i8] c"So you should have %d characters left..\00"
@.str.6 = [20 x i8] c"\0A\09Which should be..\00"
@.str.7 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [100 x i8]
%3 = alloca [100 x i8]
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32 @puts(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
%7 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%8 = load i32, i32* @stdin
%9 = call i32 @fgets(i8* %7, i32 100, i32 %8)
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %4)
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.3, i64 0, i64 0))
%13 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %5)
%14 = call i32 @puts(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%15 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%16 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%17 = load i32, i32* %4
%18 = load i32, i32* %5
%19 = call i32 @substr(i8* %15, i8* %16, i32 %17, i32 %18)
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.5, i64 0, i64 0), i32 %19)
%21 = call i32 @puts(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0))
%22 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%23 = call i32 @puts(i8* %22)
%24 = call i32 @puts(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [39 x i8] c"Say something cool from which to copy:\00"
@stdin = global i32 0
@.str.1 = [56 x i8] c"Ok, now from which ch forward do you want me to copy?: \00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [46 x i8] c"\0AAnd at which ch would you like me to stop?: \00"
@.str.4 = [8 x i8] c"\0A\0ACool!\00"
@.str.5 = [40 x i8] c"So you should have %d characters left..\00"
@.str.6 = [20 x i8] c"\0A\09Which should be..\00"
@.str.7 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca [100 x i8]
%2 = alloca [100 x i8]
%3 = alloca i32
%4 = alloca i32
%5 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%6 = getelementptr inbounds [100 x i8], [100 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 ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
%10 = load i32, i32* @stdin
%11 = call i32 @fgets(i8* %6, i32 100, i32 %10)
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @.str.1, i64 0, i64 0))
%13 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str.3, i64 0, i64 0))
%15 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %4)
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%17 = load i32, i32* %3
%18 = load i32, i32* %4
%19 = call i32 @substr(i8* %5, i8* %6, i32 %17, i32 %18)
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.5, i64 0, i64 0), i32 %19)
%21 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0))
%22 = call i32 @puts(i8* %5)
%23 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
ret i32 0
}