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

/* Variables and functions */
int prv_getHeaderLength(uint16_t id, size_t dataLen) {
  int length;
  length = 2;
  if (id > 0xFF) {
    length += 1;
  }
  if (dataLen > 0xFFFF) {
    length += 3;
  } else if (dataLen > 0xFF) {
    length += 2;
  } else if (dataLen > 7) {
    length += 1;
  }
  return length;
}


x86 assembly (clang, -O0):
<prv_getHeaderLength>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x2,-0x14(%rbp)
cmpl   $0xff,-0x4(%rbp)
jle    1128 <prv_getHeaderLength+0x28>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
cmpq   $0xffff,-0x10(%rbp)
jbe    1144 <prv_getHeaderLength+0x44>
mov    -0x14(%rbp),%eax
add    $0x3,%eax
mov    %eax,-0x14(%rbp)
jmp    117e <prv_getHeaderLength+0x7e>
cmpq   $0xff,-0x10(%rbp)
jbe    1160 <prv_getHeaderLength+0x60>
mov    -0x14(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x14(%rbp)
jmp    1179 <prv_getHeaderLength+0x79>
cmpq   $0x7,-0x10(%rbp)
jbe    1174 <prv_getHeaderLength+0x74>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1179 <prv_getHeaderLength+0x79>
jmp    117e <prv_getHeaderLength+0x7e>
mov    -0x14(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<prv_getHeaderLength>:
mov    $0x3,%eax
cmp    $0xffff,%rsi
ja     1125 <prv_getHeaderLength+0x25>
mov    $0x2,%eax
cmp    $0xff,%rsi
ja     1125 <prv_getHeaderLength+0x25>
xor    %eax,%eax
cmp    $0x8,%rsi
setae  %al
xor    %ecx,%ecx
cmp    $0x100,%edi
setge  %cl
add    %ecx,%eax
add    $0x2,%eax
ret

LLVM IR (-O0):
define i32 @prv_getHeaderLength(i32 %0, i64 %1) {
%3 = alloca i32
%4 = alloca i64
%5 = alloca i32
store i32 %0, i32* %3
store i64 %1, i64* %4
store i32 2, i32* %5
%6 = load i32, i32* %3
%7 = icmp sgt i32 %6, 255
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = load i32, i32* %5
%10 = add nsw i32 %9, 1
store i32 %10, i32* %5
br label %11
11: ; preds = %8, %2
%12 = load i64, i64* %4
%13 = icmp ugt i64 %12, 65535
br i1 %13, label %14, label %17
14: ; preds = %11
%15 = load i32, i32* %5
%16 = add nsw i32 %15, 3
store i32 %16, i32* %5
br label %31
17: ; preds = %11
%18 = load i64, i64* %4
%19 = icmp ugt i64 %18, 255
br i1 %19, label %20, label %23
20: ; preds = %17
%21 = load i32, i32* %5
%22 = add nsw i32 %21, 2
store i32 %22, i32* %5
br label %30
23: ; preds = %17
%24 = load i64, i64* %4
%25 = icmp ugt i64 %24, 7
br i1 %25, label %26, label %29
26: ; preds = %23
%27 = load i32, i32* %5
%28 = add nsw i32 %27, 1
store i32 %28, i32* %5
br label %29
29: ; preds = %26, %23
br label %30
30: ; preds = %29, %20
br label %31
31: ; preds = %30, %14
%32 = load i32, i32* %5
ret i32 %32
}

LLVM IR (-O2):
define i32 @prv_getHeaderLength(i32 %0, i64 %1) {
%3 = icmp ugt i64 %1, 65535
br i1 %3, label %9, label %4
4: ; preds = %2
%5 = icmp ugt i64 %1, 255
br i1 %5, label %9, label %6
6: ; preds = %4
%7 = icmp ugt i64 %1, 7
%8 = zext i1 %7 to i32
br label %9
9: ; preds = %4, %2, %6
%10 = phi i32 [ %8, %6 ], [ 3, %2 ], [ 2, %4 ]
%11 = icmp sgt i32 %0, 255
%12 = select i1 %11, i32 3, i32 2
%13 = add nuw nsw i32 %12, %10
ret i32 %13
}