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

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ SEEK_SET;
int errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
size_t fread(unsigned char *, int, long, int /*<<< orphan*/ *);
int fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
size_t fwrite(unsigned char *, int, long, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
void copy_bytes(FILE *infile, FILE *outfile, long offset, long count) {
  int rc;
  size_t size_rc;
  unsigned char buf[0x800];
  rc = fseek(infile, offset, SEEK_SET);
  do {
    if (rc == -1) {
      fflush(stdout);
      perror("error "
             "seek for copy");
      exit(EXIT_FAILURE);
    }
  } while (0);
  while (count > 0) {
    long dump_size = (count > sizeof(buf) ? sizeof(buf) : count);
    size_rc = fread(buf, 1, dump_size, infile);
    do {
      if (size_rc != dump_size) {
        int temperrno = errno;
        fflush(stdout);
        if (feof(infile)) {
          fprintf(stderr, "error "
                          "reading for copy"
                          ": eof\n");
        } else {
          errno = temperrno;
          perror("reading for copy");
        }
        exit(EXIT_FAILURE);
      }
    } while (0);
    size_rc = fwrite(buf, 1, dump_size, outfile);
    do {
      if (size_rc != dump_size) {
        int temperrno = errno;
        fflush(stdout);
        if (feof(outfile)) {
          fprintf(stderr, "error "
                          "writing for copy"
                          ": eof\n");
        } else {
          errno = temperrno;
          perror("writing for copy");
        }
        exit(EXIT_FAILURE);
      }
    } while (0);
    count -= dump_size;
  }
}


x86 assembly (clang, -O0):
<copy_bytes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x850,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    0x2e26(%rip),%rax
mov    (%rax),%edx
call   1070 <fseek@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    11e6 <copy_bytes+0x66>
mov    0x2dfb(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
lea    0xe2d(%rip),%rdi
call   1080 <perror@plt>
mov    0x2de9(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
jmp    11eb <copy_bytes+0x6b>
jmp    11f0 <copy_bytes+0x70>
cmpq   $0x0,-0x20(%rbp)
jle    139c <copy_bytes+0x21c>
cmpq   $0x800,-0x20(%rbp)
jbe    121a <copy_bytes+0x9a>
mov    $0x800,%eax
mov    %rax,-0x848(%rbp)
jmp    1225 <copy_bytes+0xa5>
mov    -0x20(%rbp),%rax
mov    %rax,-0x848(%rbp)
mov    -0x848(%rbp),%rax
mov    %rax,-0x838(%rbp)
lea    -0x830(%rbp),%rdi
mov    -0x838(%rbp),%rdx
mov    -0x8(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x838(%rbp),%rax
je     12d7 <copy_bytes+0x157>
mov    0x2d6d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x83c(%rbp)
mov    0x2d46(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
mov    -0x8(%rbp),%rdi
call   1050 <feof@plt>
cmp    $0x0,%rax
je     12ae <copy_bytes+0x12e>
mov    0x2d45(%rip),%rax
mov    (%rax),%edi
lea    0xd70(%rip),%rsi
call   1040 <fprintf@plt>
jmp    12c9 <copy_bytes+0x149>
mov    -0x83c(%rbp),%ecx
mov    0x2d1d(%rip),%rax
mov    %ecx,(%rax)
lea    0xd6d(%rip),%rdi
call   1080 <perror@plt>
mov    0x2cf8(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
jmp    12dc <copy_bytes+0x15c>
lea    -0x830(%rbp),%rdi
mov    -0x838(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
call   10a0 <fwrite@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x838(%rbp),%rax
je     1380 <copy_bytes+0x200>
mov    0x2cc4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x840(%rbp)
mov    0x2c9d(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
mov    -0x10(%rbp),%rdi
call   1050 <feof@plt>
cmp    $0x0,%rax
je     1357 <copy_bytes+0x1d7>
mov    0x2c9c(%rip),%rax
mov    (%rax),%edi
lea    0xcf5(%rip),%rsi
call   1040 <fprintf@plt>
jmp    1372 <copy_bytes+0x1f2>
mov    -0x840(%rbp),%ecx
mov    0x2c74(%rip),%rax
mov    %ecx,(%rax)
lea    0xcf2(%rip),%rdi
call   1080 <perror@plt>
mov    0x2c4f(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
jmp    1385 <copy_bytes+0x205>
mov    -0x838(%rbp),%rcx
mov    -0x20(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x20(%rbp)
jmp    11f0 <copy_bytes+0x70>
add    $0x850,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<copy_bytes>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x808,%rsp
mov    %rcx,%r13
mov    %rsi,%r14
mov    %rdi,%r15
mov    0x2e2f(%rip),%rax
mov    (%rax),%eax
mov    %rdx,%rsi
mov    %eax,%edx
call   1070 <fseek@plt>
cmp    $0xffffffff,%eax
je     1289 <copy_bytes+0x109>
test   %r13,%r13
jle    1208 <copy_bytes+0x88>
mov    %rsp,%r12
xchg   %ax,%ax
cmp    $0x800,%r13
mov    $0x800,%ebx
cmovb  %r13,%rbx
mov    %r12,%rdi
mov    $0x1,%esi
mov    %rbx,%rdx
mov    %r15,%rcx
call   1030 <fread@plt>
cmp    %rbx,%rax
jne    1249 <copy_bytes+0xc9>
mov    %r12,%rdi
mov    $0x1,%esi
mov    %rbx,%rdx
mov    %r14,%rcx
call   10a0 <fwrite@plt>
cmp    %rbx,%rax
jne    121a <copy_bytes+0x9a>
sub    %rbx,%r13
test   %r13,%r13
jg     11c0 <copy_bytes+0x40>
add    $0x808,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2db7(%rip),%rbx
mov    (%rbx),%ebp
mov    0x2d96(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
mov    %r14,%rdi
call   1050 <feof@plt>
test   %rax,%rax
jne    12a0 <copy_bytes+0x120>
mov    %ebp,(%rbx)
lea    0xe18(%rip),%rdi
jmp    1276 <copy_bytes+0xf6>
mov    0x2d88(%rip),%rbx
mov    (%rbx),%ebp
mov    0x2d67(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
mov    %r15,%rdi
call   1050 <feof@plt>
test   %rax,%rax
jne    12b7 <copy_bytes+0x137>
mov    %ebp,(%rbx)
lea    0xdbb(%rip),%rdi
call   1080 <perror@plt>
mov    0x2d46(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    0x2d30(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
lea    0xd62(%rip),%rdi
jmp    1276 <copy_bytes+0xf6>
mov    0x2d39(%rip),%rax
mov    (%rax),%edi
lea    0xd92(%rip),%rsi
call   1040 <fprintf@plt>
jmp    127b <copy_bytes+0xfb>
mov    0x2d22(%rip),%rax
mov    (%rax),%edi
lea    0xd4d(%rip),%rsi
call   1040 <fprintf@plt>
jmp    127b <copy_bytes+0xfb>

LLVM IR (-O0):
@SEEK_SET = global i32 0
@stdout = global i32 0
@.str = [20 x i8] c"error seek for copy\00"
@EXIT_FAILURE = global i32 0
@errno = global i32 0
@stderr = global i32 0
@.str.1 = [29 x i8] c"error reading for copy: eof\0A\00"
@.str.2 = [17 x i8] c"reading for copy\00"
@.str.3 = [29 x i8] c"error writing for copy: eof\0A\00"
@.str.4 = [17 x i8] c"writing for copy\00"
define void @copy_bytes(i32* %0, i32* %1, i64 %2, i64 %3) {
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i64
%8 = alloca i64
%9 = alloca i32
%10 = alloca i64
%11 = alloca [2048 x i8]
%12 = alloca i64
%13 = alloca i32
%14 = alloca i32
store i32* %0, i32** %5
store i32* %1, i32** %6
store i64 %2, i64* %7
store i64 %3, i64* %8
%15 = load i32*, i32** %5
%16 = load i64, i64* %7
%17 = load i32, i32* @SEEK_SET
%18 = call i32 @fseek(i32* %15, i64 %16, i32 %17)
store i32 %18, i32* %9
br label %19
19: ; preds = %4
%20 = load i32, i32* %9
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %28
22: ; preds = %19
%23 = load i32, i32* @stdout
%24 = call i32 @fflush(i32 %23)
%25 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%26 = load i32, i32* @EXIT_FAILURE
%27 = call i32 @exit(i32 %26)
unreachable
28: ; preds = %19
br label %29
29: ; preds = %28
br label %30
30: ; preds = %92, %29
%31 = load i64, i64* %8
%32 = icmp sgt i64 %31, 0
br i1 %32, label %33, label %96
33: ; preds = %30
%34 = load i64, i64* %8
%35 = icmp ugt i64 %34, 2048
br i1 %35, label %36, label %37
36: ; preds = %33
br label %39
37: ; preds = %33
%38 = load i64, i64* %8
br label %39
39: ; preds = %37, %36
%40 = phi i64 [ 2048, %36 ], [ %38, %37 ]
store i64 %40, i64* %12
%41 = getelementptr inbounds [2048 x i8], [2048 x i8]* %11, i64 0, i64 0
%42 = load i64, i64* %12
%43 = load i32*, i32** %5
%44 = call i64 @fread(i8* %41, i32 1, i64 %42, i32* %43)
store i64 %44, i64* %10
br label %45
45: ; preds = %39
%46 = load i64, i64* %10
%47 = load i64, i64* %12
%48 = icmp ne i64 %46, %47
br i1 %48, label %49, label %65
49: ; preds = %45
%50 = load i32, i32* @errno
store i32 %50, i32* %13
%51 = load i32, i32* @stdout
%52 = call i32 @fflush(i32 %51)
%53 = load i32*, i32** %5
%54 = call i64 @feof(i32* %53)
%55 = icmp ne i64 %54, 0
br i1 %55, label %56, label %59
56: ; preds = %49
%57 = load i32, i32* @stderr
%58 = call i32 @fprintf(i32 %57, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
br label %62
59: ; preds = %49
%60 = load i32, i32* %13
store i32 %60, i32* @errno
%61 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
br label %62
62: ; preds = %59, %56
%63 = load i32, i32* @EXIT_FAILURE
%64 = call i32 @exit(i32 %63)
unreachable
65: ; preds = %45
br label %66
66: ; preds = %65
%67 = getelementptr inbounds [2048 x i8], [2048 x i8]* %11, i64 0, i64 0
%68 = load i64, i64* %12
%69 = load i32*, i32** %6
%70 = call i64 @fwrite(i8* %67, i32 1, i64 %68, i32* %69)
store i64 %70, i64* %10
br label %71
71: ; preds = %66
%72 = load i64, i64* %10
%73 = load i64, i64* %12
%74 = icmp ne i64 %72, %73
br i1 %74, label %75, label %91
75: ; preds = %71
%76 = load i32, i32* @errno
store i32 %76, i32* %14
%77 = load i32, i32* @stdout
%78 = call i32 @fflush(i32 %77)
%79 = load i32*, i32** %6
%80 = call i64 @feof(i32* %79)
%81 = icmp ne i64 %80, 0
br i1 %81, label %82, label %85
82: ; preds = %75
%83 = load i32, i32* @stderr
%84 = call i32 @fprintf(i32 %83, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
br label %88
85: ; preds = %75
%86 = load i32, i32* %14
store i32 %86, i32* @errno
%87 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
br label %88
88: ; preds = %85, %82
%89 = load i32, i32* @EXIT_FAILURE
%90 = call i32 @exit(i32 %89)
unreachable
91: ; preds = %71
br label %92
92: ; preds = %91
%93 = load i64, i64* %12
%94 = load i64, i64* %8
%95 = sub nsw i64 %94, %93
store i64 %95, i64* %8
br label %30
96: ; preds = %30
ret void
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
@stdout = global i32 0
@.str = [20 x i8] c"error seek for copy\00"
@EXIT_FAILURE = global i32 0
@errno = global i32 0
@stderr = global i32 0
@.str.1 = [29 x i8] c"error reading for copy: eof\0A\00"
@.str.2 = [17 x i8] c"reading for copy\00"
@.str.3 = [29 x i8] c"error writing for copy: eof\0A\00"
@.str.4 = [17 x i8] c"writing for copy\00"
define void @copy_bytes(i32* nocapture %0, i32* nocapture %1, i64 %2, i64 %3) {
%5 = alloca [2048 x i8]
%6 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 0
%7 = load i32, i32* @SEEK_SET
%8 = tail call i32 @fseek(i32* %0, i64 %2, i32 %7)
%9 = icmp eq i32 %8, -1
br i1 %9, label %12, label %10
10: ; preds = %4
%11 = icmp sgt i64 %3, 0
br i1 %11, label %20, label %58
12: ; preds = %4
%13 = load i32, i32* @stdout
%14 = tail call i32 @fflush(i32 %13)
%15 = tail call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%16 = load i32, i32* @EXIT_FAILURE
%17 = tail call i32 @exit(i32 %16)
unreachable
18: ; preds = %40
%19 = icmp sgt i64 %43, 0
br i1 %19, label %20, label %58
20: ; preds = %10, %18
%21 = phi i64 [ %43, %18 ], [ %3, %10 ]
%22 = icmp ult i64 %21, 2048
%23 = select i1 %22, i64 %21, i64 2048
%24 = call i64 @fread(i8* %6, i32 1, i64 %23, i32* %0)
%25 = icmp eq i64 %24, %23
br i1 %25, label %40, label %26
26: ; preds = %20
%27 = load i32, i32* @errno
%28 = load i32, i32* @stdout
%29 = tail call i32 @fflush(i32 %28)
%30 = tail call i64 @feof(i32* %0)
%31 = icmp eq i64 %30, 0
br i1 %31, label %35, label %32
32: ; preds = %26
%33 = load i32, i32* @stderr
%34 = tail call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
br label %37
35: ; preds = %26
store i32 %27, i32* @errno
%36 = tail call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
br label %37
37: ; preds = %35, %32
%38 = load i32, i32* @EXIT_FAILURE
%39 = tail call i32 @exit(i32 %38)
unreachable
40: ; preds = %20
%41 = call i64 @fwrite(i8* %6, i32 1, i64 %23, i32* %1)
%42 = icmp eq i64 %41, %23
%43 = sub nsw i64 %21, %23
br i1 %42, label %18, label %44
44: ; preds = %40
%45 = load i32, i32* @errno
%46 = load i32, i32* @stdout
%47 = tail call i32 @fflush(i32 %46)
%48 = tail call i64 @feof(i32* %1)
%49 = icmp eq i64 %48, 0
br i1 %49, label %53, label %50
50: ; preds = %44
%51 = load i32, i32* @stderr
%52 = tail call i32 @fprintf(i32 %51, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
br label %55
53: ; preds = %44
store i32 %45, i32* @errno
%54 = tail call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
br label %55
55: ; preds = %53, %50
%56 = load i32, i32* @EXIT_FAILURE
%57 = tail call i32 @exit(i32 %56)
unreachable
58: ; preds = %18, %10
ret void
}