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

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int fread(unsigned char *, unsigned long, int, int /*<<< orphan*/ *);
int fwrite(unsigned char *, unsigned long, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int dump_file(FILE *infile, FILE *outfile, unsigned long size) {
  unsigned char buffer[0x200];
  for (; size >= sizeof(buffer); size -= sizeof(buffer)) {
    if (1 != fread(buffer, sizeof(buffer), 1, infile)) {
      fprintf(stderr, "error reading for dump\n");
      return 1;
    }
    if (1 != fwrite(buffer, sizeof(buffer), 1, outfile)) {
      perror("fwrite");
      fprintf(stderr, "error writing dump\n");
      return 1;
    }
  }
  if (size > 0) {
    if (1 != fread(buffer, size, 1, infile)) {
      fprintf(stderr, "error reading for dump\n");
      return 1;
    }
    if (1 != fwrite(buffer, size, 1, outfile)) {
      perror("fwrite");
      fprintf(stderr, "error writing dump\n");
      return 1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<dump_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x200,-0x20(%rbp)
jb     121d <dump_file+0xdd>
lea    -0x220(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x200,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cmp    %ecx,%eax
je     11af <dump_file+0x6f>
mov    0x2e4b(%rip),%rax
mov    (%rax),%edi
lea    0xe62(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12d2 <dump_file+0x192>
lea    -0x220(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x200,%esi
mov    $0x1,%edx
call   1060 <fwrite@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cmp    %ecx,%eax
je     1205 <dump_file+0xc5>
lea    0xe39(%rip),%rdi
call   1050 <perror@plt>
mov    0x2df5(%rip),%rax
mov    (%rax),%edi
lea    0xe2b(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12d2 <dump_file+0x192>
jmp    120a <dump_file+0xca>
mov    -0x20(%rbp),%rax
sub    $0x200,%rax
mov    %rax,-0x20(%rbp)
jmp    1157 <dump_file+0x17>
cmpq   $0x0,-0x20(%rbp)
jbe    12cb <dump_file+0x18b>
lea    -0x220(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x10(%rbp),%rcx
mov    $0x1,%edx
call   1030 <fread@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cmp    %ecx,%eax
je     1271 <dump_file+0x131>
mov    0x2d89(%rip),%rax
mov    (%rax),%edi
lea    0xda0(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12d2 <dump_file+0x192>
lea    -0x220(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rcx
mov    $0x1,%edx
call   1060 <fwrite@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cmp    %ecx,%eax
je     12c6 <dump_file+0x186>
lea    0xd78(%rip),%rdi
call   1050 <perror@plt>
mov    0x2d34(%rip),%rax
mov    (%rax),%edi
lea    0xd6a(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12d2 <dump_file+0x192>
jmp    12cb <dump_file+0x18b>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_file>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x200,%rsp
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %rdi,%r15
cmp    $0x200,%rdx
jb     11b4 <dump_file+0x74>
mov    %rsp,%rbp
lea    0xe95(%rip),%r12
nopl   0x0(%rax,%rax,1)
mov    $0x200,%esi
mov    %rbp,%rdi
mov    $0x1,%edx
mov    %r15,%rcx
call   1030 <fread@plt>
cmp    $0x1,%eax
jne    1207 <dump_file+0xc7>
mov    $0x200,%esi
mov    %rbp,%rdi
mov    $0x1,%edx
mov    %r14,%rcx
call   1060 <fwrite@plt>
cmp    $0x1,%eax
jne    11eb <dump_file+0xab>
add    $0xfffffffffffffe00,%rbx
cmp    $0x1ff,%rbx
ja     1170 <dump_file+0x30>
xor    %ebp,%ebp
test   %rbx,%rbx
je     121d <dump_file+0xdd>
mov    %rsp,%rdi
mov    %rbx,%rsi
mov    $0x1,%edx
mov    %r15,%rcx
call   1030 <fread@plt>
cmp    $0x1,%eax
jne    1200 <dump_file+0xc0>
mov    %rsp,%rdi
mov    %rbx,%rsi
mov    $0x1,%edx
mov    %r14,%rcx
call   1060 <fwrite@plt>
cmp    $0x1,%eax
je     121d <dump_file+0xdd>
lea    0xe26(%rip),%rdi
call   1050 <perror@plt>
lea    0xe21(%rip),%r12
jmp    1207 <dump_file+0xc7>
lea    0xdf9(%rip),%r12
mov    0x2dd2(%rip),%rax
mov    (%rax),%edi
mov    %r12,%rsi
call   1040 <fprintf@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x200,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [24 x i8] c"error reading for dump\0A\00"
@.str.1 = [7 x i8] c"fwrite\00"
@.str.2 = [20 x i8] c"error writing dump\0A\00"
define i32 @dump_file(i32* %0, i32* %1, i64 %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i64
%8 = alloca [512 x i8]
store i32* %0, i32** %5
store i32* %1, i32** %6
store i64 %2, i64* %7
br label %9
9: ; preds = %30, %3
%10 = load i64, i64* %7
%11 = icmp uge i64 %10, 512
br i1 %11, label %12, label %33
12: ; preds = %9
%13 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%14 = load i32*, i32** %5
%15 = call i32 @fread(i8* %13, i64 512, i32 1, i32* %14)
%16 = icmp ne i32 1, %15
br i1 %16, label %17, label %20
17: ; preds = %12
%18 = load i32, i32* @stderr
%19 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %4
br label %57
20: ; preds = %12
%21 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%22 = load i32*, i32** %6
%23 = call i32 @fwrite(i8* %21, i64 512, i32 1, i32* %22)
%24 = icmp ne i32 1, %23
br i1 %24, label %25, label %29
25: ; preds = %20
%26 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%27 = load i32, i32* @stderr
%28 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %4
br label %57
29: ; preds = %20
br label %30
30: ; preds = %29
%31 = load i64, i64* %7
%32 = sub i64 %31, 512
store i64 %32, i64* %7
br label %9
33: ; preds = %9
%34 = load i64, i64* %7
%35 = icmp ugt i64 %34, 0
br i1 %35, label %36, label %56
36: ; preds = %33
%37 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%38 = load i64, i64* %7
%39 = load i32*, i32** %5
%40 = call i32 @fread(i8* %37, i64 %38, i32 1, i32* %39)
%41 = icmp ne i32 1, %40
br i1 %41, label %42, label %45
42: ; preds = %36
%43 = load i32, i32* @stderr
%44 = call i32 @fprintf(i32 %43, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %4
br label %57
45: ; preds = %36
%46 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%47 = load i64, i64* %7
%48 = load i32*, i32** %6
%49 = call i32 @fwrite(i8* %46, i64 %47, i32 1, i32* %48)
%50 = icmp ne i32 1, %49
br i1 %50, label %51, label %55
51: ; preds = %45
%52 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%53 = load i32, i32* @stderr
%54 = call i32 @fprintf(i32 %53, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %4
br label %57
55: ; preds = %45
br label %56
56: ; preds = %55, %33
store i32 0, i32* %4
br label %57
57: ; preds = %56, %51, %42, %25, %17
%58 = load i32, i32* %4
ret i32 %58
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [24 x i8] c"error reading for dump\0A\00"
@.str.1 = [7 x i8] c"fwrite\00"
@.str.2 = [20 x i8] c"error writing dump\0A\00"
define i32 @dump_file(i32* nocapture %0, i32* nocapture %1, i64 %2) {
%4 = alloca [512 x i8]
%5 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%6 = icmp ugt i64 %2, 511
br i1 %6, label %7, label %17
7: ; preds = %3, %14
%8 = phi i64 [ %15, %14 ], [ %2, %3 ]
%9 = call i32 @fread(i8* %5, i64 512, i32 1, i32* %0)
%10 = icmp eq i32 %9, 1
br i1 %10, label %11, label %28
11: ; preds = %7
%12 = call i32 @fwrite(i8* %5, i64 512, i32 1, i32* %1)
%13 = icmp eq i32 %12, 1
br i1 %13, label %14, label %26
14: ; preds = %11
%15 = add i64 %8, -512
%16 = icmp ugt i64 %15, 511
br i1 %16, label %7, label %17
17: ; preds = %14, %3
%18 = phi i64 [ %2, %3 ], [ %15, %14 ]
%19 = icmp eq i64 %18, 0
br i1 %19, label %32, label %20
20: ; preds = %17
%21 = call i32 @fread(i8* %5, i64 %18, i32 1, i32* %0)
%22 = icmp eq i32 %21, 1
br i1 %22, label %23, label %28
23: ; preds = %20
%24 = call i32 @fwrite(i8* %5, i64 %18, i32 1, i32* %1)
%25 = icmp eq i32 %24, 1
br i1 %25, label %32, label %26
26: ; preds = %11, %23
%27 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %28
28: ; preds = %7, %26, %20
%29 = phi i8* [ getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), %20 ], [ getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), %26 ], [ getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), %7 ]
%30 = load i32, i32* @stderr
%31 = tail call i32 @fprintf(i32 %30, i8* %29)
br label %32
32: ; preds = %28, %17, %23
%33 = phi i32 [ 0, %23 ], [ 0, %17 ], [ 1, %28 ]
ret i32 %33
}