#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);
char *strstr(char *, char *);
int filter(char *buf, int searchLen, char *search, int returnLen,
           char *returnVal) {
  char *s = strstr(buf, search);
  if (s != NULL) {
    int index = s - buf + searchLen;
    while (buf[index] == ' ') {
      index++;
    }
    memcpy(returnVal + 2, &buf[index], returnLen);
    return 1;
  } else {
    memcpy(returnVal + 2, "00000000", 8);
    return 0;
  }
}


x86 assembly (clang, -O0):
<filter>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    %r8,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <strstr@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     11b5 <filter+0x95>
mov    -0x38(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
movslq -0x14(%rbp),%rcx
add    %rcx,%rax
mov    %eax,-0x3c(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
jne    118e <filter+0x6e>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    116b <filter+0x4b>
mov    -0x30(%rbp),%rdi
add    $0x2,%rdi
mov    -0x10(%rbp),%rsi
movslq -0x3c(%rbp),%rax
add    %rax,%rsi
mov    -0x24(%rbp),%edx
call   1030 <memcpy@plt>
movl   $0x1,-0x4(%rbp)
jmp    11d5 <filter+0xb5>
mov    -0x30(%rbp),%rdi
add    $0x2,%rdi
lea    0xe3c(%rip),%rsi
mov    $0x8,%edx
call   1030 <memcpy@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<filter>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %r8,%rbx
mov    %ecx,%r14d
mov    %esi,%r15d
mov    %rdi,%rbp
mov    %rdx,%rsi
call   1040 <strstr@plt>
test   %rax,%rax
je     1170 <filter+0x50>
sub    %ebp,%eax
add    %r15d,%eax
cltq
lea    (%rax,%rbp,1),%rsi
add    $0xffffffffffffffff,%rsi
nop
cmpb   $0x20,0x1(%rsi)
lea    0x1(%rsi),%rsi
je     1150 <filter+0x30>
add    $0x2,%rbx
mov    %rbx,%rdi
mov    %r14d,%edx
call   1030 <memcpy@plt>
mov    $0x1,%eax
jmp    118a <filter+0x6a>
add    $0x2,%rbx
lea    0xe85(%rip),%rsi
mov    %rbx,%rdi
mov    $0x8,%edx
call   1030 <memcpy@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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