#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_hex(unsigned char *pkt, int len) {
  int i, j;
  for (i = 0, j = 0; i < len; i++, j++) {
    if (j == 16)
      j = 0;
    printf("%02x ", pkt[i]);
    switch (j) {
    case 7:
      printf(" ");
      break;
    case 15:
      printf("\n");
      break;
    }
  }
  printf("\n\n");
}


x86 assembly (clang, -O0):
<print_hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11c6 <print_hex+0xb6>
cmpl   $0x10,-0x14(%rbp)
jne    114a <print_hex+0x3a>
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xea3(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
sub    $0x7,%eax
je     1189 <print_hex+0x79>
jmp    1178 <print_hex+0x68>
mov    -0x18(%rbp),%eax
sub    $0xf,%eax
je     119c <print_hex+0x8c>
jmp    11aa <print_hex+0x9a>
lea    0xe74(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11aa <print_hex+0x9a>
lea    0xe64(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11af <print_hex+0x9f>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    112d <print_hex+0x1d>
lea    0xe39(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_hex>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
jle    119d <print_hex+0x6d>
mov    %rdi,%r15
mov    %esi,%r13d
xor    %r12d,%r12d
lea    0xeb1(%rip),%r14
xor    %ebx,%ebx
xor    %ebp,%ebp
jmp    1176 <print_hex+0x46>
cs nopw 0x0(%rax,%rax,1)
nop
mov    $0x20,%edi
call   1030 <putchar@plt>
add    $0x1,%rbx
add    $0x1,%ebp
cmp    %rbx,%r13
je     119d <print_hex+0x6d>
cmp    $0x10,%ebp
cmove  %r12d,%ebp
movzbl (%r15,%rbx,1),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
cmp    $0x7,%ebp
je     1160 <print_hex+0x30>
cmp    $0xf,%ebp
jne    116a <print_hex+0x3a>
mov    $0xa,%edi
jmp    1165 <print_hex+0x35>
lea    0xe62(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <puts@plt>

LLVM IR (-O0):
@.str = [6 x i8] c"%02x \00"
@.str.1 = [2 x i8] c" \00"
@.str.2 = [2 x i8] c"\0A\00"
@.str.3 = [3 x i8] c"\0A\0A\00"
define void @print_hex(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
store i32 0, i32* %5
store i32 0, i32* %6
br label %7
7: ; preds = %29, %2
%8 = load i32, i32* %5
%9 = load i32, i32* %4
%10 = icmp slt i32 %8, %9
br i1 %10, label %11, label %34
11: ; preds = %7
%12 = load i32, i32* %6
%13 = icmp eq i32 %12, 16
br i1 %13, label %14, label %15
14: ; preds = %11
store i32 0, i32* %6
br label %15
15: ; preds = %14, %11
%16 = load i8*, i8** %3
%17 = load i32, i32* %5
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %16, i64 %18
%20 = load i8, i8* %19
%21 = zext i8 %20 to i32
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %21)
%23 = load i32, i32* %6
switch i32 %23, label %28 [
i32 7, label %24
i32 15, label %26
]
24: ; preds = %15
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %28
26: ; preds = %15
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %28
28: ; preds = %15, %26, %24
br label %29
29: ; preds = %28
%30 = load i32, i32* %5
%31 = add nsw i32 %30, 1
store i32 %31, i32* %5
%32 = load i32, i32* %6
%33 = add nsw i32 %32, 1
store i32 %33, i32* %6
br label %7
34: ; preds = %7
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"%02x \00"
@str = [2 x i8] c"\0A\00"
define void @print_hex(i8* nocapture %0, i32 %1) {
%3 = icmp sgt i32 %1, 0
br i1 %3, label %4, label %23
4: ; preds = %2
%5 = zext i32 %1 to i64
br label %6
6: ; preds = %4, %19
%7 = phi i64 [ 0, %4 ], [ %20, %19 ]
%8 = phi i32 [ 0, %4 ], [ %21, %19 ]
%9 = icmp eq i32 %8, 16
%10 = select i1 %9, i32 0, i32 %8
%11 = getelementptr inbounds i8, i8* %0, i64 %7
%12 = load i8, i8* %11
%13 = zext i8 %12 to i32
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %13)
switch i32 %10, label %19 [
i32 7, label %16
i32 15, label %15
]
15: ; preds = %6
br label %16
16: ; preds = %6, %15
%17 = phi i32 [ 10, %15 ], [ 32, %6 ]
%18 = tail call i32 @putchar(i32 %17)
br label %19
19: ; preds = %16, %6
%20 = add nuw nsw i64 %7, 1
%21 = add nsw i32 %10, 1
%22 = icmp eq i64 %20, %5
br i1 %22, label %23, label %6
23: ; preds = %19, %2
%24 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
ret void
}