#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*/ SEEK_SET;
int /*<<< orphan*/ lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ read(int, char *, int);
void print_file(int fd) {
  lseek(fd, 0, SEEK_SET);
  int i = 0;
  char data_in[1];
  for (; i < 22; i++) {
    read(fd, &data_in[0], 1);
    printf("0x%02x ", (int)data_in[0]);
    if (i && (i + 1) % 10 == 0)
      printf("\n");
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<print_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e9b(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1040 <lseek@plt>
movl   $0x0,-0x8(%rbp)
cmpl   $0x16,-0x8(%rbp)
jge    11c4 <print_file+0x94>
mov    -0x4(%rbp),%edi
lea    -0x9(%rbp),%rsi
mov    $0x1,%edx
call   1050 <read@plt>
movsbl -0x9(%rbp),%esi
lea    0xe85(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x0,-0x8(%rbp)
je     11b1 <print_file+0x81>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11b1 <print_file+0x81>
lea    0xe5e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11b6 <print_file+0x86>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1155 <print_file+0x25>
lea    0xe3d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edi,%r12d
mov    0x2e8b(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1050 <lseek@plt>
lea    0x7(%rsp),%r14
mov    %r12d,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1060 <read@plt>
movsbl 0x7(%rsp),%esi
lea    0xe81(%rip),%r15
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x2,%r13b
xor    %ebp,%ebp
jmp    119c <print_file+0x5c>
add    $0xffffffff,%ebp
add    $0x1,%r13b
cmp    $0xffffffeb,%ebp
je     11e3 <print_file+0xa3>
movzbl %r13b,%eax
imul   $0xcd,%eax,%eax
shr    $0xa,%eax
and    $0xfffffffe,%eax
lea    (%rax,%rax,4),%eax
mov    $0x2,%bl
sub    %al,%bl
mov    %r12d,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1060 <read@plt>
movsbl 0x7(%rsp),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    %bpl,%bl
jne    1190 <print_file+0x50>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    1190 <print_file+0x50>
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):
@SEEK_SET = global i32 0
@.str = [8 x i8] c"0x%02x \00"
@.str.1 = [2 x i8] c"\0A\00"
define void @print_file(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [1 x i8]
store i32 %0, i32* %2
%5 = load i32, i32* %2
%6 = load i32, i32* @SEEK_SET
%7 = call i32 @lseek(i32 %5, i32 0, i32 %6)
store i32 0, i32* %3
br label %8
8: ; preds = %29, %1
%9 = load i32, i32* %3
%10 = icmp slt i32 %9, 22
br i1 %10, label %11, label %32
11: ; preds = %8
%12 = load i32, i32* %2
%13 = getelementptr inbounds [1 x i8], [1 x i8]* %4, i64 0, i64 0
%14 = call i32 @read(i32 %12, i8* %13, i32 1)
%15 = getelementptr inbounds [1 x i8], [1 x i8]* %4, i64 0, i64 0
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %17)
%19 = load i32, i32* %3
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %28
21: ; preds = %11
%22 = load i32, i32* %3
%23 = add nsw i32 %22, 1
%24 = srem i32 %23, 10
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %21
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %28
28: ; preds = %26, %21, %11
br label %29
29: ; preds = %28
%30 = load i32, i32* %3
%31 = add nsw i32 %30, 1
store i32 %31, i32* %3
br label %8
32: ; preds = %8
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
ret void
}

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