#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*/ assert(char *);
char *calloc(int, int);
int /*<<< orphan*/ memcpy(char *, char *, int);
char *strcasestr(char const *, char const *);
int /*<<< orphan*/ strlen(char const *);
char *http_utils_get_string_between(const char *str, const char *begin,
                                    const char *end) {
  char *found = strcasestr(str, begin);
  char *ret = NULL;
  if (found) {
    found += strlen(begin);
    char *found_end = strcasestr(found, end);
    if (found_end) {
      ret = calloc(1, found_end - found + 1);
      assert(ret);
      memcpy(ret, found, found_end - found);
      return ret;
    }
  }
  return NULL;
}


x86 assembly (clang, -O0):
<http_utils_get_string_between>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1070 <strcasestr@plt>
mov    %rax,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1211 <http_utils_get_string_between+0xc1>
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1070 <strcasestr@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     120c <http_utils_get_string_between+0xbc>
mov    -0x38(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    %rcx,%rax
add    $0x1,%rax
mov    %eax,%esi
mov    $0x1,%edi
call   1040 <calloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
call   1050 <assert@plt>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x38(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
call   1060 <memcpy@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1219 <http_utils_get_string_between+0xc9>
jmp    1211 <http_utils_get_string_between+0xc1>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<http_utils_get_string_between>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%rbx
call   1070 <strcasestr@plt>
test   %rax,%rax
je     11b7 <http_utils_get_string_between+0x67>
mov    %rax,%r12
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
add    %rax,%r12
mov    %r12,%rdi
mov    %r14,%rsi
call   1070 <strcasestr@plt>
test   %rax,%rax
je     11b7 <http_utils_get_string_between+0x67>
mov    %rax,%r14
sub    %r12d,%r14d
lea    0x1(%r14),%esi
mov    $0x1,%edi
call   1040 <calloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
call   1050 <assert@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %r14d,%edx
call   1060 <memcpy@plt>
jmp    11ba <http_utils_get_string_between+0x6a>
xor    %r15d,%r15d
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @http_utils_get_string_between(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%11 = load i8*, i8** %5
%12 = load i8*, i8** %6
%13 = call i8* @strcasestr(i8* %11, i8* %12)
store i8* %13, i8** %8
store i8* null, i8** %9
%14 = load i8*, i8** %8
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %49
16: ; preds = %3
%17 = load i8*, i8** %6
%18 = call i32 @strlen(i8* %17)
%19 = load i8*, i8** %8
%20 = sext i32 %18 to i64
%21 = getelementptr inbounds i8, i8* %19, i64 %20
store i8* %21, i8** %8
%22 = load i8*, i8** %8
%23 = load i8*, i8** %7
%24 = call i8* @strcasestr(i8* %22, i8* %23)
store i8* %24, i8** %10
%25 = load i8*, i8** %10
%26 = icmp ne i8* %25, null
br i1 %26, label %27, label %48
27: ; preds = %16
%28 = load i8*, i8** %10
%29 = load i8*, i8** %8
%30 = ptrtoint i8* %28 to i64
%31 = ptrtoint i8* %29 to i64
%32 = sub i64 %30, %31
%33 = add nsw i64 %32, 1
%34 = trunc i64 %33 to i32
%35 = call i8* @calloc(i32 1, i32 %34)
store i8* %35, i8** %9
%36 = load i8*, i8** %9
%37 = call i32 @assert(i8* %36)
%38 = load i8*, i8** %9
%39 = load i8*, i8** %8
%40 = load i8*, i8** %10
%41 = load i8*, i8** %8
%42 = ptrtoint i8* %40 to i64
%43 = ptrtoint i8* %41 to i64
%44 = sub i64 %42, %43
%45 = trunc i64 %44 to i32
%46 = call i32 @memcpy(i8* %38, i8* %39, i32 %45)
%47 = load i8*, i8** %9
store i8* %47, i8** %4
br label %50
48: ; preds = %16
br label %49
49: ; preds = %48, %3
store i8* null, i8** %4
br label %50
50: ; preds = %49, %27
%51 = load i8*, i8** %4
ret i8* %51
}

LLVM IR (-O2):
define i8* @http_utils_get_string_between(i8* %0, i8* %1, i8* %2) {
%4 = tail call i8* @strcasestr(i8* %0, i8* %1)
%5 = icmp eq i8* %4, null
br i1 %5, label %21, label %6
6: ; preds = %3
%7 = tail call i32 @strlen(i8* %1)
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds i8, i8* %4, i64 %8
%10 = tail call i8* @strcasestr(i8* %9, i8* %2)
%11 = icmp eq i8* %10, null
br i1 %11, label %21, label %12
12: ; preds = %6
%13 = ptrtoint i8* %10 to i64
%14 = ptrtoint i8* %9 to i64
%15 = sub i64 %13, %14
%16 = trunc i64 %15 to i32
%17 = add i32 %16, 1
%18 = tail call i8* @calloc(i32 1, i32 %17)
%19 = tail call i32 @assert(i8* %18)
%20 = tail call i32 @memcpy(i8* %18, i8* %9, i32 %16)
br label %21
21: ; preds = %6, %3, %12
%22 = phi i8* [ %18, %12 ], [ null, %3 ], [ null, %6 ]
ret i8* %22
}