#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 compressed_parse_bit_length(unsigned char *);
int /*<<< orphan*/ get_flag_value(unsigned char);
int get_packet_type(unsigned char);
int /*<<< orphan*/ printf(char *);
int preparse_packet(unsigned char *raw_packet_header, int packet_length,
                    int *soft_packet_headers, int *soft_packet_types) {
  int position = 0;
  int nb_packets = 0;
  int bitlength = 0;
  while ((position < packet_length) & (nb_packets < 10)) {
    soft_packet_headers[nb_packets] = position;
    switch (get_packet_type(raw_packet_header[position])) {
    case 0xF:
      position += 4;
      soft_packet_types[nb_packets] = 0xF;
      break;
    case 0xE:
      if (get_flag_value(raw_packet_header[position])) {
        position += 8;
        printf("Samples were dropped!\n");
      } else {
        position += 6;
      }
      soft_packet_types[nb_packets] = 0xE;
      break;
    case 0xD:
      position += 5;
      soft_packet_types[nb_packets] = 0xD;
      break;
    case 0xC:
      bitlength =
          compressed_parse_bit_length(&(raw_packet_header[6 + position]));
      position += 8;
      position += (int)(bitlength / 8);
      if (bitlength % 8)
        position += 1;
      soft_packet_types[nb_packets] = 0xC;
      break;
    case 0xB:
      position += 9;
      soft_packet_types[nb_packets] = 0xB;
      break;
    case 0xA:
      if (get_flag_value(raw_packet_header[position]))
        position += 7;
      else
        position += 5;
      soft_packet_types[nb_packets] = 0xA;
      break;
    case 0x9:
      position += 4;
      soft_packet_types[nb_packets] = 0x9;
      break;
    case 0x0:
    default:
      printf("Pre-Parsing error!\n");
      return 0;
    }
    nb_packets = nb_packets + 1;
  }
  return nb_packets;
}


x86 assembly (clang, -O0):
<preparse_packet>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x14(%rbp),%eax
setl   %al
and    $0x1,%al
movzbl %al,%eax
cmpl   $0xa,-0x30(%rbp)
setl   %cl
and    $0x1,%cl
movzbl %cl,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     136b <preparse_packet+0x22b>
mov    -0x2c(%rbp),%edx
mov    -0x20(%rbp),%rax
movslq -0x30(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movzbl (%rax,%rcx,1),%edi
call   1040 <get_packet_type@plt>
mov    %eax,%ecx
mov    %rcx,-0x40(%rbp)
sub    $0xf,%eax
ja     1345 <preparse_packet+0x205>
mov    -0x40(%rbp),%rax
lea    0xe35(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x2c(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%rax
movslq -0x30(%rbp),%rcx
movl   $0xf,(%rax,%rcx,4)
jmp    135d <preparse_packet+0x21d>
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movzbl (%rax,%rcx,1),%edi
call   1060 <get_flag_value@plt>
cmp    $0x0,%eax
je     1225 <preparse_packet+0xe5>
mov    -0x2c(%rbp),%eax
add    $0x8,%eax
mov    %eax,-0x2c(%rbp)
lea    0xe25(%rip),%rdi
call   1050 <printf@plt>
jmp    122e <preparse_packet+0xee>
mov    -0x2c(%rbp),%eax
add    $0x6,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%rax
movslq -0x30(%rbp),%rcx
movl   $0xe,(%rax,%rcx,4)
jmp    135d <preparse_packet+0x21d>
mov    -0x2c(%rbp),%eax
add    $0x5,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%rax
movslq -0x30(%rbp),%rcx
movl   $0xd,(%rax,%rcx,4)
jmp    135d <preparse_packet+0x21d>
mov    -0x10(%rbp),%rdi
mov    -0x2c(%rbp),%eax
add    $0x6,%eax
cltq
add    %rax,%rdi
call   1030 <compressed_parse_bit_length@plt>
mov    %eax,-0x34(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x8,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x34(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
add    -0x2c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x34(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     12ad <preparse_packet+0x16d>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%rax
movslq -0x30(%rbp),%rcx
movl   $0xc,(%rax,%rcx,4)
jmp    135d <preparse_packet+0x21d>
mov    -0x2c(%rbp),%eax
add    $0x9,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%rax
movslq -0x30(%rbp),%rcx
movl   $0xb,(%rax,%rcx,4)
jmp    135d <preparse_packet+0x21d>
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movzbl (%rax,%rcx,1),%edi
call   1060 <get_flag_value@plt>
cmp    $0x0,%eax
je     1306 <preparse_packet+0x1c6>
mov    -0x2c(%rbp),%eax
add    $0x7,%eax
mov    %eax,-0x2c(%rbp)
jmp    130f <preparse_packet+0x1cf>
mov    -0x2c(%rbp),%eax
add    $0x5,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%rax
movslq -0x30(%rbp),%rcx
movl   $0xa,(%rax,%rcx,4)
jmp    135d <preparse_packet+0x21d>
mov    -0x2c(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%rax
movslq -0x30(%rbp),%rcx
movl   $0x9,(%rax,%rcx,4)
jmp    135d <preparse_packet+0x21d>
jmp    1345 <preparse_packet+0x205>
lea    0xd0b(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1371 <preparse_packet+0x231>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    116c <preparse_packet+0x2c>
mov    -0x30(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<preparse_packet>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,(%rsp)
test   %esi,%esi
jle    127b <preparse_packet+0x13b>
mov    %rdx,%r15
mov    %esi,%r13d
mov    %rdi,%rbx
xor    %ebp,%ebp
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14d,(%r15,%rbp,4)
movslq %r14d,%r12
movzbl (%rbx,%r12,1),%edi
call   1050 <get_packet_type@plt>
add    $0xfffffff7,%eax
cmp    $0x6,%eax
ja     126f <preparse_packet+0x12f>
lea    0xe6c(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
add    $0x4,%r14d
mov    $0x9,%eax
jmp    1250 <preparse_packet+0x110>
movzbl (%rbx,%r12,1),%edi
call   1060 <get_flag_value@plt>
xor    %ecx,%ecx
test   %eax,%eax
setne  %cl
lea    (%r14,%rcx,2),%r14d
add    $0x5,%r14d
mov    $0xa,%eax
jmp    1250 <preparse_packet+0x110>
add    $0x9,%r14d
mov    $0xb,%eax
jmp    1250 <preparse_packet+0x110>
lea    (%r12,%rbx,1),%rdi
add    $0x6,%rdi
call   1040 <compressed_parse_bit_length@plt>
lea    0x7(%rax),%ecx
test   %eax,%eax
cmovns %eax,%ecx
sar    $0x3,%ecx
add    %ecx,%r14d
and    $0x7,%eax
cmp    $0x1,%eax
sbb    $0xffffffff,%r14d
add    $0x8,%r14d
mov    $0xc,%eax
jmp    1250 <preparse_packet+0x110>
add    $0x5,%r14d
mov    $0xd,%eax
jmp    1250 <preparse_packet+0x110>
movzbl (%rbx,%r12,1),%edi
call   1060 <get_flag_value@plt>
test   %eax,%eax
je     123f <preparse_packet+0xff>
add    $0x8,%r14d
lea    0xdef(%rip),%rdi
call   1030 <puts@plt>
jmp    1243 <preparse_packet+0x103>
add    $0x4,%r14d
mov    $0xf,%eax
jmp    1250 <preparse_packet+0x110>
add    $0x6,%r14d
mov    $0xe,%eax
nopl   0x0(%rax,%rax,1)
mov    (%rsp),%rcx
mov    %eax,(%rcx,%rbp,4)
lea    0x1(%rbp),%rax
cmp    %r13d,%r14d
jge    127d <preparse_packet+0x13d>
cmp    $0x9,%rbp
mov    %rax,%rbp
jb     1170 <preparse_packet+0x30>
jmp    127d <preparse_packet+0x13d>
lea    0xdbc(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [23 x i8] c"Samples were dropped!\0A\00"
@.str.1 = [20 x i8] c"Pre-Parsing error!\0A\00"
define i32 @preparse_packet(i8* %0, i32 %1, i32* %2, i32* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i8* %0, i8** %6
store i32 %1, i32* %7
store i32* %2, i32** %8
store i32* %3, i32** %9
store i32 0, i32* %10
store i32 0, i32* %11
store i32 0, i32* %12
br label %13
13: ; preds = %129, %4
%14 = load i32, i32* %10
%15 = load i32, i32* %7
%16 = icmp slt i32 %14, %15
%17 = zext i1 %16 to i32
%18 = load i32, i32* %11
%19 = icmp slt i32 %18, 10
%20 = zext i1 %19 to i32
%21 = and i32 %17, %20
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %132
23: ; preds = %13
%24 = load i32, i32* %10
%25 = load i32*, i32** %8
%26 = load i32, i32* %11
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i32, i32* %25, i64 %27
store i32 %24, i32* %28
%29 = load i8*, i8** %6
%30 = load i32, i32* %10
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %29, i64 %31
%33 = load i8, i8* %32
%34 = call i32 @get_packet_type(i8 zeroext %33)
switch i32 %34, label %127 [
i32 15, label %35
i32 14, label %42
i32 13, label %62
i32 12, label %69
i32 11, label %93
i32 10, label %100
i32 9, label %119
i32 0, label %126
]
35: ; preds = %23
%36 = load i32, i32* %10
%37 = add nsw i32 %36, 4
store i32 %37, i32* %10
%38 = load i32*, i32** %9
%39 = load i32, i32* %11
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i32, i32* %38, i64 %40
store i32 15, i32* %41
br label %129
42: ; preds = %23
%43 = load i8*, i8** %6
%44 = load i32, i32* %10
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8, i8* %43, i64 %45
%47 = load i8, i8* %46
%48 = call i32 @get_flag_value(i8 zeroext %47)
%49 = icmp ne i32 %48, 0
br i1 %49, label %50, label %54
50: ; preds = %42
%51 = load i32, i32* %10
%52 = add nsw i32 %51, 8
store i32 %52, i32* %10
%53 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %57
54: ; preds = %42
%55 = load i32, i32* %10
%56 = add nsw i32 %55, 6
store i32 %56, i32* %10
br label %57
57: ; preds = %54, %50
%58 = load i32*, i32** %9
%59 = load i32, i32* %11
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds i32, i32* %58, i64 %60
store i32 14, i32* %61
br label %129
62: ; preds = %23
%63 = load i32, i32* %10
%64 = add nsw i32 %63, 5
store i32 %64, i32* %10
%65 = load i32*, i32** %9
%66 = load i32, i32* %11
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds i32, i32* %65, i64 %67
store i32 13, i32* %68
br label %129
69: ; preds = %23
%70 = load i8*, i8** %6
%71 = load i32, i32* %10
%72 = add nsw i32 6, %71
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds i8, i8* %70, i64 %73
%75 = call i32 @compressed_parse_bit_length(i8* %74)
store i32 %75, i32* %12
%76 = load i32, i32* %10
%77 = add nsw i32 %76, 8
store i32 %77, i32* %10
%78 = load i32, i32* %12
%79 = sdiv i32 %78, 8
%80 = load i32, i32* %10
%81 = add nsw i32 %80, %79
store i32 %81, i32* %10
%82 = load i32, i32* %12
%83 = srem i32 %82, 8
%84 = icmp ne i32 %83, 0
br i1 %84, label %85, label %88
85: ; preds = %69
%86 = load i32, i32* %10
%87 = add nsw i32 %86, 1
store i32 %87, i32* %10
br label %88
88: ; preds = %85, %69
%89 = load i32*, i32** %9
%90 = load i32, i32* %11
%91 = sext i32 %90 to i64
%92 = getelementptr inbounds i32, i32* %89, i64 %91
store i32 12, i32* %92
br label %129
93: ; preds = %23
%94 = load i32, i32* %10
%95 = add nsw i32 %94, 9
store i32 %95, i32* %10
%96 = load i32*, i32** %9
%97 = load i32, i32* %11
%98 = sext i32 %97 to i64
%99 = getelementptr inbounds i32, i32* %96, i64 %98
store i32 11, i32* %99
br label %129
100: ; preds = %23
%101 = load i8*, i8** %6
%102 = load i32, i32* %10
%103 = sext i32 %102 to i64
%104 = getelementptr inbounds i8, i8* %101, i64 %103
%105 = load i8, i8* %104
%106 = call i32 @get_flag_value(i8 zeroext %105)
%107 = icmp ne i32 %106, 0
br i1 %107, label %108, label %111
108: ; preds = %100
%109 = load i32, i32* %10
%110 = add nsw i32 %109, 7
store i32 %110, i32* %10
br label %114
111: ; preds = %100
%112 = load i32, i32* %10
%113 = add nsw i32 %112, 5
store i32 %113, i32* %10
br label %114
114: ; preds = %111, %108
%115 = load i32*, i32** %9
%116 = load i32, i32* %11
%117 = sext i32 %116 to i64
%118 = getelementptr inbounds i32, i32* %115, i64 %117
store i32 10, i32* %118
br label %129
119: ; preds = %23
%120 = load i32, i32* %10
%121 = add nsw i32 %120, 4
store i32 %121, i32* %10
%122 = load i32*, i32** %9
%123 = load i32, i32* %11
%124 = sext i32 %123 to i64
%125 = getelementptr inbounds i32, i32* %122, i64 %124
store i32 9, i32* %125
br label %129
126: ; preds = %23
br label %127
127: ; preds = %23, %126
%128 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %5
br label %134
129: ; preds = %119, %114, %93, %88, %62, %57, %35
%130 = load i32, i32* %11
%131 = add nsw i32 %130, 1
store i32 %131, i32* %11
br label %13
132: ; preds = %13
%133 = load i32, i32* %11
store i32 %133, i32* %5
br label %134
134: ; preds = %132, %127
%135 = load i32, i32* %5
ret i32 %135
}

LLVM IR (-O2):
@str = [22 x i8] c"Samples were dropped!\00"
@str.2 = [19 x i8] c"Pre-Parsing error!\00"
define i32 @preparse_packet(i8* %0, i32 %1, i32* nocapture writeonly %2, i32* nocapture writeonly %3) {
%5 = icmp sgt i32 %1, 0
br i1 %5, label %6, label %61
6: ; preds = %4, %51
%7 = phi i64 [ %55, %51 ], [ 0, %4 ]
%8 = phi i32 [ %53, %51 ], [ 0, %4 ]
%9 = getelementptr inbounds i32, i32* %2, i64 %7
store i32 %8, i32* %9
%10 = sext i32 %8 to i64
%11 = getelementptr inbounds i8, i8* %0, i64 %10
%12 = load i8, i8* %11
%13 = tail call i32 @get_packet_type(i8 zeroext %12)
switch i32 %13, label %49 [
i32 15, label %14
i32 14, label %16
i32 13, label %25
i32 12, label %27
i32 11, label %39
i32 10, label %41
i32 9, label %47
]
14: ; preds = %6
%15 = add nsw i32 %8, 4
br label %51
16: ; preds = %6
%17 = load i8, i8* %11
%18 = tail call i32 @get_flag_value(i8 zeroext %17)
%19 = icmp eq i32 %18, 0
br i1 %19, label %23, label %20
20: ; preds = %16
%21 = add nsw i32 %8, 8
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
br label %51
23: ; preds = %16
%24 = add nsw i32 %8, 6
br label %51
25: ; preds = %6
%26 = add nsw i32 %8, 5
br label %51
27: ; preds = %6
%28 = add nsw i32 %8, 6
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %0, i64 %29
%31 = tail call i32 @compressed_parse_bit_length(i8* %30)
%32 = add nsw i32 %8, 8
%33 = sdiv i32 %31, 8
%34 = add nsw i32 %32, %33
%35 = and i32 %31, 7
%36 = icmp ne i32 %35, 0
%37 = zext i1 %36 to i32
%38 = add nsw i32 %34, %37
br label %51
39: ; preds = %6
%40 = add nsw i32 %8, 9
br label %51
41: ; preds = %6
%42 = load i8, i8* %11
%43 = tail call i32 @get_flag_value(i8 zeroext %42)
%44 = icmp eq i32 %43, 0
%45 = select i1 %44, i32 5, i32 7
%46 = add nsw i32 %45, %8
br label %51
47: ; preds = %6
%48 = add nsw i32 %8, 4
br label %51
49: ; preds = %6
%50 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.2, i64 0, i64 0))
br label %61
51: ; preds = %20, %23, %47, %41, %39, %27, %25, %14
%52 = phi i32 [ 9, %47 ], [ 10, %41 ], [ 11, %39 ], [ 12, %27 ], [ 13, %25 ], [ 15, %14 ], [ 14, %23 ], [ 14, %20 ]
%53 = phi i32 [ %48, %47 ], [ %46, %41 ], [ %40, %39 ], [ %38, %27 ], [ %26, %25 ], [ %15, %14 ], [ %24, %23 ], [ %21, %20 ]
%54 = getelementptr inbounds i32, i32* %3, i64 %7
store i32 %52, i32* %54
%55 = add nuw nsw i64 %7, 1
%56 = icmp slt i32 %53, %1
%57 = icmp ult i64 %7, 9
%58 = and i1 %56, %57
br i1 %58, label %6, label %59
59: ; preds = %51
%60 = trunc i64 %55 to i32
br label %61
61: ; preds = %59, %4, %49
%62 = phi i32 [ 0, %49 ], [ 0, %4 ], [ %60, %59 ]
ret i32 %62
}