#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__ memcmp(char *, unsigned char *, unsigned int);
int vector_find(char *data, unsigned int data_size, unsigned char *value,
                unsigned int beg, unsigned int end) {
  for (unsigned int i = beg; i < end; ++i) {
    if (memcmp(&data[i * data_size], value, data_size) == 0)
      return i;
  }
  return -1;
}


x86 assembly (clang, -O0):
<vector_find>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    %r8d,-0x28(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x28(%rbp),%eax
jae    1180 <vector_find+0x70>
mov    -0x10(%rbp),%rdi
mov    -0x2c(%rbp),%eax
imul   -0x14(%rbp),%eax
mov    %eax,%eax
add    %rax,%rdi
mov    -0x20(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <memcmp@plt>
cmp    $0x0,%rax
jne    116d <vector_find+0x5d>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1187 <vector_find+0x77>
jmp    1172 <vector_find+0x62>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1130 <vector_find+0x20>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vector_find>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0xffffffff,%eax
cmp    %r8d,%ecx
jae    116a <vector_find+0x5a>
mov    %ecx,%ebp
mov    %rdx,%r15
mov    %esi,%r13d
mov    %rdi,%r12
mov    %ecx,%ebx
mov    %r8d,%r14d
imul   %esi,%ebp
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
add    %r12,%rdi
mov    %r15,%rsi
mov    %r13d,%edx
call   1030 <memcmp@plt>
test   %rax,%rax
je     1168 <vector_find+0x58>
add    $0x1,%rbx
add    %r13d,%ebp
cmp    %rbx,%r14
jne    1140 <vector_find+0x30>
mov    $0xffffffff,%eax
jmp    116a <vector_find+0x5a>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @vector_find(i8* %0, i32 %1, i8* %2, i32 %3, i32 %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i8* %0, i8** %7
store i32 %1, i32* %8
store i8* %2, i8** %9
store i32 %3, i32* %10
store i32 %4, i32* %11
%13 = load i32, i32* %10
store i32 %13, i32* %12
br label %14
14: ; preds = %32, %5
%15 = load i32, i32* %12
%16 = load i32, i32* %11
%17 = icmp ult i32 %15, %16
br i1 %17, label %18, label %35
18: ; preds = %14
%19 = load i8*, i8** %7
%20 = load i32, i32* %12
%21 = load i32, i32* %8
%22 = mul i32 %20, %21
%23 = zext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %19, i64 %23
%25 = load i8*, i8** %9
%26 = load i32, i32* %8
%27 = call i64 @memcmp(i8* %24, i8* %25, i32 %26)
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %18
%30 = load i32, i32* %12
store i32 %30, i32* %6
br label %36
31: ; preds = %18
br label %32
32: ; preds = %31
%33 = load i32, i32* %12
%34 = add i32 %33, 1
store i32 %34, i32* %12
br label %14
35: ; preds = %14
store i32 -1, i32* %6
br label %36
36: ; preds = %35, %29
%37 = load i32, i32* %6
ret i32 %37
}

LLVM IR (-O2):
define i32 @vector_find(i8* %0, i32 %1, i8* %2, i32 %3, i32 %4) {
%6 = icmp ult i32 %3, %4
br i1 %6, label %7, label %23
7: ; preds = %5
%8 = zext i32 %3 to i64
%9 = zext i32 %4 to i64
br label %10
10: ; preds = %7, %18
%11 = phi i64 [ %8, %7 ], [ %19, %18 ]
%12 = trunc i64 %11 to i32
%13 = mul i32 %12, %1
%14 = zext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %0, i64 %14
%16 = tail call i64 @memcmp(i8* %15, i8* %2, i32 %1)
%17 = icmp eq i64 %16, 0
br i1 %17, label %21, label %18
18: ; preds = %10
%19 = add nuw nsw i64 %11, 1
%20 = icmp eq i64 %19, %9
br i1 %20, label %23, label %10
21: ; preds = %10
%22 = trunc i64 %11 to i32
br label %23
23: ; preds = %18, %21, %5
%24 = phi i32 [ -1, %5 ], [ %22, %21 ], [ -1, %18 ]
ret i32 %24
}