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

/* Variables and functions */
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
int dump(FILE *infile, FILE *outfile, int offset, int size) {
  char dumpbuf[512];
  int oldoff;
  oldoff = ftell(infile);
  fseek(infile, offset, SEEK_SET);
  for (; size >= 512; size -= 512) {
    fread(dumpbuf, 1, 512, infile);
    fwrite(dumpbuf, 1, 512, outfile);
  }
  if (size) {
    fread(dumpbuf, 1, size, infile);
    fwrite(dumpbuf, 1, size, outfile);
  }
  fseek(infile, oldoff, SEEK_SET);
}


x86 assembly (clang, -O0):
<dump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <ftell@plt>
mov    %eax,-0x224(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    0x2e6a(%rip),%rax
mov    (%rax),%edx
call   1050 <fseek@plt>
cmpl   $0x200,-0x20(%rbp)
jl     11ce <dump+0x8e>
lea    -0x220(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
mov    $0x200,%edx
call   1030 <fread@plt>
lea    -0x220(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
mov    $0x200,%edx
call   1060 <fwrite@plt>
mov    -0x20(%rbp),%eax
sub    $0x200,%eax
mov    %eax,-0x20(%rbp)
jmp    117d <dump+0x3d>
cmpl   $0x0,-0x20(%rbp)
je     1208 <dump+0xc8>
lea    -0x220(%rbp),%rdi
mov    -0x20(%rbp),%edx
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
lea    -0x220(%rbp),%rdi
mov    -0x20(%rbp),%edx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   1060 <fwrite@plt>
mov    -0x10(%rbp),%rdi
mov    -0x224(%rbp),%esi
mov    0x2dc7(%rip),%rax
mov    (%rax),%edx
call   1050 <fseek@plt>
mov    -0x4(%rbp),%eax
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x208,%rsp
mov    %ecx,%ebp
mov    %edx,%ebx
mov    %rsi,%r15
mov    %rdi,%r12
call   1040 <ftell@plt>
mov    %eax,%r14d
mov    0x2e76(%rip),%rax
mov    (%rax),%edx
mov    %r12,%rdi
mov    %ebx,%esi
call   1050 <fseek@plt>
cmp    $0x200,%ebp
jl     121a <dump+0xda>
mov    %rsp,%r13
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r13,%rdi
mov    $0x1,%esi
mov    $0x200,%edx
mov    %r12,%rcx
call   1030 <fread@plt>
mov    %r13,%rdi
mov    $0x1,%esi
mov    $0x200,%edx
mov    %r15,%rcx
call   1060 <fwrite@plt>
lea    -0x200(%rbp),%ebx
cmp    $0x3ff,%ebp
mov    %ebx,%ebp
ja     1190 <dump+0x50>
test   %ebx,%ebx
je     11f5 <dump+0xb5>
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    $0x1,%esi
mov    %ebx,%edx
mov    %r12,%rcx
call   1030 <fread@plt>
mov    %rbp,%rdi
mov    $0x1,%esi
mov    %ebx,%edx
mov    %r15,%rcx
call   1060 <fwrite@plt>
mov    0x2de4(%rip),%rax
mov    (%rax),%edx
mov    %r12,%rdi
mov    %r14d,%esi
add    $0x208,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <fseek@plt>
mov    %ebp,%ebx
test   %ebx,%ebx
jne    11ce <dump+0x8e>
jmp    11f5 <dump+0xb5>

LLVM IR (-O0):
@SEEK_SET = global i32 0
define i32 @dump(i32* %0, i32* %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca [512 x i8]
%11 = alloca i32
store i32* %0, i32** %6
store i32* %1, i32** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
%12 = load i32*, i32** %6
%13 = call i32 @ftell(i32* %12)
store i32 %13, i32* %11
%14 = load i32*, i32** %6
%15 = load i32, i32* %8
%16 = load i32, i32* @SEEK_SET
%17 = call i32 @fseek(i32* %14, i32 %15, i32 %16)
br label %18
18: ; preds = %28, %4
%19 = load i32, i32* %9
%20 = icmp sge i32 %19, 512
br i1 %20, label %21, label %31
21: ; preds = %18
%22 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
%23 = load i32*, i32** %6
%24 = call i32 @fread(i8* %22, i32 1, i32 512, i32* %23)
%25 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
%26 = load i32*, i32** %7
%27 = call i32 @fwrite(i8* %25, i32 1, i32 512, i32* %26)
br label %28
28: ; preds = %21
%29 = load i32, i32* %9
%30 = sub nsw i32 %29, 512
store i32 %30, i32* %9
br label %18
31: ; preds = %18
%32 = load i32, i32* %9
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %43
34: ; preds = %31
%35 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
%36 = load i32, i32* %9
%37 = load i32*, i32** %6
%38 = call i32 @fread(i8* %35, i32 1, i32 %36, i32* %37)
%39 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
%40 = load i32, i32* %9
%41 = load i32*, i32** %7
%42 = call i32 @fwrite(i8* %39, i32 1, i32 %40, i32* %41)
br label %43
43: ; preds = %34, %31
%44 = load i32*, i32** %6
%45 = load i32, i32* %11
%46 = load i32, i32* @SEEK_SET
%47 = call i32 @fseek(i32* %44, i32 %45, i32 %46)
%48 = load i32, i32* %5
ret i32 %48
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
define i32 @dump(i32* nocapture %0, i32* nocapture %1, i32 %2, i32 %3) {
%5 = alloca [512 x i8]
%6 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%7 = tail call i32 @ftell(i32* %0)
%8 = load i32, i32* @SEEK_SET
%9 = tail call i32 @fseek(i32* %0, i32 %2, i32 %8)
%10 = icmp sgt i32 %3, 511
br i1 %10, label %11, label %17
11: ; preds = %4, %11
%12 = phi i32 [ %15, %11 ], [ %3, %4 ]
%13 = call i32 @fread(i8* %6, i32 1, i32 512, i32* %0)
%14 = call i32 @fwrite(i8* %6, i32 1, i32 512, i32* %1)
%15 = add nsw i32 %12, -512
%16 = icmp ugt i32 %12, 1023
br i1 %16, label %11, label %17
17: ; preds = %11, %4
%18 = phi i32 [ %3, %4 ], [ %15, %11 ]
%19 = icmp eq i32 %18, 0
br i1 %19, label %23, label %20
20: ; preds = %17
%21 = call i32 @fread(i8* %6, i32 1, i32 %18, i32* %0)
%22 = call i32 @fwrite(i8* %6, i32 1, i32 %18, i32* %1)
br label %23
23: ; preds = %20, %17
%24 = load i32, i32* @SEEK_SET
%25 = tail call i32 @fseek(i32* %0, i32 %7, i32 %24)
ret i32 undef
}