#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 *, ...);
int print_all_byte(void *addr, int size) {
  unsigned char *ptr = (unsigned char *)addr;
  int print_bytes = 0;
  if (ptr == NULL) {
    return -1;
  }
  while (print_bytes < size) {
    printf("%02x", *ptr);
    ptr++;
    print_bytes++;
  }
  printf("\n");
  return print_bytes;
}


x86 assembly (clang, -O0):
<print_all_byte>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1145 <print_all_byte+0x35>
movl   $0xffffffff,-0x4(%rbp)
jmp    1199 <print_all_byte+0x89>
jmp    114a <print_all_byte+0x3a>
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1185 <print_all_byte+0x75>
mov    -0x20(%rbp),%rax
movzbl (%rax),%esi
lea    0xe9c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    114a <print_all_byte+0x3a>
lea    0xe79(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_all_byte>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %rdi,%rdi
je     1169 <print_all_byte+0x49>
mov    %esi,%r14d
test   %esi,%esi
jle    1171 <print_all_byte+0x51>
mov    %rdi,%r12
mov    %r14d,%ebp
lea    0xebf(%rip),%r15
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movzbl (%r12,%rbx,1),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbx
cmp    %ebx,%ebp
jne    1150 <print_all_byte+0x30>
jmp    1174 <print_all_byte+0x54>
mov    $0xffffffff,%r14d
jmp    117e <print_all_byte+0x5e>
xor    %r14d,%r14d
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r14d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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