#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*/ memcpy(char *, char *, int);
int /*<<< orphan*/ memset(char *, int, int);
int /*<<< orphan*/ printf(char *, int, ...);
char *strstr(char *, char *);
char *search_get(char *ptr, char *search_start, char *search_end, char *buf,
                 int buf_len) {
  char *start = strstr(ptr, search_start);
  if (start == NULL) {
    printf("%d\n", 17);
    return NULL;
  }
  char *end = strstr(start, search_end);
  if (end == NULL) {
    printf("%d %x\n", 23, *search_end);
    return NULL;
  }
  memset(buf, 0x0, buf_len);
  memcpy(buf, start, end - start);
  return start;
}


x86 assembly (clang, -O0):
<search_get>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8d,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <strstr@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    1198 <search_get+0x58>
lea    0xe81(%rip),%rdi
mov    $0x11,%esi
mov    $0x0,%al
call   1030 <printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    120b <search_get+0xcb>
mov    -0x38(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1060 <strstr@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    11db <search_get+0x9b>
mov    -0x20(%rbp),%rax
movsbl (%rax),%edx
lea    0xe42(%rip),%rdi
mov    $0x17,%esi
mov    $0x0,%al
call   1030 <printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    120b <search_get+0xcb>
mov    -0x28(%rbp),%rdi
mov    -0x2c(%rbp),%edx
xor    %esi,%esi
call   1040 <memset@plt>
mov    -0x28(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x40(%rbp),%rax
mov    -0x38(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
call   1050 <memcpy@plt>
mov    -0x38(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<search_get>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %r8d,%r15d
mov    %rcx,%r14
mov    %rdx,%r12
call   1060 <strstr@plt>
test   %rax,%rax
je     118f <search_get+0x4f>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r12,%rsi
call   1060 <strstr@plt>
test   %rax,%rax
je     11a6 <search_get+0x66>
mov    %rax,%rbp
mov    %r14,%rdi
xor    %esi,%esi
mov    %r15d,%edx
call   1040 <memset@plt>
sub    %ebx,%ebp
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1050 <memcpy@plt>
jmp    11c0 <search_get+0x80>
lea    0xe6a(%rip),%rdi
xor    %ebx,%ebx
mov    $0x11,%esi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    11c0 <search_get+0x80>
movsbl (%r12),%edx
lea    0xe52(%rip),%rdi
xor    %ebx,%ebx
mov    $0x17,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%d\0A\00"
@.str.1 = [7 x i8] c"%d %x\0A\00"
define i8* @search_get(i8* %0, i8* %1, i8* %2, i8* %3, i32 %4) {
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i8*
store i8* %0, i8** %7
store i8* %1, i8** %8
store i8* %2, i8** %9
store i8* %3, i8** %10
store i32 %4, i32* %11
%14 = load i8*, i8** %7
%15 = load i8*, i8** %8
%16 = call i8* @strstr(i8* %14, i8* %15)
store i8* %16, i8** %12
%17 = load i8*, i8** %12
%18 = icmp eq i8* %17, null
br i1 %18, label %19, label %21
19: ; preds = %5
%20 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 17)
store i8* null, i8** %6
br label %46
21: ; preds = %5
%22 = load i8*, i8** %12
%23 = load i8*, i8** %9
%24 = call i8* @strstr(i8* %22, i8* %23)
store i8* %24, i8** %13
%25 = load i8*, i8** %13
%26 = icmp eq i8* %25, null
br i1 %26, label %27, label %32
27: ; preds = %21
%28 = load i8*, i8** %9
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 23, i32 %30)
store i8* null, i8** %6
br label %46
32: ; preds = %21
%33 = load i8*, i8** %10
%34 = load i32, i32* %11
%35 = call i32 @memset(i8* %33, i32 0, i32 %34)
%36 = load i8*, i8** %10
%37 = load i8*, i8** %12
%38 = load i8*, i8** %13
%39 = load i8*, i8** %12
%40 = ptrtoint i8* %38 to i64
%41 = ptrtoint i8* %39 to i64
%42 = sub i64 %40, %41
%43 = trunc i64 %42 to i32
%44 = call i32 @memcpy(i8* %36, i8* %37, i32 %43)
%45 = load i8*, i8** %12
store i8* %45, i8** %6
br label %46
46: ; preds = %32, %27, %19
%47 = load i8*, i8** %6
ret i8* %47
}

LLVM IR (-O2):
@.str = [4 x i8] c"%d\0A\00"
@.str.1 = [7 x i8] c"%d %x\0A\00"
define i8* @search_get(i8* %0, i8* nocapture %1, i8* nocapture %2, i8* %3, i32 %4) {
%6 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) %1)
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %10
8: ; preds = %5
%9 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 17)
br label %24
10: ; preds = %5
%11 = tail call i8* @strstr(i8* %6, i8* dereferenceable(1) %2)
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %17
13: ; preds = %10
%14 = load i8, i8* %2
%15 = sext i8 %14 to i32
%16 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 23, i32 %15)
br label %24
17: ; preds = %10
%18 = tail call i32 @memset(i8* %3, i32 0, i32 %4)
%19 = ptrtoint i8* %11 to i64
%20 = ptrtoint i8* %6 to i64
%21 = sub i64 %19, %20
%22 = trunc i64 %21 to i32
%23 = tail call i32 @memcpy(i8* %3, i8* %6, i32 %22)
br label %24
24: ; preds = %13, %17, %8
%25 = phi i8* [ null, %8 ], [ null, %13 ], [ %6, %17 ]
ret i8* %25
}