#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 */
typedef int /*<<< orphan*/ data;

/* Variables and functions */
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int read(int /*<<< orphan*/, unsigned char *, int);
int /*<<< orphan*/ stdout;
int main() {
  unsigned char data[512];
  size_t addr = 0;
  int iRead = 0;
  while ((iRead = read(0, data, sizeof(data))) > 0) {
    int i;
    for (i = 0; i < iRead; ++i) {
      printf(" %02X", data[i]);
      addr++;
    }
    printf("\n");
    fflush(stdout);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x218(%rbp)
movl   $0x0,-0x21c(%rbp)
lea    -0x210(%rbp),%rsi
xor    %edi,%edi
mov    $0x200,%edx
call   1040 <read@plt>
mov    %eax,-0x21c(%rbp)
cmp    $0x0,%eax
jle    11f9 <main+0xc9>
movl   $0x0,-0x220(%rbp)
mov    -0x220(%rbp),%eax
cmp    -0x21c(%rbp),%eax
jge    11d8 <main+0xa8>
movslq -0x220(%rbp),%rax
movzbl -0x210(%rbp,%rax,1),%esi
ff
lea    0xe55(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x218(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x218(%rbp)
mov    -0x220(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x220(%rbp)
jmp    1183 <main+0x53>
lea    0xe27(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2df3(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
jmp    1157 <main+0x27>
xor    %eax,%eax
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x200,%rsp
mov    %rsp,%rsi
xor    %edi,%edi
mov    $0x200,%edx
call   1050 <read@plt>
test   %eax,%eax
jle    11cc <main+0x8c>
lea    0xe96(%rip),%r12
mov    0x2e6f(%rip),%r15
mov    %rsp,%r14
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %eax,%r13d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
movzbl (%rsp,%rbx,1),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r13
jne    1190 <main+0x50>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    (%r15),%edi
call   1060 <fflush@plt>
xor    %edi,%edi
mov    %r14,%rsi
mov    $0x200,%edx
call   1050 <read@plt>
test   %eax,%eax
jg     1180 <main+0x40>
xor    %eax,%eax
add    $0x200,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

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