#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_leadcw(uint8_t *p_tlv, uint16_t n) {
  const uint8_t *p_tlv_n = tlv_find_param(p_tlv, 0xa, n);
  uint8_t i_leadcw = 0;
  int i;
  for (i = 0; i < sizeof(uint8_t); i++)
    i_leadcw |= (uint8_t)(p_tlv_n[4 + i]) << 8 * (sizeof(uint8_t) - i - 1);
  return i_leadcw;
}


x86 assembly (clang, -O0):
<ecmg_find_leadcw>:
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    $0xa,%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    118a <ecmg_find_leadcw+0x7a>
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    1142 <ecmg_find_leadcw+0x32>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ecmg_find_leadcw>:
push   %rax
mov    %esi,%edx
mov    $0xa,%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_leadcw(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 10, i32 %9)
store i32* %10, i32** %5
store i32 0, i32* %6
store i32 0, i32* %7
br label %11
11: ; preds = %31, %2
%12 = load i32, i32* %7
%13 = sext i32 %12 to i64
%14 = icmp ult i64 %13, 4
br i1 %14, label %15, label %34
15: ; preds = %11
%16 = load i32*, i32** %5
%17 = load i32, i32* %7
%18 = add nsw i32 4, %17
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i32, i32* %16, i64 %19
%21 = load i32, i32* %20
%22 = load i32, i32* %7
%23 = sext i32 %22 to i64
%24 = sub i64 4, %23
%25 = sub i64 %24, 1
%26 = mul i64 8, %25
%27 = trunc i64 %26 to i32
%28 = shl i32 %21, %27
%29 = load i32, i32* %6
%30 = or i32 %29, %28
store i32 %30, i32* %6
br label %31
31: ; preds = %15
%32 = load i32, i32* %7
%33 = add nsw i32 %32, 1
store i32 %33, i32* %7
br label %11
34: ; preds = %11
%35 = load i32, i32* %6
ret i32 %35
}

LLVM IR (-O2):
define i32 @ecmg_find_leadcw(i32* %0, i32 %1) {
%3 = tail call i32* @tlv_find_param(i32* %0, i32 10, 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
}