#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 preparse_packet(unsigned char *, int, int *, int *);
int /*<<< orphan*/ printf(char *, ...);
void test_preparse_packet(void) {
  int i = 0;
  unsigned char packet[61] = {
      0xff, 0xff, 0xaa, 0x55, 0xc0, 0x01, 0x06, 0x1a, 0xe4, 0x04, 0x01,
      0x56, 0xcc, 0xf3, 0xf8, 0x39, 0x9c, 0xf8, 0x8c, 0xc9, 0xcf, 0xe0,
      0x19, 0x93, 0x82, 0x27, 0x38, 0x10, 0x66, 0x22, 0x22, 0x62, 0x00,
      0xcf, 0x9e, 0x0f, 0x8c, 0xf3, 0x03, 0x7d, 0xf2, 0x67, 0x40, 0x75,
      0xc6, 0xf2, 0xd3, 0x29, 0xe1, 0x3e, 0x07, 0xe1, 0xb3, 0xb1, 0x00,
      0xe0, 0x17, 0x6a, 0x88, 0x63, 0x84};
  int expected_nb_of_soft_packets = 3;
  int expected_soft_packets_headers[10] = {0, 4, 55, 0, 0, 0, 0, 0, 0, 0};
  int expected_soft_packets_types[10] = {0xF, 0xC, 0xE, 0, 0, 0, 0, 0, 0, 0};
  int nb_of_soft_packets;
  int soft_packets_headers[10];
  int soft_packets_types[10];
  nb_of_soft_packets =
      preparse_packet(packet, 61, soft_packets_headers, soft_packets_types);
  printf("\n\n");
  printf("*************************\n");
  printf("PreParse Packet          \n");
  printf("*************************\n");
  printf("Nb of Soft Packets: %i:%i\n", expected_nb_of_soft_packets,
         nb_of_soft_packets);
  for (i = 0; i < nb_of_soft_packets; i++) {
    printf("Soft Packets Start: %i:%i\n", expected_soft_packets_headers[i],
           soft_packets_headers[i]);
    printf("Soft Packets Type: %i:%i\n", expected_soft_packets_types[i],
           soft_packets_types[i]);
  }
}


x86 assembly (clang, -O0):
<test_preparse_packet>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x50(%rbp),%rdi
lea    0xea3(%rip),%rsi
mov    $0x3d,%edx
call   1060 <memcpy@plt>
movl   $0x3,-0x54(%rbp)
lea    -0x80(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1040 <memset@plt>
movl   $0x4,-0x7c(%rbp)
movl   $0x37,-0x78(%rbp)
lea    -0xb0(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1040 <memset@plt>
movl   $0xf,-0xb0(%rbp)
movl   $0xc,-0xac(%rbp)
movl   $0xe,-0xa8(%rbp)
lea    -0x50(%rbp),%rdi
lea    -0xe0(%rbp),%rdx
lea    -0x110(%rbp),%rcx
mov    $0x3d,%esi
call   1050 <preparse_packet@plt>
mov    %eax,-0xb4(%rbp)
lea    0xe57(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe4c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe30(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x54(%rbp),%esi
mov    -0xb4(%rbp),%edx
lea    0xe4f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
cmp    -0xb4(%rbp),%eax
jge    1297 <test_preparse_packet+0x157>
movslq -0x4(%rbp),%rax
mov    -0x80(%rbp,%rax,4),%esi
movslq -0x4(%rbp),%rax
mov    -0xe0(%rbp,%rax,4),%edx
lea    0xe33(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movslq -0x4(%rbp),%rax
mov    -0xb0(%rbp,%rax,4),%esi
movslq -0x4(%rbp),%rax
mov    -0x110(%rbp,%rax,4),%edx
lea    0xe2a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1235 <test_preparse_packet+0xf5>
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_preparse_packet>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0xf8,%rsp
movups 0xee8(%rip),%xmm0
movups %xmm0,0x8d(%rsp)
movaps 0xecc(%rip),%xmm0
movaps %xmm0,0x80(%rsp)
movaps 0xead(%rip),%xmm0
movaps %xmm0,0x70(%rsp)
movaps 0xe91(%rip),%xmm0
movaps %xmm0,0x60(%rsp)
xorps  %xmm0,%xmm0
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x40(%rsp)
movq   $0x0,0x50(%rsp)
movabs $0x3700000004,%rax
mov    %rax,0x34(%rsp)
movaps %xmm0,(%rsp)
movaps %xmm0,0x10(%rsp)
movq   $0x0,0x20(%rsp)
movabs $0xc0000000f,%rax
mov    %rax,(%rsp)
movl   $0xe,0x8(%rsp)
lea    0x60(%rsp),%rdi
lea    0xd0(%rsp),%rdx
lea    0xa0(%rsp),%rcx
mov    $0x3d,%esi
call   1050 <preparse_packet@plt>
mov    %eax,%ebx
lea    0xea2(%rip),%rdi
call   1030 <puts@plt>
lea    0xeb2(%rip),%r14
mov    %r14,%rdi
call   1030 <puts@plt>
lea    0xe89(%rip),%rdi
call   1030 <puts@plt>
mov    %r14,%rdi
call   1030 <puts@plt>
lea    0xe25(%rip),%rdi
mov    $0x3,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1040 <printf@plt>
test   %ebx,%ebx
jle    1272 <test_preparse_packet+0x142>
mov    %ebx,%r12d
lea    0xe24(%rip),%r14
lea    0xe38(%rip),%r15
xor    %ebx,%ebx
nopl   (%rax)
mov    0x30(%rsp,%rbx,4),%esi
mov    0xd0(%rsp,%rbx,4),%edx
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rsp,%rbx,4),%esi
mov    0xa0(%rsp,%rbx,4),%edx
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1240 <test_preparse_packet+0x110>
add    $0xf8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.test_preparse_packet.packet = [61 x i8] c"\FF\FF\AAU\C0\01\06\1A\E4\04\01V\CC\F3\F89\9C\F8\8C\C9\CF\E0\19\93\82'8\10f\22\22b\00\CF\9E\0F\8C\F3\03}\F2g@u\C6\F2\D3)\E1>\07\E1\B3\B1\00\E0\17j\88c\84"
@.str = [3 x i8] c"\0A\0A\00"
@.str.1 = [27 x i8] c"*************************\0A\00"
@.str.2 = [27 x i8] c"PreParse Packet \0A\00"
@.str.3 = [27 x i8] c"Nb of Soft Packets: %i:%i\0A\00"
@.str.4 = [27 x i8] c"Soft Packets Start: %i:%i\0A\00"
@.str.5 = [26 x i8] c"Soft Packets Type: %i:%i\0A\00"
define void @test_preparse_packet() {
%1 = alloca i32
%2 = alloca [61 x i8]
%3 = alloca i32
%4 = alloca [10 x i32]
%5 = alloca [10 x i32]
%6 = alloca i32
%7 = alloca [10 x i32]
%8 = alloca [10 x i32]
store i32 0, i32* %1
%9 = bitcast [61 x i8]* %2 to i8*
store i32 3, i32* %3
%10 = bitcast [10 x i32]* %4 to i8*
%11 = bitcast i8* %10 to [10 x i32]*
%12 = getelementptr inbounds [10 x i32], [10 x i32]* %11, i32 0, i32 1
store i32 4, i32* %12
%13 = getelementptr inbounds [10 x i32], [10 x i32]* %11, i32 0, i32 2
store i32 55, i32* %13
%14 = bitcast [10 x i32]* %5 to i8*
%15 = bitcast i8* %14 to [10 x i32]*
%16 = getelementptr inbounds [10 x i32], [10 x i32]* %15, i32 0, i32 0
store i32 15, i32* %16
%17 = getelementptr inbounds [10 x i32], [10 x i32]* %15, i32 0, i32 1
store i32 12, i32* %17
%18 = getelementptr inbounds [10 x i32], [10 x i32]* %15, i32 0, i32 2
store i32 14, i32* %18
%19 = getelementptr inbounds [61 x i8], [61 x i8]* %2, i64 0, i64 0
%20 = getelementptr inbounds [10 x i32], [10 x i32]* %7, i64 0, i64 0
%21 = getelementptr inbounds [10 x i32], [10 x i32]* %8, i64 0, i64 0
%22 = call i32 @preparse_packet(i8* %19, i32 61, i32* %20, i32* %21)
store i32 %22, i32* %6
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
%27 = load i32, i32* %3
%28 = load i32, i32* %6
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i32 %27, i32 %28)
store i32 0, i32* %1
br label %30
30: ; preds = %53, %0
%31 = load i32, i32* %1
%32 = load i32, i32* %6
%33 = icmp slt i32 %31, %32
br i1 %33, label %34, label %56
34: ; preds = %30
%35 = load i32, i32* %1
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [10 x i32], [10 x i32]* %4, i64 0, i64 %36
%38 = load i32, i32* %37
%39 = load i32, i32* %1
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [10 x i32], [10 x i32]* %7, i64 0, i64 %40
%42 = load i32, i32* %41
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i32 %38, i32 %42)
%44 = load i32, i32* %1
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds [10 x i32], [10 x i32]* %5, i64 0, i64 %45
%47 = load i32, i32* %46
%48 = load i32, i32* %1
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds [10 x i32], [10 x i32]* %8, i64 0, i64 %49
%51 = load i32, i32* %50
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i32 %47, i32 %51)
br label %53
53: ; preds = %34
%54 = load i32, i32* %1
%55 = add nsw i32 %54, 1
store i32 %55, i32* %1
br label %30
56: ; preds = %30
ret void
}

LLVM IR (-O2):
@__const.test_preparse_packet.packet = [61 x i8] c"\FF\FF\AAU\C0\01\06\1A\E4\04\01V\CC\F3\F89\9C\F8\8C\C9\CF\E0\19\93\82'8\10f\22\22b\00\CF\9E\0F\8C\F3\03}\F2g@u\C6\F2\D3)\E1>\07\E1\B3\B1\00\E0\17j\88c\84"
@.str.3 = [27 x i8] c"Nb of Soft Packets: %i:%i\0A\00"
@.str.4 = [27 x i8] c"Soft Packets Start: %i:%i\0A\00"
@.str.5 = [26 x i8] c"Soft Packets Type: %i:%i\0A\00"
@str = [2 x i8] c"\0A\00"
@str.7 = [26 x i8] c"PreParse Packet \00"
@str.8 = [26 x i8] c"*************************\00"
define void @test_preparse_packet() {
%1 = alloca [61 x i8]
%2 = alloca [10 x i32]
%3 = alloca [10 x i32]
%4 = alloca [10 x i32]
%5 = alloca [10 x i32]
%6 = getelementptr inbounds [61 x i8], [61 x i8]* %1, i64 0, i64 0
%7 = bitcast [10 x i32]* %2 to i8*
%8 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 1
store i32 4, i32* %8
%9 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 2
store i32 55, i32* %9
%10 = bitcast [10 x i32]* %3 to i8*
%11 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 0
store i32 15, i32* %11
%12 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 1
store i32 12, i32* %12
%13 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 2
store i32 14, i32* %13
%14 = bitcast [10 x i32]* %4 to i8*
%15 = bitcast [10 x i32]* %5 to i8*
%16 = getelementptr inbounds [10 x i32], [10 x i32]* %4, i64 0, i64 0
%17 = getelementptr inbounds [10 x i32], [10 x i32]* %5, i64 0, i64 0
%18 = call i32 @preparse_packet(i8* %6, i32 61, i32* %16, i32* %17)
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.8, i64 0, i64 0))
%21 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.7, i64 0, i64 0))
%22 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.8, i64 0, i64 0))
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i32 3, i32 %18)
%24 = icmp sgt i32 %18, 0
br i1 %24, label %25, label %41
25: ; preds = %0
%26 = zext i32 %18 to i64
br label %27
27: ; preds = %25, %27
%28 = phi i64 [ 0, %25 ], [ %39, %27 ]
%29 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 %28
%30 = load i32, i32* %29
%31 = getelementptr inbounds [10 x i32], [10 x i32]* %4, i64 0, i64 %28
%32 = load i32, i32* %31
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i32 %30, i32 %32)
%34 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 %28
%35 = load i32, i32* %34
%36 = getelementptr inbounds [10 x i32], [10 x i32]* %5, i64 0, i64 %28
%37 = load i32, i32* %36
%38 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i32 %35, i32 %37)
%39 = add nuw nsw i64 %28, 1
%40 = icmp eq i64 %39, %26
br i1 %40, label %41, label %27
41: ; preds = %27, %0
ret void
}