#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*/ free(char *);
int /*<<< orphan*/ printf(char *, char *, ...);
char *strutil_substring(char *, size_t, size_t);
int main(void) {
  size_t start = 7;
  size_t end = 12;
  char *str = "Hello, world!";
  char *substr = strutil_substring(str, start, end);
  printf("Original:  \"%s\"\n", str);
  printf("Substring: \"%s\" (from index %lu to %lu)\n", substr, start, end);
  free(substr);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x7,-0x10(%rbp)
movq   $0xc,-0x18(%rbp)
lea    0xeaa(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <strutil_substring@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rsi
lea    0xe94(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x28(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xe8b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xec5(%rip),%r14
mov    $0x7,%esi
mov    $0xc,%edx
mov    %r14,%rdi
call   1040 <strutil_substring@plt>
mov    %rax,%rbx
lea    0xeb7(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xeb7(%rip),%rdi
mov    $0x7,%edx
mov    $0xc,%ecx
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [14 x i8] c"Hello, world!\00"
@.str.1 = [17 x i8] c"Original: \22%s\22\0A\00"
@.str.2 = [41 x i8] c"Substring: \22%s\22 (from index %lu to %lu)\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i64
%4 = alloca i8*
%5 = alloca i8*
store i32 0, i32* %1
store i64 7, i64* %2
store i64 12, i64* %3
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8** %4
%6 = load i8*, i8** %4
%7 = load i64, i64* %2
%8 = load i64, i64* %3
%9 = call i8* @strutil_substring(i8* %6, i64 %7, i64 %8)
store i8* %9, i8** %5
%10 = load i8*, i8** %4
%11 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %10)
%12 = load i8*, i8** %5
%13 = load i64, i64* %2
%14 = load i64, i64* %3
%15 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i8* %12, i64 %13, i64 %14)
%16 = load i8*, i8** %5
%17 = call i32 @free(i8* %16)
ret i32 0
}

LLVM IR (-O2):
@.str = [14 x i8] c"Hello, world!\00"
@.str.1 = [17 x i8] c"Original: \22%s\22\0A\00"
@.str.2 = [41 x i8] c"Substring: \22%s\22 (from index %lu to %lu)\0A\00"
define i32 @main() {
%1 = tail call i8* @strutil_substring(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i64 7, i64 12)
%2 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%3 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i8* %1, i64 7, i64 12)
%4 = tail call i32 @free(i8* %1)
ret i32 0
}