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

/* Variables and functions */
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ exit(int);
int lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int read_auto_resume(int, char *, int);
int write_all(int, char *, int);
void dump(int fd, int d) {
  int r = lseek(fd, 0, SEEK_SET);
  do {
    if (r == -1) {
      perror("seeking output file");
      exit(1);
    }
  } while (0);
  char buffer[128 * 1024];
  for (;;) {
    ssize_t n = read_auto_resume(fd, buffer, sizeof(buffer));
    do {
      if (n == -1) {
        perror("reading output file");
        exit(1);
      }
    } while (0);
    if (!n)
      break;
    ssize_t m = write_all(d, buffer, n);
    do {
      if (m == -1) {
        perror("writing output");
        exit(1);
      }
    } while (0);
  }
}


x86 assembly (clang, -O0):
<dump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20020,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e75(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1040 <lseek@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    1197 <dump+0x47>
lea    0xe78(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
jmp    119c <dump+0x4c>
jmp    11a1 <dump+0x51>
mov    -0x4(%rbp),%edi
lea    -0x20010(%rbp),%rsi
mov    $0x20000,%edx
call   1030 <read_auto_resume@plt>
mov    %eax,-0x20014(%rbp)
cmpl   $0xffffffff,-0x20014(%rbp)
jne    11de <dump+0x8e>
lea    0xe45(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
jmp    11e3 <dump+0x93>
cmpl   $0x0,-0x20014(%rbp)
jne    11f5 <dump+0xa5>
jmp    123d <dump+0xed>
mov    -0x8(%rbp),%edi
lea    -0x20010(%rbp),%rsi
mov    -0x20014(%rbp),%edx
call   1050 <write_all@plt>
mov    %eax,-0x20018(%rbp)
cmpl   $0xffffffff,-0x20018(%rbp)
jne    1233 <dump+0xe3>
lea    0xe04(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
jmp    1238 <dump+0xe8>
jmp    11a1 <dump+0x51>
add    $0x20020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20000,%rsp
mov    %esi,%r14d
mov    %edi,%ebp
mov    0x2e79(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1040 <lseek@plt>
cmp    $0xffffffff,%eax
je     11d5 <dump+0x85>
mov    %rsp,%rbx
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x20000,%edx
call   1030 <read_auto_resume@plt>
test   %eax,%eax
je     11b3 <dump+0x63>
cmp    $0xffffffff,%eax
je     11bf <dump+0x6f>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1050 <write_all@plt>
cmp    $0xffffffff,%eax
jne    1180 <dump+0x30>
lea    0xe77(%rip),%rdi
jmp    11c6 <dump+0x76>
add    $0x20000,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe4e(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
lea    0xe24(%rip),%rdi
jmp    11c6 <dump+0x76>

LLVM IR (-O0):
@SEEK_SET = global i32 0
@.str = [20 x i8] c"seeking output file\00"
@.str.1 = [20 x i8] c"reading output file\00"
@.str.2 = [15 x i8] c"writing output\00"
define void @dump(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [131072 x i8]
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%9 = load i32, i32* %3
%10 = load i32, i32* @SEEK_SET
%11 = call i32 @lseek(i32 %9, i32 0, i32 %10)
store i32 %11, i32* %5
br label %12
12: ; preds = %2
%13 = load i32, i32* %5
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %12
br label %19
19: ; preds = %18
br label %20
20: ; preds = %47, %19
%21 = load i32, i32* %3
%22 = getelementptr inbounds [131072 x i8], [131072 x i8]* %6, i64 0, i64 0
%23 = call i32 @read_auto_resume(i32 %21, i8* %22, i32 131072)
store i32 %23, i32* %7
br label %24
24: ; preds = %20
%25 = load i32, i32* %7
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %30
27: ; preds = %24
%28 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %24
br label %31
31: ; preds = %30
%32 = load i32, i32* %7
%33 = icmp ne i32 %32, 0
br i1 %33, label %35, label %34
34: ; preds = %31
br label %48
35: ; preds = %31
%36 = load i32, i32* %4
%37 = getelementptr inbounds [131072 x i8], [131072 x i8]* %6, i64 0, i64 0
%38 = load i32, i32* %7
%39 = call i32 @write_all(i32 %36, i8* %37, i32 %38)
store i32 %39, i32* %8
br label %40
40: ; preds = %35
%41 = load i32, i32* %8
%42 = icmp eq i32 %41, -1
br i1 %42, label %43, label %46
43: ; preds = %40
%44 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%45 = call i32 @exit(i32 1)
unreachable
46: ; preds = %40
br label %47
47: ; preds = %46
br label %20
48: ; preds = %34
ret void
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
@.str = [20 x i8] c"seeking output file\00"
@.str.1 = [20 x i8] c"reading output file\00"
@.str.2 = [15 x i8] c"writing output\00"
define void @dump(i32 %0, i32 %1) {
%3 = alloca [131072 x i8]
%4 = load i32, i32* @SEEK_SET
%5 = tail call i32 @lseek(i32 %0, i32 0, i32 %4)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = tail call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %2
%11 = getelementptr inbounds [131072 x i8], [131072 x i8]* %3, i64 0, i64 0
br label %12
12: ; preds = %17, %10
%13 = call i32 @read_auto_resume(i32 %0, i8* %11, i32 131072)
switch i32 %13, label %17 [
i32 -1, label %14
i32 0, label %23
]
14: ; preds = %12
%15 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %12
%18 = call i32 @write_all(i32 %1, i8* %11, i32 %13)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %12
20: ; preds = %17
%21 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %12
ret void
}