#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 read_bytes(char *mem, long addr, unsigned int size) {
  while (size) {
    int i = 16;
    printf("0x%lx: ", addr);
    for (; i > 0 && size > 0; i--, size--, addr++) {
      printf("%.2x ", *mem++);
    }
    printf("\n");
  }
}


x86 assembly (clang, -O0):
<read_bytes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11c5 <read_bytes+0xb5>
movl   $0x10,-0x18(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xec1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
cmpl   $0x0,-0x18(%rbp)
mov    %al,-0x19(%rbp)
jle    115f <read_bytes+0x4f>
cmpl   $0x0,-0x14(%rbp)
seta   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    116f <read_bytes+0x5f>
jmp    11b2 <read_bytes+0xa2>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movsbl (%rax),%esi
lea    0xe80(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1146 <read_bytes+0x36>
lea    0xe55(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1123 <read_bytes+0x13>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_bytes>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
test   %edx,%edx
je     11c8 <read_bytes+0xa8>
mov    %edx,%ebx
mov    %rdi,%rbp
lea    0xec6(%rip),%r13
jmp    116e <read_bytes+0x4e>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0x10(%rsp),%rsi
add    %r12,%rsi
add    %r12,%rbp
mov    0xc(%rsp),%ebx
sub    %r12d,%ebx
je     11c8 <read_bytes+0xa8>
lea    0xe8b(%rip),%rdi
mov    %rsi,0x10(%rsp)
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,0xc(%rsp)
mov    %ebx,%ebx
add    $0xffffffffffffffff,%rbx
mov    $0x10,%r15d
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsbl 0x0(%rbp,%r14,1),%esi
mov    %r13,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x1(%r14),%r12
cmp    $0x2,%r15d
jb     1150 <read_bytes+0x30>
add    $0xffffffff,%r15d
cmp    %r14d,%ebx
mov    %r12,%r14
jne    11a0 <read_bytes+0x80>
jmp    1150 <read_bytes+0x30>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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