#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 muggle_output_hex(const unsigned char *bytes, unsigned int len,
                       int bytes_per_line) {
  int cnt = 0;
  for (unsigned int i = 0; i < len; ++i) {
    printf("%02x ", 0xff & bytes[i]);
    if (bytes_per_line > 0 && ++cnt == bytes_per_line) {
      cnt = 0;
      printf("\n");
    }
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<muggle_output_hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0xc(%rbp),%eax
jae    119f <muggle_output_hex+0x8f>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%ecx
movzbl (%rax,%rcx,1),%esi
and    $0xff,%esi
lea    0xeac(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x0,-0x10(%rbp)
jle    118c <muggle_output_hex+0x7c>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
cmp    -0x10(%rbp),%eax
jne    118c <muggle_output_hex+0x7c>
movl   $0x0,-0x14(%rbp)
lea    0xe81(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1191 <muggle_output_hex+0x81>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1130 <muggle_output_hex+0x20>
lea    0xe60(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<muggle_output_hex>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
je     1183 <muggle_output_hex+0x63>
mov    %edx,%r13d
mov    %rdi,%r14
mov    %esi,%r12d
lea    0xec1(%rip),%r15
xor    %ebx,%ebx
xor    %ebp,%ebp
jmp    1159 <muggle_output_hex+0x39>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%rbx
cmp    %rbx,%r12
je     1183 <muggle_output_hex+0x63>
movzbl (%r14,%rbx,1),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
test   %r13d,%r13d
jle    1150 <muggle_output_hex+0x30>
add    $0x1,%ebp
cmp    %r13d,%ebp
jne    1150 <muggle_output_hex+0x30>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %ebp,%ebp
jmp    1150 <muggle_output_hex+0x30>
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 = [6 x i8] c"%02x \00"
@.str.1 = [2 x i8] c"\0A\00"
define void @muggle_output_hex(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
br label %9
9: ; preds = %32, %3
%10 = load i32, i32* %8
%11 = load i32, i32* %5
%12 = icmp ult i32 %10, %11
br i1 %12, label %13, label %35
13: ; preds = %9
%14 = load i8*, i8** %4
%15 = load i32, i32* %8
%16 = zext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %14, i64 %16
%18 = load i8, i8* %17
%19 = zext i8 %18 to i32
%20 = and i32 255, %19
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %20)
%22 = load i32, i32* %6
%23 = icmp sgt i32 %22, 0
br i1 %23, label %24, label %31
24: ; preds = %13
%25 = load i32, i32* %7
%26 = add nsw i32 %25, 1
store i32 %26, i32* %7
%27 = load i32, i32* %6
%28 = icmp eq i32 %26, %27
br i1 %28, label %29, label %31
29: ; preds = %24
store i32 0, i32* %7
%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, %24, %13
br label %32
32: ; preds = %31
%33 = load i32, i32* %8
%34 = add i32 %33, 1
store i32 %34, i32* %8
br label %9
35: ; preds = %9
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
ret void
}

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