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

/* Variables and functions */
int *tlv_find_param(int *, int, int /*<<< orphan*/);
uint8_t ecmg_find_sectiontspkt(uint8_t *p_tlv, uint16_t n) {
  const uint8_t *p_tlv_n = tlv_find_param(p_tlv, 0x2, n);
  uint8_t i_sectiontspkt = (uint8_t)(p_tlv_n[4]) << 8 * (sizeof(uint8_t) - 1);
  int i;
  for (i = 1; i < sizeof(uint8_t); i++)
    i_sectiontspkt |= (uint8_t)(p_tlv_n[4 + i])
                      << 8 * (sizeof(uint8_t) - i - 1);
  return i_sectiontspkt;
}


x86 assembly (clang, -O0):
<ecmg_find_sectiontspkt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%edx
mov    $0x2,%esi
call   1030 <tlv_find_param@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%eax
shl    $0x18,%eax
mov    %eax,-0x1c(%rbp)
movl   $0x1,-0x20(%rbp)
movslq -0x20(%rbp),%rax
cmp    $0x4,%rax
jae    1190 <ecmg_find_sectiontspkt+0x80>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%ecx
add    $0x4,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%eax
movslq -0x20(%rbp),%rdx
mov    $0x4,%ecx
sub    %rdx,%rcx
sub    $0x1,%rcx
shl    $0x3,%rcx
shl    %cl,%eax
or     -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1148 <ecmg_find_sectiontspkt+0x38>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ecmg_find_sectiontspkt>:
push   %rax
mov    %esi,%edx
mov    $0x2,%esi
call   1030 <tlv_find_param@plt>
mov    0x10(%rax),%ecx
mov    0x14(%rax),%edx
shl    $0x18,%ecx
shl    $0x10,%edx
or     %ecx,%edx
mov    0x18(%rax),%ecx
shl    $0x8,%ecx
or     %edx,%ecx
or     0x1c(%rax),%ecx
mov    %ecx,%eax
pop    %rcx
ret

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

LLVM IR (-O2):
define i32 @ecmg_find_sectiontspkt(i32* %0, i32 %1) {
%3 = tail call i32* @tlv_find_param(i32* %0, i32 2, i32 %1)
%4 = getelementptr inbounds i32, i32* %3, i64 4
%5 = load i32, i32* %4
%6 = shl i32 %5, 24
%7 = getelementptr inbounds i32, i32* %3, i64 5
%8 = load i32, i32* %7
%9 = shl i32 %8, 16
%10 = or i32 %9, %6
%11 = getelementptr inbounds i32, i32* %3, i64 6
%12 = load i32, i32* %11
%13 = shl i32 %12, 8
%14 = or i32 %13, %10
%15 = getelementptr inbounds i32, i32* %3, i64 7
%16 = load i32, i32* %15
%17 = or i32 %16, %14
ret i32 %17
}