#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 /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, unsigned char const);
scalar_t__ isprint(unsigned char const);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdout;
void packet_print_line(const unsigned char *packet, unsigned int len,
                       unsigned int offset) {
  unsigned int gap;
  fprintf(stdout, "%05x   ", offset);
  for (size_t i = 0; i < len; i++) {
    fprintf(stdout, "%02x ", packet[i]);
    if (i == 7)
      printf(" ");
  }
  if (len < 8)
    printf(" ");
  if (len < 16) {
    gap = 16 - len;
    for (size_t i = 0; i < gap; i++) {
      printf("   ");
    }
  }
  printf("   ");
  for (size_t i = 0; i < len; i++) {
    if (isprint(packet[i]))
      printf("%c", packet[i]);
    else
      printf(".");
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<packet_print_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    0x2e97(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%eax
lea    0xeab(%rip),%rsi
movzbl %al,%edx
call   1040 <fprintf@plt>
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    -0xc(%rbp),%ecx
cmp    %rcx,%rax
jae    11c5 <packet_print_line+0x95>
mov    0x2e64(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
lea    0xe7b(%rip),%rsi
movzbl (%rax,%rcx,1),%edx
call   1040 <fprintf@plt>
cmpq   $0x7,-0x20(%rbp)
jne    11af <packet_print_line+0x7f>
lea    0xe5e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11b4 <packet_print_line+0x84>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1165 <packet_print_line+0x35>
cmpl   $0x8,-0xc(%rbp)
jae    11dd <packet_print_line+0xad>
lea    0xe30(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x10,-0xc(%rbp)
jae    122e <packet_print_line+0xfe>
mov    $0x10,%eax
sub    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x14(%rbp),%ecx
cmp    %rcx,%rax
jae    1229 <packet_print_line+0xf9>
lea    0xdf3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    11fa <packet_print_line+0xca>
jmp    122e <packet_print_line+0xfe>
lea    0xdcf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movq   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    -0xc(%rbp),%ecx
cmp    %rcx,%rax
jae    12b2 <packet_print_line+0x182>
mov    -0x8(%rbp),%rax
mov    -0x30(%rbp),%rcx
movzbl (%rax,%rcx,1),%edi
call   1050 <isprint@plt>
cmp    $0x0,%rax
je     128e <packet_print_line+0x15e>
mov    -0x8(%rbp),%rax
mov    -0x30(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xd8c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    129c <packet_print_line+0x16c>
lea    0xd7c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12a1 <packet_print_line+0x171>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    1244 <packet_print_line+0x114>
lea    0xd5a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<packet_print_line>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %rdi,%rbx
mov    0x2e88(%rip),%r12
mov    (%r12),%edi
movzbl %dl,%edx
lea    0xe9a(%rip),%rsi
call   1050 <fprintf@plt>
mov    %r14d,%r15d
test   %r14d,%r14d
je     11b1 <packet_print_line+0x71>
xor    %ebp,%ebp
lea    0xe8c(%rip),%r13
jmp    1189 <packet_print_line+0x49>
xchg   %ax,%ax
add    $0x1,%rbp
cmp    %rbp,%r15
je     11ab <packet_print_line+0x6b>
mov    (%r12),%edi
movzbl (%rbx,%rbp,1),%edx
mov    %r13,%rsi
call   1050 <fprintf@plt>
cmp    $0x7,%rbp
jne    1180 <packet_print_line+0x40>
mov    $0x20,%edi
call   1030 <putchar@plt>
jmp    1180 <packet_print_line+0x40>
cmp    $0x8,%r14d
jae    11bd <packet_print_line+0x7d>
mov    $0x20,%edi
call   1030 <putchar@plt>
jmp    11c3 <packet_print_line+0x83>
cmp    $0xf,%r14d
ja     11f0 <packet_print_line+0xb0>
mov    $0x10,%ebp
sub    %r14d,%ebp
lea    0xe32(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r12,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0xffffffffffffffff,%rbp
jne    11e0 <packet_print_line+0xa0>
lea    0xe0d(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
test   %r14d,%r14d
je     1237 <packet_print_line+0xf7>
xor    %ebp,%ebp
jmp    1222 <packet_print_line+0xe2>
nopw   0x0(%rax,%rax,1)
movzbl (%rbx,%rbp,1),%edi
call   1030 <putchar@plt>
add    $0x1,%rbp
cmp    %rbp,%r15
je     1237 <packet_print_line+0xf7>
movzbl (%rbx,%rbp,1),%edi
call   1060 <isprint@plt>
test   %rax,%rax
jne    1210 <packet_print_line+0xd0>
mov    $0x2e,%edi
jmp    1214 <packet_print_line+0xd4>
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):
@stdout = global i32 0
@.str = [8 x i8] c"%05x \00"
@.str.1 = [6 x i8] c"%02x \00"
@.str.2 = [2 x i8] c" \00"
@.str.3 = [4 x i8] c" \00"
@.str.4 = [3 x i8] c"%c\00"
@.str.5 = [2 x i8] c".\00"
@.str.6 = [2 x i8] c"\0A\00"
define void @packet_print_line(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%11 = load i32, i32* @stdout
%12 = load i32, i32* %6
%13 = trunc i32 %12 to i8
%14 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8 zeroext %13)
store i64 0, i64* %8
br label %15
15: ; preds = %32, %3
%16 = load i64, i64* %8
%17 = load i32, i32* %5
%18 = zext i32 %17 to i64
%19 = icmp ult i64 %16, %18
br i1 %19, label %20, label %35
20: ; preds = %15
%21 = load i32, i32* @stdout
%22 = load i8*, i8** %4
%23 = load i64, i64* %8
%24 = getelementptr inbounds i8, i8* %22, i64 %23
%25 = load i8, i8* %24
%26 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8 zeroext %25)
%27 = load i64, i64* %8
%28 = icmp eq i64 %27, 7
br i1 %28, label %29, label %31
29: ; preds = %20
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %31
31: ; preds = %29, %20
br label %32
32: ; preds = %31
%33 = load i64, i64* %8
%34 = add i64 %33, 1
store i64 %34, i64* %8
br label %15
35: ; preds = %15
%36 = load i32, i32* %5
%37 = icmp ult i32 %36, 8
br i1 %37, label %38, label %40
38: ; preds = %35
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %40
40: ; preds = %38, %35
%41 = load i32, i32* %5
%42 = icmp ult i32 %41, 16
br i1 %42, label %43, label %57
43: ; preds = %40
%44 = load i32, i32* %5
%45 = sub i32 16, %44
store i32 %45, i32* %7
store i64 0, i64* %9
br label %46
46: ; preds = %53, %43
%47 = load i64, i64* %9
%48 = load i32, i32* %7
%49 = zext i32 %48 to i64
%50 = icmp ult i64 %47, %49
br i1 %50, label %51, label %56
51: ; preds = %46
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
br label %53
53: ; preds = %51
%54 = load i64, i64* %9
%55 = add i64 %54, 1
store i64 %55, i64* %9
br label %46
56: ; preds = %46
br label %57
57: ; preds = %56, %40
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
store i64 0, i64* %10
br label %59
59: ; preds = %81, %57
%60 = load i64, i64* %10
%61 = load i32, i32* %5
%62 = zext i32 %61 to i64
%63 = icmp ult i64 %60, %62
br i1 %63, label %64, label %84
64: ; preds = %59
%65 = load i8*, i8** %4
%66 = load i64, i64* %10
%67 = getelementptr inbounds i8, i8* %65, i64 %66
%68 = load i8, i8* %67
%69 = call i64 @isprint(i8 zeroext %68)
%70 = icmp ne i64 %69, 0
br i1 %70, label %71, label %78
71: ; preds = %64
%72 = load i8*, i8** %4
%73 = load i64, i64* %10
%74 = getelementptr inbounds i8, i8* %72, i64 %73
%75 = load i8, i8* %74
%76 = zext i8 %75 to i32
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %76)
br label %80
78: ; preds = %64
%79 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
br label %80
80: ; preds = %78, %71
br label %81
81: ; preds = %80
%82 = load i64, i64* %10
%83 = add i64 %82, 1
store i64 %83, i64* %10
br label %59
84: ; preds = %59
%85 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@stdout = global i32 0
@.str = [8 x i8] c"%05x \00"
@.str.1 = [6 x i8] c"%02x \00"
@.str.3 = [4 x i8] c" \00"
define void @packet_print_line(i8* nocapture %0, i32 %1, i32 %2) {
%4 = load i32, i32* @stdout
%5 = trunc i32 %2 to i8
%6 = tail call i32 @fprintf(i32 %4, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8 zeroext %5)
%7 = zext i32 %1 to i64
%8 = icmp eq i32 %1, 0
br i1 %8, label %23, label %11
9: ; preds = %20
%10 = icmp ult i32 %1, 8
br i1 %10, label %23, label %25
11: ; preds = %3, %20
%12 = phi i64 [ %21, %20 ], [ 0, %3 ]
%13 = load i32, i32* @stdout
%14 = getelementptr inbounds i8, i8* %0, i64 %12
%15 = load i8, i8* %14
%16 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8 zeroext %15)
%17 = icmp eq i64 %12, 7
br i1 %17, label %18, label %20
18: ; preds = %11
%19 = tail call i32 @putchar(i32 32)
br label %20
20: ; preds = %11, %18
%21 = add nuw nsw i64 %12, 1
%22 = icmp eq i64 %21, %7
br i1 %22, label %9, label %11
23: ; preds = %3, %9
%24 = tail call i32 @putchar(i32 32)
br label %27
25: ; preds = %9
%26 = icmp ult i32 %1, 16
br i1 %26, label %27, label %35
27: ; preds = %25, %23
%28 = sub nuw nsw i32 16, %1
%29 = zext i32 %28 to i64
br label %30
30: ; preds = %27, %30
%31 = phi i64 [ %33, %30 ], [ 0, %27 ]
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%33 = add nuw nsw i64 %31, 1
%34 = icmp eq i64 %33, %29
br i1 %34, label %35, label %30
35: ; preds = %30, %25
%36 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
br i1 %8, label %37, label %39
37: ; preds = %48, %35
%38 = tail call i32 @putchar(i32 10)
ret void
39: ; preds = %35, %48
%40 = phi i64 [ %51, %48 ], [ 0, %35 ]
%41 = getelementptr inbounds i8, i8* %0, i64 %40
%42 = load i8, i8* %41
%43 = tail call i64 @isprint(i8 zeroext %42)
%44 = icmp eq i64 %43, 0
br i1 %44, label %48, label %45
45: ; preds = %39
%46 = load i8, i8* %41
%47 = zext i8 %46 to i32
br label %48
48: ; preds = %39, %45
%49 = phi i32 [ %47, %45 ], [ 46, %39 ]
%50 = tail call i32 @putchar(i32 %49)
%51 = add nuw nsw i64 %40, 1
%52 = icmp eq i64 %51, %7
br i1 %52, label %37, label %39
}