#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 log_sense_data_len(int /*<<< orphan*/ *);
scalar_t__ log_sense_subpage_code(int /*<<< orphan*/ *);
int /*<<< orphan*/ log_sense_subpage_format(int /*<<< orphan*/ *);
bool log_sense_is_valid(uint8_t *data, unsigned data_len) {
  if (data_len < 4)
    return false;
  if (!log_sense_subpage_format(data) && log_sense_subpage_code(data) != 0)
    return false;
  if (log_sense_data_len(data) + 4 < data_len)
    return false;
  return true;
}


x86 assembly (clang, -O0):
<log_sense_is_valid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpl   $0x4,-0x14(%rbp)
jae    1155 <log_sense_is_valid+0x25>
movl   $0x0,-0x4(%rbp)
jmp    11ae <log_sense_is_valid+0x7e>
mov    -0x10(%rbp),%rdi
call   1040 <log_sense_subpage_format@plt>
cmp    $0x0,%eax
jne    1186 <log_sense_is_valid+0x56>
mov    -0x10(%rbp),%rdi
call   1050 <log_sense_subpage_code@plt>
cmp    $0x0,%rax
je     1186 <log_sense_is_valid+0x56>
movl   $0x0,-0x4(%rbp)
jmp    11ae <log_sense_is_valid+0x7e>
mov    -0x10(%rbp),%rdi
call   1030 <log_sense_data_len@plt>
add    $0x4,%eax
cmp    -0x14(%rbp),%eax
jae    11a7 <log_sense_is_valid+0x77>
movl   $0x0,-0x4(%rbp)
jmp    11ae <log_sense_is_valid+0x7e>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<log_sense_is_valid>:
push   %rbp
push   %r14
push   %rbx
xor    %ebp,%ebp
cmp    $0x4,%esi
jb     116b <log_sense_is_valid+0x3b>
mov    %esi,%r14d
mov    %rdi,%rbx
call   1040 <log_sense_subpage_format@plt>
test   %eax,%eax
jne    1157 <log_sense_is_valid+0x27>
mov    %rbx,%rdi
call   1050 <log_sense_subpage_code@plt>
test   %rax,%rax
jne    116b <log_sense_is_valid+0x3b>
mov    %rbx,%rdi
call   1030 <log_sense_data_len@plt>
add    $0x4,%eax
xor    %ebp,%ebp
cmp    %r14d,%eax
setae  %bpl
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @log_sense_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* %5
%7 = icmp ult i32 %6, 4
br i1 %7, label %8, label %9
8: ; preds = %2
store i32 0, i32* %3
br label %26
9: ; preds = %2
%10 = load i32*, i32** %4
%11 = call i32 @log_sense_subpage_format(i32* %10)
%12 = icmp ne i32 %11, 0
br i1 %12, label %18, label %13
13: ; preds = %9
%14 = load i32*, i32** %4
%15 = call i64 @log_sense_subpage_code(i32* %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %13
store i32 0, i32* %3
br label %26
18: ; preds = %13, %9
%19 = load i32*, i32** %4
%20 = call i32 @log_sense_data_len(i32* %19)
%21 = add nsw i32 %20, 4
%22 = load i32, i32* %5
%23 = icmp ult i32 %21, %22
br i1 %23, label %24, label %25
24: ; preds = %18
store i32 0, i32* %3
br label %26
25: ; preds = %18
store i32 1, i32* %3
br label %26
26: ; preds = %25, %24, %17, %8
%27 = load i32, i32* %3
ret i32 %27
}

LLVM IR (-O2):
define i32 @log_sense_is_valid(i32* %0, i32 %1) {
%3 = icmp ult i32 %1, 4
br i1 %3, label %15, label %4
4: ; preds = %2
%5 = tail call i32 @log_sense_subpage_format(i32* %0)
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %4
%8 = tail call i64 @log_sense_subpage_code(i32* %0)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %15
10: ; preds = %7, %4
%11 = tail call i32 @log_sense_data_len(i32* %0)
%12 = add nsw i32 %11, 4
%13 = icmp uge i32 %12, %1
%14 = zext i1 %13 to i32
br label %15
15: ; preds = %10, %7, %2
%16 = phi i32 [ 0, %2 ], [ 0, %7 ], [ %14, %10 ]
ret i32 %16
}