#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*/ buf;

/* Variables and functions */
int /*<<< orphan*/ SEEK_CUR;
int errno;
scalar_t__ lseek(int, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int /*<<< orphan*/ show(char *, int);
void dump(int fd) {
  char buf[1];
  int ret;
  size_t off, i;
  off = 0;
  while (1) {
    printf("0x%08zu:", off);
    for (i = 0; i < 8; ++i) {
      ret = read(fd, buf, sizeof(buf));
      if (ret > 0) {
        show(buf, ret);
      } else if (ret < 0) {
        printf(" (read error %d)", errno);
        if (lseek(fd, 1, SEEK_CUR) < 0) {
          printf(" (Seek failed %d)", errno);
          goto out;
        }
      } else {
        printf(" (eof)");
        goto out;
      }
      ++off;
    }
    printf("\n");
  }
out:
  return;
}


x86 assembly (clang, -O0):
<dump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xea2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movq   $0x0,-0x20(%rbp)
cmpq   $0x8,-0x20(%rbp)
jae    123e <dump+0xfe>
mov    -0x4(%rbp),%edi
lea    -0x5(%rbp),%rsi
mov    $0x1,%edx
call   1060 <read@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jle    11a7 <dump+0x67>
lea    -0x5(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1050 <show@plt>
jmp    1221 <dump+0xe1>
cmpl   $0x0,-0xc(%rbp)
jge    1209 <dump+0xc9>
mov    0x2e20(%rip),%rax
mov    (%rax),%esi
lea    0xe48(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%edi
mov    0x2e16(%rip),%rax
mov    (%rax),%edx
mov    $0x1,%esi
call   1040 <lseek@plt>
cmp    $0x0,%rax
jge    1204 <dump+0xc4>
mov    0x2de9(%rip),%rax
mov    (%rax),%esi
lea    0xe22(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1251 <dump+0x111>
jmp    121c <dump+0xdc>
lea    0xe1c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1251 <dump+0x111>
jmp    1221 <dump+0xe1>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    116d <dump+0x2d>
lea    0xdee(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1153 <dump+0x13>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edi,%ebx
lea    0xe9c(%rip),%rdi
lea    0x7(%rsp),%r15
lea    0xe99(%rip),%r12
mov    0x2e71(%rip),%r14
xor    %ebp,%ebp
jmp    1191 <dump+0x41>
nopl   0x0(%rax,%rax,1)
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xe6f(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x8,%rbp
mov    $0x8,%r13d
jmp    11c0 <dump+0x70>
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %eax,%esi
call   1060 <show@plt>
add    $0xffffffffffffffff,%r13
je     1180 <dump+0x30>
mov    %ebx,%edi
mov    %r15,%rsi
mov    $0x1,%edx
call   1070 <read@plt>
test   %eax,%eax
jg     11b0 <dump+0x60>
jns    1215 <dump+0xc5>
mov    0x2dfc(%rip),%rax
mov    (%rax),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%r14),%edx
mov    %ebx,%edi
mov    $0x1,%esi
call   1050 <lseek@plt>
test   %rax,%rax
jns    11ba <dump+0x6a>
mov    0x2dd5(%rip),%rax
mov    (%rax),%esi
lea    0xe0e(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1223 <dump+0xd3>
lea    0xe10(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"0x%08zu:\00"
@.str.1 = [17 x i8] c" (read error %d)\00"
@errno = global i32 0
@SEEK_CUR = global i32 0
@.str.2 = [18 x i8] c" (Seek failed %d)\00"
@.str.3 = [7 x i8] c" (eof)\00"
@.str.4 = [2 x i8] c"\0A\00"
define void @dump(i32 %0) {
%2 = alloca i32
%3 = alloca [1 x i8]
%4 = alloca i32
%5 = alloca i64
%6 = alloca i64
store i32 %0, i32* %2
store i64 0, i64* %5
br label %7
7: ; preds = %1, %46
%8 = load i64, i64* %5
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i64 %8)
store i64 0, i64* %6
br label %10
10: ; preds = %43, %7
%11 = load i64, i64* %6
%12 = icmp ult i64 %11, 8
br i1 %12, label %13, label %46
13: ; preds = %10
%14 = load i32, i32* %2
%15 = getelementptr inbounds [1 x i8], [1 x i8]* %3, i64 0, i64 0
%16 = call i32 @read(i32 %14, i8* %15, i32 1)
store i32 %16, i32* %4
%17 = load i32, i32* %4
%18 = icmp sgt i32 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %13
%20 = getelementptr inbounds [1 x i8], [1 x i8]* %3, i64 0, i64 0
%21 = load i32, i32* %4
%22 = call i32 @show(i8* %20, i32 %21)
br label %40
23: ; preds = %13
%24 = load i32, i32* %4
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %37
26: ; preds = %23
%27 = load i32, i32* @errno
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %27)
%29 = load i32, i32* %2
%30 = load i32, i32* @SEEK_CUR
%31 = call i64 @lseek(i32 %29, i32 1, i32 %30)
%32 = icmp slt i64 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %26
%34 = load i32, i32* @errno
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %34)
br label %48
36: ; preds = %26
br label %39
37: ; preds = %23
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
br label %48
39: ; preds = %36
br label %40
40: ; preds = %39, %19
%41 = load i64, i64* %5
%42 = add i64 %41, 1
store i64 %42, i64* %5
br label %43
43: ; preds = %40
%44 = load i64, i64* %6
%45 = add i64 %44, 1
store i64 %45, i64* %6
br label %10
46: ; preds = %10
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %7
48: ; preds = %37, %33
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c"0x%08zu:\00"
@.str.1 = [17 x i8] c" (read error %d)\00"
@errno = global i32 0
@SEEK_CUR = global i32 0
@.str.2 = [18 x i8] c" (Seek failed %d)\00"
@.str.3 = [7 x i8] c" (eof)\00"
define void @dump(i32 %0) {
%2 = alloca [1 x i8]
%3 = getelementptr inbounds [1 x i8], [1 x i8]* %2, i64 0, i64 0
br label %4
4: ; preds = %31, %1
%5 = phi i64 [ %33, %31 ], [ 8, %1 ]
%6 = phi i64 [ %8, %31 ], [ 0, %1 ]
%7 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i64 %6)
%8 = add i64 %6, 8
br label %9
9: ; preds = %4, %28
%10 = phi i64 [ %6, %4 ], [ %29, %28 ]
%11 = call i32 @read(i32 %0, i8* %3, i32 1)
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %9
%14 = call i32 @show(i8* %3, i32 %11)
br label %28
15: ; preds = %9
%16 = icmp slt i32 %11, 0
br i1 %16, label %17, label %26
17: ; preds = %15
%18 = load i32, i32* @errno
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %18)
%20 = load i32, i32* @SEEK_CUR
%21 = call i64 @lseek(i32 %0, i32 1, i32 %20)
%22 = icmp slt i64 %21, 0
br i1 %22, label %23, label %28
23: ; preds = %17
%24 = load i32, i32* @errno
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %24)
br label %34
26: ; preds = %15
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
br label %34
28: ; preds = %17, %13
%29 = add i64 %10, 1
%30 = icmp eq i64 %29, %5
br i1 %30, label %31, label %9
31: ; preds = %28
%32 = call i32 @putchar(i32 10)
%33 = add i64 %5, 8
br label %4
34: ; preds = %26, %23
ret void
}