#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 */
scalar_t__ malloc(int);
long strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, long);
char *strstr(char const *, char *);
char *create_substring(const char *haystack, char *start, char *end) {
  char *from, *to;
  long diff;
  long offset;
  from = strstr(haystack, start);
  to = strstr(from, end);
  diff = to - from;
  offset = strlen(start);
  char *out = (char *)malloc(sizeof(char) * diff - offset + 1);
  strncpy(out, from + offset, diff - offset);
  out[diff - offset] = '\0';
  return out;
}


x86 assembly (clang, -O0):
<create_substring>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <strstr@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <strstr@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rax
shl    $0x0,%rax
sub    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x20(%rbp),%rsi
add    -0x38(%rbp),%rsi
mov    -0x30(%rbp),%rdx
sub    -0x38(%rbp),%rdx
call   1030 <strncpy@plt>
mov    -0x40(%rbp),%rax
mov    -0x30(%rbp),%rcx
sub    -0x38(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x40(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_substring>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
call   1060 <strstr@plt>
mov    %rax,%r12
mov    %rax,%rdi
mov    %r14,%rsi
call   1060 <strstr@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1040 <strlen@plt>
add    %rax,%r12
sub    %r12,%rbx
lea    0x1(%rbx),%edi
call   1050 <malloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1030 <strncpy@plt>
movb   $0x0,(%r14,%rbx,1)
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @create_substring(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i64
%11 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%12 = load i8*, i8** %4
%13 = load i8*, i8** %5
%14 = call i8* @strstr(i8* %12, i8* %13)
store i8* %14, i8** %7
%15 = load i8*, i8** %7
%16 = load i8*, i8** %6
%17 = call i8* @strstr(i8* %15, i8* %16)
store i8* %17, i8** %8
%18 = load i8*, i8** %8
%19 = load i8*, i8** %7
%20 = ptrtoint i8* %18 to i64
%21 = ptrtoint i8* %19 to i64
%22 = sub i64 %20, %21
store i64 %22, i64* %9
%23 = load i8*, i8** %5
%24 = call i64 @strlen(i8* %23)
store i64 %24, i64* %10
%25 = load i64, i64* %9
%26 = mul i64 1, %25
%27 = load i64, i64* %10
%28 = sub i64 %26, %27
%29 = add i64 %28, 1
%30 = trunc i64 %29 to i32
%31 = call i64 @malloc(i32 %30)
%32 = inttoptr i64 %31 to i8*
store i8* %32, i8** %11
%33 = load i8*, i8** %11
%34 = load i8*, i8** %7
%35 = load i64, i64* %10
%36 = getelementptr inbounds i8, i8* %34, i64 %35
%37 = load i64, i64* %9
%38 = load i64, i64* %10
%39 = sub nsw i64 %37, %38
%40 = call i32 @strncpy(i8* %33, i8* %36, i64 %39)
%41 = load i8*, i8** %11
%42 = load i64, i64* %9
%43 = load i64, i64* %10
%44 = sub nsw i64 %42, %43
%45 = getelementptr inbounds i8, i8* %41, i64 %44
store i8 0, i8* %45
%46 = load i8*, i8** %11
ret i8* %46
}

LLVM IR (-O2):
define i8* @create_substring(i8* %0, i8* nocapture %1, i8* nocapture %2) {
%4 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) %1)
%5 = tail call i8* @strstr(i8* dereferenceable(1) %4, i8* dereferenceable(1) %2)
%6 = ptrtoint i8* %5 to i64
%7 = ptrtoint i8* %4 to i64
%8 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%9 = add i64 %8, %7
%10 = sub i64 %6, %9
%11 = trunc i64 %10 to i32
%12 = add i32 %11, 1
%13 = tail call i64 @malloc(i32 %12)
%14 = inttoptr i64 %13 to i8*
%15 = getelementptr inbounds i8, i8* %4, i64 %8
%16 = tail call i32 @strncpy(i8* %14, i8* %15, i64 %10)
%17 = getelementptr inbounds i8, i8* %14, i64 %10
store i8 0, i8* %17
ret i8* %14
}