#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*/ 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;
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) {
      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;
        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;
        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    0x2e36(%rip),%rax
mov    (%rax),%edx
call   1060 <fseek@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    11c8 <copy_bytes+0x58>
lea    0xe4b(%rip),%rdi
call   1070 <perror@plt>
mov    0x2e07(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
jmp    11cd <copy_bytes+0x5d>
jmp    11d2 <copy_bytes+0x62>
cmpq   $0x0,-0x20(%rbp)
jle    1362 <copy_bytes+0x1f2>
cmpq   $0x800,-0x20(%rbp)
jbe    11fc <copy_bytes+0x8c>
mov    $0x800,%eax
mov    %rax,-0x848(%rbp)
jmp    1207 <copy_bytes+0x97>
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     12ab <copy_bytes+0x13b>
mov    0x2d8b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x83c(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <feof@plt>
cmp    $0x0,%rax
je     1282 <copy_bytes+0x112>
mov    0x2d71(%rip),%rax
mov    (%rax),%edi
lea    0xd9c(%rip),%rsi
call   1040 <fprintf@plt>
jmp    129d <copy_bytes+0x12d>
mov    -0x83c(%rbp),%ecx
mov    0x2d49(%rip),%rax
mov    %ecx,(%rax)
lea    0xd99(%rip),%rdi
call   1070 <perror@plt>
mov    0x2d24(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
jmp    12b0 <copy_bytes+0x140>
lea    -0x830(%rbp),%rdi
mov    -0x838(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
call   1090 <fwrite@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x838(%rbp),%rax
je     1346 <copy_bytes+0x1d6>
mov    0x2cf0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x840(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <feof@plt>
cmp    $0x0,%rax
je     131d <copy_bytes+0x1ad>
mov    0x2cd6(%rip),%rax
mov    (%rax),%edi
lea    0xd2f(%rip),%rsi
call   1040 <fprintf@plt>
jmp    1338 <copy_bytes+0x1c8>
mov    -0x840(%rbp),%ecx
mov    0x2cae(%rip),%rax
mov    %ecx,(%rax)
lea    0xd2c(%rip),%rdi
call   1070 <perror@plt>
mov    0x2c89(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
jmp    134b <copy_bytes+0x1db>
mov    -0x838(%rbp),%rcx
mov    -0x20(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x20(%rbp)
jmp    11d2 <copy_bytes+0x62>
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    0x2e3f(%rip),%rax
mov    (%rax),%eax
mov    %rdx,%rsi
mov    %eax,%edx
call   1060 <fseek@plt>
cmp    $0xffffffff,%eax
je     125d <copy_bytes+0xed>
test   %r13,%r13
jle    11f8 <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    122b <copy_bytes+0xbb>
mov    %r12,%rdi
mov    $0x1,%esi
mov    %rbx,%rdx
mov    %r14,%rcx
call   1090 <fwrite@plt>
cmp    %rbx,%rax
jne    120a <copy_bytes+0x9a>
sub    %rbx,%r13
test   %r13,%r13
jg     11b0 <copy_bytes+0x40>
add    $0x808,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2dc7(%rip),%rbx
mov    (%rbx),%ebp
mov    %r14,%rdi
call   1050 <feof@plt>
test   %rax,%rax
jne    1266 <copy_bytes+0xf6>
mov    %ebp,(%rbx)
lea    0xe36(%rip),%rdi
jmp    124a <copy_bytes+0xda>
mov    0x2da6(%rip),%rbx
mov    (%rbx),%ebp
mov    %r15,%rdi
call   1050 <feof@plt>
test   %rax,%rax
jne    127d <copy_bytes+0x10d>
mov    %ebp,(%rbx)
lea    0xde7(%rip),%rdi
call   1070 <perror@plt>
mov    0x2d72(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
lea    0xd9c(%rip),%rdi
jmp    124a <copy_bytes+0xda>
mov    0x2d73(%rip),%rax
mov    (%rax),%edi
lea    0xdcc(%rip),%rsi
call   1040 <fprintf@plt>
jmp    124f <copy_bytes+0xdf>
mov    0x2d5c(%rip),%rax
mov    (%rax),%edi
lea    0xd87(%rip),%rsi
call   1040 <fprintf@plt>
jmp    124f <copy_bytes+0xdf>

LLVM IR (-O0):
@SEEK_SET = 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 %26
22: ; preds = %19
%23 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%24 = load i32, i32* @EXIT_FAILURE
%25 = call i32 @exit(i32 %24)
unreachable
26: ; preds = %19
br label %27
27: ; preds = %26
br label %28
28: ; preds = %86, %27
%29 = load i64, i64* %8
%30 = icmp sgt i64 %29, 0
br i1 %30, label %31, label %90
31: ; preds = %28
%32 = load i64, i64* %8
%33 = icmp ugt i64 %32, 2048
br i1 %33, label %34, label %35
34: ; preds = %31
br label %37
35: ; preds = %31
%36 = load i64, i64* %8
br label %37
37: ; preds = %35, %34
%38 = phi i64 [ 2048, %34 ], [ %36, %35 ]
store i64 %38, i64* %12
%39 = getelementptr inbounds [2048 x i8], [2048 x i8]* %11, i64 0, i64 0
%40 = load i64, i64* %12
%41 = load i32*, i32** %5
%42 = call i64 @fread(i8* %39, i32 1, i64 %40, i32* %41)
store i64 %42, i64* %10
br label %43
43: ; preds = %37
%44 = load i64, i64* %10
%45 = load i64, i64* %12
%46 = icmp ne i64 %44, %45
br i1 %46, label %47, label %61
47: ; preds = %43
%48 = load i32, i32* @errno
store i32 %48, i32* %13
%49 = load i32*, i32** %5
%50 = call i64 @feof(i32* %49)
%51 = icmp ne i64 %50, 0
br i1 %51, label %52, label %55
52: ; preds = %47
%53 = load i32, i32* @stderr
%54 = call i32 @fprintf(i32 %53, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
br label %58
55: ; preds = %47
%56 = load i32, i32* %13
store i32 %56, i32* @errno
%57 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
br label %58
58: ; preds = %55, %52
%59 = load i32, i32* @EXIT_FAILURE
%60 = call i32 @exit(i32 %59)
unreachable
61: ; preds = %43
br label %62
62: ; preds = %61
%63 = getelementptr inbounds [2048 x i8], [2048 x i8]* %11, i64 0, i64 0
%64 = load i64, i64* %12
%65 = load i32*, i32** %6
%66 = call i64 @fwrite(i8* %63, i32 1, i64 %64, i32* %65)
store i64 %66, i64* %10
br label %67
67: ; preds = %62
%68 = load i64, i64* %10
%69 = load i64, i64* %12
%70 = icmp ne i64 %68, %69
br i1 %70, label %71, label %85
71: ; preds = %67
%72 = load i32, i32* @errno
store i32 %72, i32* %14
%73 = load i32*, i32** %6
%74 = call i64 @feof(i32* %73)
%75 = icmp ne i64 %74, 0
br i1 %75, label %76, label %79
76: ; preds = %71
%77 = load i32, i32* @stderr
%78 = call i32 @fprintf(i32 %77, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
br label %82
79: ; preds = %71
%80 = load i32, i32* %14
store i32 %80, i32* @errno
%81 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
br label %82
82: ; preds = %79, %76
%83 = load i32, i32* @EXIT_FAILURE
%84 = call i32 @exit(i32 %83)
unreachable
85: ; preds = %67
br label %86
86: ; preds = %85
%87 = load i64, i64* %12
%88 = load i64, i64* %8
%89 = sub nsw i64 %88, %87
store i64 %89, i64* %8
br label %28
90: ; preds = %28
ret void
}

LLVM IR (-O2):
@SEEK_SET = 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 %18, label %52
12: ; preds = %4
%13 = tail call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%14 = load i32, i32* @EXIT_FAILURE
%15 = tail call i32 @exit(i32 %14)
unreachable
16: ; preds = %36
%17 = icmp sgt i64 %39, 0
br i1 %17, label %18, label %52
18: ; preds = %10, %16
%19 = phi i64 [ %39, %16 ], [ %3, %10 ]
%20 = icmp ult i64 %19, 2048
%21 = select i1 %20, i64 %19, i64 2048
%22 = call i64 @fread(i8* %6, i32 1, i64 %21, i32* %0)
%23 = icmp eq i64 %22, %21
br i1 %23, label %36, label %24
24: ; preds = %18
%25 = load i32, i32* @errno
%26 = tail call i64 @feof(i32* %0)
%27 = icmp eq i64 %26, 0
br i1 %27, label %31, label %28
28: ; preds = %24
%29 = load i32, i32* @stderr
%30 = tail call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
br label %33
31: ; preds = %24
store i32 %25, i32* @errno
%32 = tail call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
br label %33
33: ; preds = %31, %28
%34 = load i32, i32* @EXIT_FAILURE
%35 = tail call i32 @exit(i32 %34)
unreachable
36: ; preds = %18
%37 = call i64 @fwrite(i8* %6, i32 1, i64 %21, i32* %1)
%38 = icmp eq i64 %37, %21
%39 = sub nsw i64 %19, %21
br i1 %38, label %16, label %40
40: ; preds = %36
%41 = load i32, i32* @errno
%42 = tail call i64 @feof(i32* %1)
%43 = icmp eq i64 %42, 0
br i1 %43, label %47, label %44
44: ; preds = %40
%45 = load i32, i32* @stderr
%46 = tail call i32 @fprintf(i32 %45, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
br label %49
47: ; preds = %40
store i32 %41, i32* @errno
%48 = tail call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
br label %49
49: ; preds = %47, %44
%50 = load i32, i32* @EXIT_FAILURE
%51 = tail call i32 @exit(i32 %50)
unreachable
52: ; preds = %16, %10
ret void
}