#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*/ memcmp(unsigned char *, unsigned char *, size_t);
int /*<<< orphan*/ printf(char *, size_t);
size_t search_bin2(unsigned char *_data, size_t _data_size,
                   unsigned char *_search_data, size_t _search_size) {
  size_t pos = 0, found = 0;
  for (pos = 0; pos < _data_size; pos++) {
    if (!memcmp(&_data[pos], _search_data, _search_size)) {
      printf("found.\nposition = 0x%x\n", pos);
      found = pos;
      break;
    }
  }
  if (found) {
    return found;
  } else {
    return 0;
  }
}


x86 assembly (clang, -O0):
<search_bin2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    11af <search_bin2+0x8f>
mov    -0x10(%rbp),%rdi
add    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1040 <memcmp@plt>
cmp    $0x0,%eax
jne    1199 <search_bin2+0x79>
mov    -0x30(%rbp),%rsi
lea    0xe79(%rip),%rdi
call   1030 <printf@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
jmp    11af <search_bin2+0x8f>
jmp    119e <search_bin2+0x7e>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    1150 <search_bin2+0x30>
cmpq   $0x0,-0x38(%rbp)
je     11c7 <search_bin2+0xa7>
mov    -0x38(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11cf <search_bin2+0xaf>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<search_bin2>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
test   %rsi,%rsi
je     115c <search_bin2+0x3c>
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%r13
xor    %ebx,%ebx
nopl   0x0(%rax)
lea    (%rbx,%r13,1),%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1040 <bcmp@plt>
test   %eax,%eax
je     1160 <search_bin2+0x40>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1140 <search_bin2+0x20>
xor    %ebx,%ebx
jmp    116f <search_bin2+0x4f>
lea    0xe99(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [24 x i8] c"found.\0Aposition = 0x%x\0A\00"
define i64 @search_bin2(i8* %0, i64 %1, i8* %2, i64 %3) {
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i64
%11 = alloca i64
store i8* %0, i8** %6
store i64 %1, i64* %7
store i8* %2, i8** %8
store i64 %3, i64* %9
store i64 0, i64* %10
store i64 0, i64* %11
store i64 0, i64* %10
br label %12
12: ; preds = %29, %4
%13 = load i64, i64* %10
%14 = load i64, i64* %7
%15 = icmp ult i64 %13, %14
br i1 %15, label %16, label %32
16: ; preds = %12
%17 = load i8*, i8** %6
%18 = load i64, i64* %10
%19 = getelementptr inbounds i8, i8* %17, i64 %18
%20 = load i8*, i8** %8
%21 = load i64, i64* %9
%22 = call i32 @memcmp(i8* %19, i8* %20, i64 %21)
%23 = icmp ne i32 %22, 0
br i1 %23, label %28, label %24
24: ; preds = %16
%25 = load i64, i64* %10
%26 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i64 %25)
%27 = load i64, i64* %10
store i64 %27, i64* %11
br label %32
28: ; preds = %16
br label %29
29: ; preds = %28
%30 = load i64, i64* %10
%31 = add i64 %30, 1
store i64 %31, i64* %10
br label %12
32: ; preds = %24, %12
%33 = load i64, i64* %11
%34 = icmp ne i64 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %32
%36 = load i64, i64* %11
store i64 %36, i64* %5
br label %38
37: ; preds = %32
store i64 0, i64* %5
br label %38
38: ; preds = %37, %35
%39 = load i64, i64* %5
ret i64 %39
}

LLVM IR (-O2):
@.str = [24 x i8] c"found.\0Aposition = 0x%x\0A\00"
define i64 @search_bin2(i8* nocapture %0, i64 %1, i8* nocapture %2, i64 %3) {
%5 = icmp eq i64 %1, 0
br i1 %5, label %16, label %6
6: ; preds = %4, %13
%7 = phi i64 [ %14, %13 ], [ 0, %4 ]
%8 = getelementptr inbounds i8, i8* %0, i64 %7
%9 = tail call i32 @bcmp(i8* %8, i8* %2, i64 %3)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %6
%12 = tail call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i64 %7)
br label %16
13: ; preds = %6
%14 = add nuw i64 %7, 1
%15 = icmp eq i64 %14, %1
br i1 %15, label %16, label %6
16: ; preds = %13, %4, %11
%17 = phi i64 [ %7, %11 ], [ 0, %4 ], [ 0, %13 ]
ret i64 %17
}