#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;
typedef int uint32_t;

/* Variables and functions */
char *packetCommandToText(int);
int /*<<< orphan*/ printf(char *, ...);
int readU32LittleEndian(int *);
void displayPacket(uint8_t *packet_data, uint32_t buffer_length) {
  uint8_t command;
  uint8_t one_byte;
  uint32_t length;
  uint32_t i;
  command = packet_data[0];
  length = readU32LittleEndian(&(packet_data[1]));
  printf("command 0x%02x (%s)\n", command, packetCommandToText(command));
  printf("Payload length: %d\n", length);
  for (i = 0; i < length; i++) {
    if (i && !(i & 15)) {
      printf("\n");
    }
    one_byte = packet_data[i + 5];
    printf(" %02x", one_byte);
    if ((i + 5) >= buffer_length) {
      printf(" ***unexpected end of packet***");
      break;
    }
  }
  printf("\n");
  for (i = 0; i < length; i++) {
    if (i && !(i & 15)) {
      printf("\n");
    }
    one_byte = packet_data[i + 5];
    if ((one_byte < 32) || (one_byte > 126)) {
      printf(".");
    } else {
      printf("%c", packet_data[i + 5]);
    }
    if ((i + 5) >= buffer_length) {
      break;
    }
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<displayPacket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
add    $0x4,%rdi
call   1050 <readU32LittleEndian@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%edi
call   1030 <packetCommandToText@plt>
mov    -0x20(%rbp),%esi
mov    %rax,%rdx
lea    0xe8d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%esi
lea    0xe91(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    121e <displayPacket+0xee>
cmpl   $0x0,-0x1c(%rbp)
je     11c5 <displayPacket+0x95>
mov    -0x1c(%rbp),%eax
and    $0xf,%eax
cmp    $0x0,%eax
jne    11c5 <displayPacket+0x95>
lea    0xe55(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    $0x5,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
lea    0xe47(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x5,%eax
cmp    -0xc(%rbp),%eax
jl     120b <displayPacket+0xdb>
lea    0xe30(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    121e <displayPacket+0xee>
jmp    1210 <displayPacket+0xe0>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1192 <displayPacket+0x62>
lea    0xdee(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    12e5 <displayPacket+0x1b5>
cmpl   $0x0,-0x1c(%rbp)
je     1266 <displayPacket+0x136>
mov    -0x1c(%rbp),%eax
and    $0xf,%eax
cmp    $0x0,%eax
jne    1266 <displayPacket+0x136>
lea    0xdb4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    $0x5,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x20,-0x14(%rbp)
jl     128d <displayPacket+0x15d>
cmpl   $0x7e,-0x14(%rbp)
jle    12a0 <displayPacket+0x170>
lea    0xdbb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12be <displayPacket+0x18e>
mov    -0x8(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    $0x5,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%esi
lea    0xd9a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x5,%eax
cmp    -0xc(%rbp),%eax
jl     12d2 <displayPacket+0x1a2>
jmp    12e5 <displayPacket+0x1b5>
jmp    12d7 <displayPacket+0x1a7>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1233 <displayPacket+0x103>
lea    0xd27(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<displayPacket>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %rdi,%r13
mov    (%rdi),%ebp
add    $0x4,%rdi
call   1060 <readU32LittleEndian@plt>
mov    %eax,%r15d
mov    %ebp,%edi
call   1040 <packetCommandToText@plt>
lea    0xe93(%rip),%rdi
mov    %ebp,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe95(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
test   %r15d,%r15d
jle    11e8 <displayPacket+0xa8>
cmp    $0x6,%r14d
mov    $0x5,%ebx
mov    %r14d,0x4(%rsp)
cmovge %r14d,%ebx
add    $0xfffffffb,%ebx
mov    %r15d,%r14d
lea    0xe7b(%rip),%r12
xor    %ebp,%ebp
test   %rbp,%rbp
je     11c9 <displayPacket+0x89>
mov    %ebp,%eax
and    $0xf,%eax
test   %rax,%rax
jne    11c9 <displayPacket+0x89>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0x14(%r13,%rbp,4),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
cmp    %rbp,%rbx
je     11f4 <displayPacket+0xb4>
add    $0x1,%rbp
cmp    %rbp,%r14
jne    11b0 <displayPacket+0x70>
jmp    1202 <displayPacket+0xc2>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    125f <displayPacket+0x11f>
lea    0xe34(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
test   %r15d,%r15d
jle    125f <displayPacket+0x11f>
movslq 0x4(%rsp),%rbx
xor    %ebp,%ebp
mov    $0x2e,%r15d
xchg   %ax,%ax
test   %rbp,%rbp
je     1239 <displayPacket+0xf9>
mov    %ebp,%eax
and    $0xf,%eax
test   %rax,%rax
jne    1239 <displayPacket+0xf9>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0x14(%r13,%rbp,4),%edi
lea    -0x7f(%rdi),%eax
cmp    $0xffffffa1,%eax
cmovb  %r15d,%edi
call   1030 <putchar@plt>
lea    0x5(%rbp),%rax
cmp    %rbx,%rax
jge    125f <displayPacket+0x11f>
add    $0x1,%rbp
cmp    %r14,%rbp
jb     1220 <displayPacket+0xe0>
mov    $0xa,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>

LLVM IR (-O0):
@.str = [21 x i8] c"command 0x%02x (%s)\0A\00"
@.str.1 = [20 x i8] c"Payload length: %d\0A\00"
@.str.2 = [2 x i8] c"\0A\00"
@.str.3 = [6 x i8] c" %02x\00"
@.str.4 = [32 x i8] c" ***unexpected end of packet***\00"
@.str.5 = [2 x i8] c".\00"
@.str.6 = [3 x i8] c"%c\00"
define void @displayPacket(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
%9 = load i32*, i32** %3
%10 = getelementptr inbounds i32, i32* %9, i64 0
%11 = load i32, i32* %10
store i32 %11, i32* %5
%12 = load i32*, i32** %3
%13 = getelementptr inbounds i32, i32* %12, i64 1
%14 = call i32 @readU32LittleEndian(i32* %13)
store i32 %14, i32* %7
%15 = load i32, i32* %5
%16 = load i32, i32* %5
%17 = call i8* @packetCommandToText(i32 %16)
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %15, i8* %17)
%19 = load i32, i32* %7
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %19)
store i32 0, i32* %8
br label %21
21: ; preds = %50, %2
%22 = load i32, i32* %8
%23 = load i32, i32* %7
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %53
25: ; preds = %21
%26 = load i32, i32* %8
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %34
28: ; preds = %25
%29 = load i32, i32* %8
%30 = and i32 %29, 15
%31 = icmp ne i32 %30, 0
br i1 %31, label %34, label %32
32: ; preds = %28
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %34
34: ; preds = %32, %28, %25
%35 = load i32*, i32** %3
%36 = load i32, i32* %8
%37 = add nsw i32 %36, 5
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i32, i32* %35, i64 %38
%40 = load i32, i32* %39
store i32 %40, i32* %6
%41 = load i32, i32* %6
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %41)
%43 = load i32, i32* %8
%44 = add nsw i32 %43, 5
%45 = load i32, i32* %4
%46 = icmp sge i32 %44, %45
br i1 %46, label %47, label %49
47: ; preds = %34
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0))
br label %53
49: ; preds = %34
br label %50
50: ; preds = %49
%51 = load i32, i32* %8
%52 = add nsw i32 %51, 1
store i32 %52, i32* %8
br label %21
53: ; preds = %47, %21
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %8
br label %55
55: ; preds = %97, %53
%56 = load i32, i32* %8
%57 = load i32, i32* %7
%58 = icmp slt i32 %56, %57
br i1 %58, label %59, label %100
59: ; preds = %55
%60 = load i32, i32* %8
%61 = icmp ne i32 %60, 0
br i1 %61, label %62, label %68
62: ; preds = %59
%63 = load i32, i32* %8
%64 = and i32 %63, 15
%65 = icmp ne i32 %64, 0
br i1 %65, label %68, label %66
66: ; preds = %62
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %68
68: ; preds = %66, %62, %59
%69 = load i32*, i32** %3
%70 = load i32, i32* %8
%71 = add nsw i32 %70, 5
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds i32, i32* %69, i64 %72
%74 = load i32, i32* %73
store i32 %74, i32* %6
%75 = load i32, i32* %6
%76 = icmp slt i32 %75, 32
br i1 %76, label %80, label %77
77: ; preds = %68
%78 = load i32, i32* %6
%79 = icmp sgt i32 %78, 126
br i1 %79, label %80, label %82
80: ; preds = %77, %68
%81 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
br label %90
82: ; preds = %77
%83 = load i32*, i32** %3
%84 = load i32, i32* %8
%85 = add nsw i32 %84, 5
%86 = sext i32 %85 to i64
%87 = getelementptr inbounds i32, i32* %83, i64 %86
%88 = load i32, i32* %87
%89 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32 %88)
br label %90
90: ; preds = %82, %80
%91 = load i32, i32* %8
%92 = add nsw i32 %91, 5
%93 = load i32, i32* %4
%94 = icmp sge i32 %92, %93
br i1 %94, label %95, label %96
95: ; preds = %90
br label %100
96: ; preds = %90
br label %97
97: ; preds = %96
%98 = load i32, i32* %8
%99 = add nsw i32 %98, 1
store i32 %99, i32* %8
br label %55
100: ; preds = %95, %55
%101 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [21 x i8] c"command 0x%02x (%s)\0A\00"
@.str.1 = [20 x i8] c"Payload length: %d\0A\00"
@.str.3 = [6 x i8] c" %02x\00"
@.str.4 = [32 x i8] c" ***unexpected end of packet***\00"
define void @displayPacket(i32* %0, i32 %1) {
%3 = load i32, i32* %0
%4 = getelementptr inbounds i32, i32* %0, i64 1
%5 = tail call i32 @readU32LittleEndian(i32* %4)
%6 = tail call i8* @packetCommandToText(i32 %3)
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %3, i8* %6)
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %5)
%9 = icmp sgt i32 %5, 0
br i1 %9, label %12, label %10
10: ; preds = %2
%11 = tail call i32 @putchar(i32 10)
br label %61
12: ; preds = %2
%13 = call i32 @llvm.smax.i32(i32 %1, i32 5)
%14 = add nsw i32 %13, -5
%15 = zext i32 %14 to i64
%16 = zext i32 %5 to i64
br label %19
17: ; preds = %27
%18 = icmp eq i64 %32, %16
br i1 %18, label %36, label %19
19: ; preds = %12, %17
%20 = phi i64 [ 0, %12 ], [ %32, %17 ]
%21 = icmp ne i64 %20, 0
%22 = and i64 %20, 15
%23 = icmp eq i64 %22, 0
%24 = and i1 %21, %23
br i1 %24, label %25, label %27
25: ; preds = %19
%26 = tail call i32 @putchar(i32 10)
br label %27
27: ; preds = %25, %19
%28 = add nuw nsw i64 %20, 5
%29 = getelementptr inbounds i32, i32* %0, i64 %28
%30 = load i32, i32* %29
%31 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %30)
%32 = add nuw nsw i64 %20, 1
%33 = icmp eq i64 %20, %15
br i1 %33, label %34, label %17
34: ; preds = %27
%35 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0))
br label %36
36: ; preds = %17, %34
%37 = tail call i32 @putchar(i32 10)
br i1 %9, label %38, label %61
38: ; preds = %36
%39 = sext i32 %1 to i64
%40 = zext i32 %5 to i64
br label %41
41: ; preds = %49, %38
%42 = phi i64 [ %58, %49 ], [ 0, %38 ]
%43 = icmp ne i64 %42, 0
%44 = and i64 %42, 15
%45 = icmp eq i64 %44, 0
%46 = and i1 %43, %45
br i1 %46, label %47, label %49
47: ; preds = %41
%48 = tail call i32 @putchar(i32 10)
br label %49
49: ; preds = %47, %41
%50 = add nuw nsw i64 %42, 5
%51 = getelementptr inbounds i32, i32* %0, i64 %50
%52 = load i32, i32* %51
%53 = add i32 %52, -127
%54 = icmp ult i32 %53, -95
%55 = select i1 %54, i32 46, i32 %52
%56 = tail call i32 @putchar(i32 %55)
%57 = icmp slt i64 %50, %39
%58 = add nuw nsw i64 %42, 1
%59 = icmp ult i64 %58, %40
%60 = select i1 %57, i1 %59, i1 false
br i1 %60, label %41, label %61
61: ; preds = %49, %10, %36
%62 = tail call i32 @putchar(i32 10)
ret void
}