#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 */

/* Variables and functions */
int GetTLV(void *, unsigned short, int, char *, int);
int ValidQMIMessage(void *pQMIMessage, unsigned short messageLen) {
  char mandTLV[4];
  if (GetTLV(pQMIMessage, messageLen, 2, &mandTLV[0], 4) == 4) {
    if (*(unsigned short *)&mandTLV[0] != 0) {
      return *(unsigned short *)&mandTLV[2];
    } else {
      return 0;
    }
  } else {
    return -42;
  }
}


x86 assembly (clang, -O0):
<ValidQMIMessage>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %si,%ax
mov    %rdi,-0x10(%rbp)
mov    %ax,-0x12(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x12(%rbp),%ax
lea    -0x16(%rbp),%rcx
mov    $0x2,%edx
mov    $0x4,%r8d
movzwl %ax,%esi
call   1030 <GetTLV@plt>
cmp    $0x4,%eax
jne    1170 <ValidQMIMessage+0x60>
movzwl -0x16(%rbp),%eax
cmp    $0x0,%eax
je     1164 <ValidQMIMessage+0x54>
movzwl -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1177 <ValidQMIMessage+0x67>
movl   $0x0,-0x4(%rbp)
jmp    1177 <ValidQMIMessage+0x67>
movl   $0xffffffd6,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ValidQMIMessage>:
push   %rax
lea    0x4(%rsp),%rcx
mov    $0x2,%edx
mov    $0x4,%r8d
call   1030 <GetTLV@plt>
mov    %eax,%ecx
mov    $0xffffffd6,%eax
cmp    $0x4,%ecx
jne    113f <ValidQMIMessage+0x2f>
cmpw   $0x0,0x4(%rsp)
je     1141 <ValidQMIMessage+0x31>
movzwl 0x6(%rsp),%eax
pop    %rcx
ret
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
define i32 @ValidQMIMessage(i8* %0, i16 zeroext %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i16
%6 = alloca [4 x i8]
store i8* %0, i8** %4
store i16 %1, i16* %5
%7 = load i8*, i8** %4
%8 = load i16, i16* %5
%9 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
%10 = call i32 @GetTLV(i8* %7, i16 zeroext %8, i32 2, i8* %9, i32 4)
%11 = icmp eq i32 %10, 4
br i1 %11, label %12, label %24
12: ; preds = %2
%13 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
%14 = bitcast i8* %13 to i16*
%15 = load i16, i16* %14
%16 = zext i16 %15 to i32
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %23
18: ; preds = %12
%19 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 2
%20 = bitcast i8* %19 to i16*
%21 = load i16, i16* %20
%22 = zext i16 %21 to i32
store i32 %22, i32* %3
br label %25
23: ; preds = %12
store i32 0, i32* %3
br label %25
24: ; preds = %2
store i32 -42, i32* %3
br label %25
25: ; preds = %24, %23, %18
%26 = load i32, i32* %3
ret i32 %26
}

LLVM IR (-O2):
define i32 @ValidQMIMessage(i8* %0, i16 zeroext %1) {
%3 = alloca [4 x i8]
%4 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 0
%5 = call i32 @GetTLV(i8* %0, i16 zeroext %1, i32 2, i8* %4, i32 4)
%6 = icmp eq i32 %5, 4
br i1 %6, label %7, label %16
7: ; preds = %2
%8 = bitcast [4 x i8]* %3 to i16*
%9 = load i16, i16* %8
%10 = icmp eq i16 %9, 0
br i1 %10, label %16, label %11
11: ; preds = %7
%12 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 2
%13 = bitcast i8* %12 to i16*
%14 = load i16, i16* %13
%15 = zext i16 %14 to i32
br label %16
16: ; preds = %2, %7, %11
%17 = phi i32 [ %15, %11 ], [ 0, %7 ], [ -42, %2 ]
ret i32 %17
}