#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 */
typedef int /*<<< orphan*/ uint8_t;

/* Variables and functions */
int hex_to_bin(char const *, int /*<<< orphan*/ *, int);
scalar_t__ memcmp(int /*<<< orphan*/ const *, int /*<<< orphan*/ *, int);
bool match(const uint8_t *data, int data_len, const char *hex_data) {
  uint8_t hex_data_bin[2048];
  int bin_len = hex_to_bin(hex_data, hex_data_bin, 2048);
  int min = data_len <= bin_len ? data_len : bin_len;
  int match = memcmp(data, hex_data_bin, min) == 0;
  return match;
}


x86 assembly (clang, -O0):
<match>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2030,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x2020(%rbp),%rsi
mov    $0x800,%edx
call   1040 <hex_to_bin@plt>
mov    %eax,-0x2024(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x2024(%rbp),%eax
jg     116e <match+0x4e>
mov    -0xc(%rbp),%eax
mov    %eax,-0x2030(%rbp)
jmp    117a <match+0x5a>
mov    -0x2024(%rbp),%eax
mov    %eax,-0x2030(%rbp)
mov    -0x2030(%rbp),%eax
mov    %eax,-0x2028(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x2020(%rbp),%rsi
mov    -0x2028(%rbp),%edx
call   1030 <memcmp@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x202c(%rbp)
mov    -0x202c(%rbp),%eax
add    $0x2030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<match>:
push   %r15
push   %r14
push   %rbx
sub    $0x2000,%rsp
mov    %esi,%ebx
mov    %rdi,%r14
mov    %rsp,%r15
mov    %rdx,%rdi
mov    %r15,%rsi
mov    $0x800,%edx
call   1040 <hex_to_bin@plt>
cmp    %ebx,%eax
cmovl  %eax,%ebx
mov    %r14,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1030 <memcmp@plt>
xor    %ecx,%ecx
test   %rax,%rax
sete   %cl
mov    %ecx,%eax
add    $0x2000,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @match(i32* %0, i32 %1, i8* %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca [2048 x i32]
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%11 = load i8*, i8** %6
%12 = getelementptr inbounds [2048 x i32], [2048 x i32]* %7, i64 0, i64 0
%13 = call i32 @hex_to_bin(i8* %11, i32* %12, i32 2048)
store i32 %13, i32* %8
%14 = load i32, i32* %5
%15 = load i32, i32* %8
%16 = icmp sle i32 %14, %15
br i1 %16, label %17, label %19
17: ; preds = %3
%18 = load i32, i32* %5
br label %21
19: ; preds = %3
%20 = load i32, i32* %8
br label %21
21: ; preds = %19, %17
%22 = phi i32 [ %18, %17 ], [ %20, %19 ]
store i32 %22, i32* %9
%23 = load i32*, i32** %4
%24 = getelementptr inbounds [2048 x i32], [2048 x i32]* %7, i64 0, i64 0
%25 = load i32, i32* %9
%26 = call i64 @memcmp(i32* %23, i32* %24, i32 %25)
%27 = icmp eq i64 %26, 0
%28 = zext i1 %27 to i32
store i32 %28, i32* %10
%29 = load i32, i32* %10
ret i32 %29
}

LLVM IR (-O2):
define i32 @match(i32* %0, i32 %1, i8* %2) {
%4 = alloca [2048 x i32]
%5 = bitcast [2048 x i32]* %4 to i8*
%6 = getelementptr inbounds [2048 x i32], [2048 x i32]* %4, i64 0, i64 0
%7 = call i32 @hex_to_bin(i8* %2, i32* %6, i32 2048)
%8 = icmp slt i32 %7, %1
%9 = select i1 %8, i32 %7, i32 %1
%10 = call i64 @memcmp(i32* %0, i32* %6, i32 %9)
%11 = icmp eq i64 %10, 0
%12 = zext i1 %11 to i32
ret i32 %12
}