#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*/ printf(char *, ...);
void print_packet(unsigned long add, int len) {
  int truncate = (len > 256);
  int length_to_print = truncate ? 256 : len;
  int i;
  printf("\nipacket: add = %lx len = %d\n", add, len);
  for (i = 0; i < length_to_print; i++) {
    if (!(i % 8))
      printf(" ");
    if (!(i % 16))
      printf("\n");
    printf(" %.2x", *(((unsigned char *)add) + i));
  }
  printf("\n");
  if (truncate)
    printf("\ttruncated....\n");
}


x86 assembly (clang, -O0):
<print_packet>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x100,-0xc(%rbp)
setg   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
je     1148 <print_packet+0x38>
mov    $0x100,%eax
mov    %eax,-0x1c(%rbp)
jmp    114e <print_packet+0x3e>
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
lea    0xe9e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11e8 <print_packet+0xd8>
mov    -0x18(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    119e <print_packet+0x8e>
lea    0xe87(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11c0 <print_packet+0xb0>
lea    0xe7b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xe4d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1170 <print_packet+0x60>
lea    0xe45(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x0,-0x10(%rbp)
je     120e <print_packet+0xfe>
lea    0xe1f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_packet>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r14d
mov    %rdi,%r12
lea    0xebb(%rip),%rdi
mov    %r12,%rsi
mov    %r14d,%edx
xor    %eax,%eax
call   1050 <printf@plt>
test   %r14d,%r14d
jle    11cb <print_packet+0x9b>
cmp    $0x101,%r14d
mov    $0x100,%ebp
cmovl  %r14d,%ebp
lea    0xeb0(%rip),%r15
xor    %ebx,%ebx
jmp    1198 <print_packet+0x68>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movzbl (%r12,%rbx,1),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
je     11cb <print_packet+0x9b>
test   $0x7,%bl
je     11b0 <print_packet+0x80>
test   $0xf,%bl
jne    1180 <print_packet+0x50>
jmp    11bf <print_packet+0x8f>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    $0x20,%edi
call   1030 <putchar@plt>
test   $0xf,%bl
jne    1180 <print_packet+0x50>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    1180 <print_packet+0x50>
mov    $0xa,%edi
call   1030 <putchar@plt>
cmp    $0x101,%r14d
jl     11f2 <print_packet+0xc2>
lea    0xe3f(%rip),%rdi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <puts@plt>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [30 x i8] c"\0Aipacket: add = %lx len = %d\0A\00"
@.str.1 = [2 x i8] c" \00"
@.str.2 = [2 x i8] c"\0A\00"
@.str.3 = [6 x i8] c" %.2x\00"
@.str.4 = [16 x i8] c"\09truncated....\0A\00"
define void @print_packet(i64 %0, i32 %1) {
%3 = alloca i64
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i64 %0, i64* %3
store i32 %1, i32* %4
%8 = load i32, i32* %4
%9 = icmp sgt i32 %8, 256
%10 = zext i1 %9 to i32
store i32 %10, i32* %5
%11 = load i32, i32* %5
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %2
br label %16
14: ; preds = %2
%15 = load i32, i32* %4
br label %16
16: ; preds = %14, %13
%17 = phi i32 [ 256, %13 ], [ %15, %14 ]
store i32 %17, i32* %6
%18 = load i64, i64* %3
%19 = load i32, i32* %4
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i64 %18, i32 %19)
store i32 0, i32* %7
br label %21
21: ; preds = %46, %16
%22 = load i32, i32* %7
%23 = load i32, i32* %6
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %49
25: ; preds = %21
%26 = load i32, i32* %7
%27 = srem i32 %26, 8
%28 = icmp ne i32 %27, 0
br i1 %28, label %31, label %29
29: ; preds = %25
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %31
31: ; preds = %29, %25
%32 = load i32, i32* %7
%33 = srem i32 %32, 16
%34 = icmp ne i32 %33, 0
br i1 %34, label %37, label %35
35: ; preds = %31
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %37
37: ; preds = %35, %31
%38 = load i64, i64* %3
%39 = inttoptr i64 %38 to i8*
%40 = load i32, i32* %7
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %39, i64 %41
%43 = load i8, i8* %42
%44 = zext i8 %43 to i32
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %44)
br label %46
46: ; preds = %37
%47 = load i32, i32* %7
%48 = add nsw i32 %47, 1
store i32 %48, i32* %7
br label %21
49: ; preds = %21
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%51 = load i32, i32* %5
%52 = icmp ne i32 %51, 0
br i1 %52, label %53, label %55
53: ; preds = %49
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
br label %55
55: ; preds = %53, %49
ret void
}

LLVM IR (-O2):
@.str = [30 x i8] c"\0Aipacket: add = %lx len = %d\0A\00"
@.str.3 = [6 x i8] c" %.2x\00"
@str = [15 x i8] c"\09truncated....\00"
define void @print_packet(i64 %0, i32 %1) {
%3 = icmp sgt i32 %1, 256
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i64 %0, i32 %1)
%5 = icmp sgt i32 %1, 0
br i1 %5, label %6, label %29
6: ; preds = %2
%7 = inttoptr i64 %0 to i8*
%8 = select i1 %3, i32 256, i32 %1
%9 = zext i32 %8 to i64
br label %10
10: ; preds = %6, %22
%11 = phi i64 [ 0, %6 ], [ %27, %22 ]
%12 = trunc i64 %11 to i32
%13 = and i32 %12, 7
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %10
%16 = tail call i32 @putchar(i32 32)
br label %17
17: ; preds = %15, %10
%18 = and i32 %12, 15
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %17
%21 = tail call i32 @putchar(i32 10)
br label %22
22: ; preds = %20, %17
%23 = getelementptr inbounds i8, i8* %7, i64 %11
%24 = load i8, i8* %23
%25 = zext i8 %24 to i32
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %25)
%27 = add nuw nsw i64 %11, 1
%28 = icmp eq i64 %27, %9
br i1 %28, label %29, label %10
29: ; preds = %22, %2
%30 = tail call i32 @putchar(i32 10)
br i1 %3, label %31, label %33
31: ; preds = %29
%32 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
br label %33
33: ; preds = %31, %29
ret void
}