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

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


x86 assembly (clang, -O0):
<ecmg_find_nomcpdur>:
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    $0x10,%esi
call   1030 <tlv_find_param@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movslq -0x20(%rbp),%rax
cmp    $0x4,%rax
jae    118b <ecmg_find_nomcpdur+0x7b>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%ecx
add    $0x4,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rax
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    1142 <ecmg_find_nomcpdur+0x32>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ecmg_find_nomcpdur>:
push   %rax
mov    %esi,%edx
mov    $0x10,%esi
call   1030 <tlv_find_param@plt>
mov    0x20(%rax),%ecx
mov    0x28(%rax),%edx
shl    $0x18,%ecx
shl    $0x10,%edx
or     %ecx,%edx
mov    0x30(%rax),%ecx
shl    $0x8,%ecx
or     %edx,%ecx
or     0x38(%rax),%ecx
mov    %ecx,%eax
pop    %rcx
ret

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

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