#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;
typedef int uint16_t;

/* Variables and functions */
int tlv_get_length(int /*<<< orphan*/ const *);
int tlv_get_type(int /*<<< orphan*/ const *);
bool emmg_validate_param(const uint8_t *p_tlv_n) {
  static const uint16_t pi_emmg_params_minlength[] = {0, 4, 1, 2, 2,
                                                      1, 2, 1, 2};
  static const uint16_t pi_emmg_params_manlength[] = {0, 4, 1, 2, 2,
                                                      1, 2, 1, 2};
  uint16_t i_type = tlv_get_type(p_tlv_n);
  uint16_t i_length = tlv_get_length(p_tlv_n);
  if (i_type <= 0x0008 && i_type != 0x0005) {
    if (i_length < pi_emmg_params_minlength[i_type] ||
        i_length > pi_emmg_params_manlength[i_type])
      return false;
  } else if (i_type == 0x7000) {
    if (i_length < 2)
      return false;
  }
  return true;
}


x86 assembly (clang, -O0):
<emmg_validate_param>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <tlv_get_type@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <tlv_get_length@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x8,-0x14(%rbp)
jg     1197 <emmg_validate_param+0x77>
cmpl   $0x5,-0x14(%rbp)
je     1197 <emmg_validate_param+0x77>
mov    -0x18(%rbp),%eax
movslq -0x14(%rbp),%rdx
lea    0xe9a(%rip),%rcx
cmp    (%rcx,%rdx,4),%eax
jl     1186 <emmg_validate_param+0x66>
mov    -0x18(%rbp),%eax
movslq -0x14(%rbp),%rdx
lea    0xeb3(%rip),%rcx
cmp    (%rcx,%rdx,4),%eax
jle    1192 <emmg_validate_param+0x72>
movl   $0x0,-0x4(%rbp)
jmp    11cb <emmg_validate_param+0xab>
jmp    11c4 <emmg_validate_param+0xa4>
cmpl   $0x7000,-0x14(%rbp)
jne    11bf <emmg_validate_param+0x9f>
cmpl   $0x2,-0x18(%rbp)
jge    11ba <emmg_validate_param+0x9a>
movl   $0x0,-0x4(%rbp)
jmp    11cb <emmg_validate_param+0xab>
jmp    11bf <emmg_validate_param+0x9f>
jmp    11c4 <emmg_validate_param+0xa4>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<emmg_validate_param>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1030 <tlv_get_type@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1040 <tlv_get_length@plt>
mov    %eax,%ecx
cmp    $0x8,%ebp
jg     1156 <emmg_validate_param+0x36>
cmp    $0x5,%ebp
je     1156 <emmg_validate_param+0x36>
movslq %ebp,%rdx
lea    0xeb5(%rip),%rsi
xor    %eax,%eax
cmp    (%rsi,%rdx,4),%ecx
jl     116a <emmg_validate_param+0x4a>
jle    1165 <emmg_validate_param+0x45>
jmp    116a <emmg_validate_param+0x4a>
cmp    $0x7000,%ebp
jne    1165 <emmg_validate_param+0x45>
xor    %eax,%eax
cmp    $0x2,%ecx
jl     116a <emmg_validate_param+0x4a>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@emmg_validate_param.pi_emmg_params_minlength = internal constant [9 x i32] [i32 0, i32 4, i32 1, i32 2, i32 2, i32 1, i32 2, i32 1, i32 2]
@emmg_validate_param.pi_emmg_params_manlength = internal constant [9 x i32] [i32 0, i32 4, i32 1, i32 2, i32 2, i32 1, i32 2, i32 1, i32 2]
define i32 @emmg_validate_param(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
store i32* %0, i32** %3
%6 = load i32*, i32** %3
%7 = call i32 @tlv_get_type(i32* %6)
store i32 %7, i32* %4
%8 = load i32*, i32** %3
%9 = call i32 @tlv_get_length(i32* %8)
store i32 %9, i32* %5
%10 = load i32, i32* %4
%11 = icmp sle i32 %10, 8
br i1 %11, label %12, label %31
12: ; preds = %1
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, 5
br i1 %14, label %15, label %31
15: ; preds = %12
%16 = load i32, i32* %5
%17 = load i32, i32* %4
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [9 x i32], [9 x i32]* @emmg_validate_param.pi_emmg_params_minlength, i64 0, i64 %18
%20 = load i32, i32* %19
%21 = icmp slt i32 %16, %20
br i1 %21, label %29, label %22
22: ; preds = %15
%23 = load i32, i32* %5
%24 = load i32, i32* %4
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [9 x i32], [9 x i32]* @emmg_validate_param.pi_emmg_params_manlength, i64 0, i64 %25
%27 = load i32, i32* %26
%28 = icmp sgt i32 %23, %27
br i1 %28, label %29, label %30
29: ; preds = %22, %15
store i32 0, i32* %2
br label %41
30: ; preds = %22
br label %40
31: ; preds = %12, %1
%32 = load i32, i32* %4
%33 = icmp eq i32 %32, 28672
br i1 %33, label %34, label %39
34: ; preds = %31
%35 = load i32, i32* %5
%36 = icmp slt i32 %35, 2
br i1 %36, label %37, label %38
37: ; preds = %34
store i32 0, i32* %2
br label %41
38: ; preds = %34
br label %39
39: ; preds = %38, %31
br label %40
40: ; preds = %39, %30
store i32 1, i32* %2
br label %41
41: ; preds = %40, %37, %29
%42 = load i32, i32* %2
ret i32 %42
}

LLVM IR (-O2):
@emmg_validate_param.pi_emmg_params_manlength = internal unnamed_addr constant [9 x i32] [i32 0, i32 4, i32 1, i32 2, i32 2, i32 1, i32 2, i32 1, i32 2]
define i32 @emmg_validate_param(i32* %0) {
%2 = tail call i32 @tlv_get_type(i32* %0)
%3 = tail call i32 @tlv_get_length(i32* %0)
%4 = icmp slt i32 %2, 9
%5 = icmp ne i32 %2, 5
%6 = and i1 %4, %5
br i1 %6, label %7, label %16
7: ; preds = %1
%8 = sext i32 %2 to i64
%9 = getelementptr inbounds [9 x i32], [9 x i32]* @emmg_validate_param.pi_emmg_params_manlength, i64 0, i64 %8
%10 = load i32, i32* %9
%11 = icmp slt i32 %3, %10
br i1 %11, label %21, label %12
12: ; preds = %7
%13 = getelementptr inbounds [9 x i32], [9 x i32]* @emmg_validate_param.pi_emmg_params_manlength, i64 0, i64 %8
%14 = load i32, i32* %13
%15 = icmp sgt i32 %3, %14
br i1 %15, label %21, label %20
16: ; preds = %1
%17 = icmp eq i32 %2, 28672
%18 = icmp slt i32 %3, 2
%19 = select i1 %17, i1 %18, i1 false
br i1 %19, label %21, label %20
20: ; preds = %16, %12
br label %21
21: ; preds = %16, %7, %12, %20
%22 = phi i32 [ 1, %20 ], [ 0, %12 ], [ 0, %7 ], [ 0, %16 ]
ret i32 %22
}