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

/* Variables and functions */
unsigned get_pkt_len_len(uint8_t newfmt, uint8_t *p, int isprimary) {
  if (newfmt) {
    if (((*p) >= 224 && (*p) < 255)) {
      return (isprimary) ? 1 : 2;
    }
    return ((p[0] < 192) ? 1 : (p[0] < 224) ? 2 : 5);
  } else {
    switch (*--p & 0x3) {
    case 0:
      return 1;
    case 1:
      return 2;
    case 2:
      return 4;
    default:
      return 0;
    }
  }
}


x86 assembly (clang, -O0):
<get_pkt_len_len>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     1197 <get_pkt_len_len+0x97>
mov    -0x10(%rbp),%rax
cmpl   $0xe0,(%rax)
jl     1153 <get_pkt_len_len+0x53>
mov    -0x10(%rbp),%rax
cmpl   $0xff,(%rax)
jge    1153 <get_pkt_len_len+0x53>
mov    -0x14(%rbp),%edx
mov    $0x2,%eax
mov    $0x1,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    1207 <get_pkt_len_len+0x107>
mov    -0x10(%rbp),%rax
cmpl   $0xc0,(%rax)
jge    1170 <get_pkt_len_len+0x70>
mov    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    118c <get_pkt_len_len+0x8c>
mov    -0x10(%rbp),%rax
mov    (%rax),%edx
mov    $0x5,%eax
mov    $0x2,%ecx
cmp    $0xe0,%edx
cmovl  %ecx,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1207 <get_pkt_len_len+0x107>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0xfffffffffffffffc,%rcx
mov    %rcx,-0x10(%rbp)
mov    -0x4(%rax),%eax
and    $0x3,%eax
mov    %eax,-0x1c(%rbp)
je     11dc <get_pkt_len_len+0xdc>
jmp    11ba <get_pkt_len_len+0xba>
mov    -0x1c(%rbp),%eax
sub    $0x1,%eax
je     11e8 <get_pkt_len_len+0xe8>
jmp    11cb <get_pkt_len_len+0xcb>
mov    -0x1c(%rbp),%eax
sub    $0x2,%eax
je     11f4 <get_pkt_len_len+0xf4>
jmp    1200 <get_pkt_len_len+0x100>
movl   $0x1,-0x4(%rbp)
jmp    1207 <get_pkt_len_len+0x107>
movl   $0x2,-0x4(%rbp)
jmp    1207 <get_pkt_len_len+0x107>
movl   $0x4,-0x4(%rbp)
jmp    1207 <get_pkt_len_len+0x107>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_pkt_len_len>:
test   %edi,%edi
je     111d <get_pkt_len_len+0x1d>
mov    (%rsi),%eax
lea    -0xe0(%rax),%ecx
cmp    $0x1e,%ecx
ja     1135 <get_pkt_len_len+0x35>
cmp    $0x1,%edx
mov    $0x1,%eax
adc    $0x0,%eax
ret
mov    -0x4(%rsi),%ecx
and    $0x3,%ecx
xor    %eax,%eax
cmp    $0x3,%ecx
je     1134 <get_pkt_len_len+0x34>
lea    0xecf(%rip),%rax
mov    (%rax,%rcx,4),%eax
ret
xor    %ecx,%ecx
cmp    $0xe0,%eax
setge  %cl
cmp    $0xc0,%eax
lea    0x2(%rcx,%rcx,2),%ecx
mov    $0x1,%eax
cmovge %ecx,%eax
ret

LLVM IR (-O0):
define i32 @get_pkt_len_len(i32 %0, i32* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
store i32 %0, i32* %5
store i32* %1, i32** %6
store i32 %2, i32* %7
%8 = load i32, i32* %5
%9 = icmp ne i32 %8, 0
br i1 %9, label %10, label %38
10: ; preds = %3
%11 = load i32*, i32** %6
%12 = load i32, i32* %11
%13 = icmp sge i32 %12, 224
br i1 %13, label %14, label %23
14: ; preds = %10
%15 = load i32*, i32** %6
%16 = load i32, i32* %15
%17 = icmp slt i32 %16, 255
br i1 %17, label %18, label %23
18: ; preds = %14
%19 = load i32, i32* %7
%20 = icmp ne i32 %19, 0
%21 = zext i1 %20 to i64
%22 = select i1 %20, i32 1, i32 2
store i32 %22, i32* %4
br label %47
23: ; preds = %14, %10
%24 = load i32*, i32** %6
%25 = getelementptr inbounds i32, i32* %24, i64 0
%26 = load i32, i32* %25
%27 = icmp slt i32 %26, 192
br i1 %27, label %28, label %29
28: ; preds = %23
br label %36
29: ; preds = %23
%30 = load i32*, i32** %6
%31 = getelementptr inbounds i32, i32* %30, i64 0
%32 = load i32, i32* %31
%33 = icmp slt i32 %32, 224
%34 = zext i1 %33 to i64
%35 = select i1 %33, i32 2, i32 5
br label %36
36: ; preds = %29, %28
%37 = phi i32 [ 1, %28 ], [ %35, %29 ]
store i32 %37, i32* %4
br label %47
38: ; preds = %3
%39 = load i32*, i32** %6
%40 = getelementptr inbounds i32, i32* %39, i32 -1
store i32* %40, i32** %6
%41 = load i32, i32* %40
%42 = and i32 %41, 3
switch i32 %42, label %46 [
i32 0, label %43
i32 1, label %44
i32 2, label %45
]
43: ; preds = %38
store i32 1, i32* %4
br label %47
44: ; preds = %38
store i32 2, i32* %4
br label %47
45: ; preds = %38
store i32 4, i32* %4
br label %47
46: ; preds = %38
store i32 0, i32* %4
br label %47
47: ; preds = %46, %45, %44, %43, %36, %18
%48 = load i32, i32* %4
ret i32 %48
}

LLVM IR (-O2):
@switch.table.get_pkt_len_len = [3 x i32] [i32 1, i32 2, i32 4]
define i32 @get_pkt_len_len(i32 %0, i32* nocapture %1, i32 %2) {
%4 = icmp eq i32 %0, 0
br i1 %4, label %17, label %5
5: ; preds = %3
%6 = load i32, i32* %1
%7 = add i32 %6, -224
%8 = icmp ult i32 %7, 31
br i1 %8, label %9, label %12
9: ; preds = %5
%10 = icmp eq i32 %2, 0
%11 = select i1 %10, i32 2, i32 1
br label %26
12: ; preds = %5
%13 = icmp slt i32 %6, 192
%14 = icmp slt i32 %6, 224
%15 = select i1 %14, i32 2, i32 5
%16 = select i1 %13, i32 1, i32 %15
br label %26
17: ; preds = %3
%18 = getelementptr inbounds i32, i32* %1, i64 -1
%19 = load i32, i32* %18
%20 = and i32 %19, 3
%21 = icmp eq i32 %20, 3
br i1 %21, label %26, label %22
22: ; preds = %17
%23 = zext i32 %20 to i64
%24 = getelementptr inbounds [3 x i32], [3 x i32]* @switch.table.get_pkt_len_len, i64 0, i64 %23
%25 = load i32, i32* %24
br label %26
26: ; preds = %17, %22, %12, %9
%27 = phi i32 [ %11, %9 ], [ %16, %12 ], [ %25, %22 ], [ 0, %17 ]
ret i32 %27
}