#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 /*<<< orphan*/ read_defect_data_12_hdr_is_valid(int /*<<< orphan*/ *,
                                                    unsigned int);
unsigned int read_defect_data_12_len(int /*<<< orphan*/ *);
bool read_defect_data_12_is_valid(uint8_t *data, unsigned data_len) {
  if (!read_defect_data_12_hdr_is_valid(data, data_len))
    return false;
  if (read_defect_data_12_len(data) + 8 < data_len)
    return false;
  return true;
}


x86 assembly (clang, -O0):
<read_defect_data_12_is_valid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1040 <read_defect_data_12_hdr_is_valid@plt>
cmp    $0x0,%eax
jne    1150 <read_defect_data_12_is_valid+0x30>
movl   $0x0,-0x4(%rbp)
jmp    1178 <read_defect_data_12_is_valid+0x58>
mov    -0x10(%rbp),%rdi
call   1030 <read_defect_data_12_len@plt>
add    $0x8,%eax
cmp    -0x14(%rbp),%eax
jae    1171 <read_defect_data_12_is_valid+0x51>
movl   $0x0,-0x4(%rbp)
jmp    1178 <read_defect_data_12_is_valid+0x58>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_defect_data_12_is_valid>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
call   1040 <read_defect_data_12_hdr_is_valid@plt>
test   %eax,%eax
je     1147 <read_defect_data_12_is_valid+0x27>
mov    %rbx,%rdi
call   1030 <read_defect_data_12_len@plt>
mov    %eax,%ecx
add    $0x8,%ecx
xor    %eax,%eax
cmp    %ebp,%ecx
setae  %al
jmp    1149 <read_defect_data_12_is_valid+0x29>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @read_defect_data_12_is_valid(i32* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
%6 = load i32*, i32** %4
%7 = load i32, i32* %5
%8 = call i32 @read_defect_data_12_hdr_is_valid(i32* %6, i32 %7)
%9 = icmp ne i32 %8, 0
br i1 %9, label %11, label %10
10: ; preds = %2
store i32 0, i32* %3
br label %19
11: ; preds = %2
%12 = load i32*, i32** %4
%13 = call i32 @read_defect_data_12_len(i32* %12)
%14 = add i32 %13, 8
%15 = load i32, i32* %5
%16 = icmp ult i32 %14, %15
br i1 %16, label %17, label %18
17: ; preds = %11
store i32 0, i32* %3
br label %19
18: ; preds = %11
store i32 1, i32* %3
br label %19
19: ; preds = %18, %17, %10
%20 = load i32, i32* %3
ret i32 %20
}

LLVM IR (-O2):
define i32 @read_defect_data_12_is_valid(i32* %0, i32 %1) {
%3 = tail call i32 @read_defect_data_12_hdr_is_valid(i32* %0, i32 %1)
%4 = icmp eq i32 %3, 0
br i1 %4, label %10, label %5
5: ; preds = %2
%6 = tail call i32 @read_defect_data_12_len(i32* %0)
%7 = add i32 %6, 8
%8 = icmp uge i32 %7, %1
%9 = zext i1 %8 to i32
br label %10
10: ; preds = %5, %2
%11 = phi i32 [ 0, %2 ], [ %9, %5 ]
ret i32 %11
}