#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*/ fputc(char, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, unsigned char);
int /*<<< orphan*/ stdout;
extern void print_byte(unsigned char *ptr, unsigned int size) {
  unsigned char *first_character;
  int ch;
  first_character = (ptr + size - 1);
  for (ch = 1; ch <= size; ++ch) {
    printf("%.2x", *first_character);
    fputc(' ', stdout);
    --(first_character);
  }
  fputc('\n', stdout);
}


x86 assembly (clang, -O0):
<print_byte>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
ja     1194 <print_byte+0x74>
mov    -0x18(%rbp),%rax
lea    0xea1(%rip),%rdi
movzbl (%rax),%esi
call   1030 <printf@plt>
mov    0x2e72(%rip),%rax
mov    (%rax),%esi
mov    $0x20,%edi
call   1040 <fputc@plt>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1148 <print_byte+0x28>
mov    0x2e45(%rip),%rax
mov    (%rax),%esi
mov    $0xa,%edi
call   1040 <fputc@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_byte>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
je     1164 <print_byte+0x44>
mov    %rdi,%r15
mov    %esi,%ebx
lea    0xec8(%rip),%r14
mov    0x2ea1(%rip),%r12
nop
movzbl -0x1(%r15,%rbx,1),%esi
mov    %r14,%rdi
call   1030 <printf@plt>
mov    (%r12),%esi
mov    $0x20,%edi
call   1040 <fputc@plt>
add    $0xffffffffffffffff,%rbx
test   %ebx,%ebx
jne    1140 <print_byte+0x20>
mov    0x2e75(%rip),%rax
mov    (%rax),%esi
mov    $0xa,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1040 <fputc@plt>

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

LLVM IR (-O2):
@.str = [5 x i8] c"%.2x\00"
@stdout = global i32 0
define void @print_byte(i8* nocapture %0, i32 %1) {
%3 = icmp eq i32 %1, 0
br i1 %3, label %17, label %4
4: ; preds = %2
%5 = zext i32 %1 to i64
%6 = getelementptr inbounds i8, i8* %0, i64 %5
br label %7
7: ; preds = %4, %7
%8 = phi i8* [ %10, %7 ], [ %6, %4 ]
%9 = phi i32 [ %15, %7 ], [ 1, %4 ]
%10 = getelementptr inbounds i8, i8* %8, i64 -1
%11 = load i8, i8* %10
%12 = tail call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %11)
%13 = load i32, i32* @stdout
%14 = tail call i32 @fputc(i8 signext 32, i32 %13)
%15 = add nuw i32 %9, 1
%16 = icmp eq i32 %9, %1
br i1 %16, label %17, label %7
17: ; preds = %7, %2
%18 = load i32, i32* @stdout
%19 = tail call i32 @fputc(i8 signext 10, i32 %18)
ret void
}