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

/* Variables and functions */
int O_CREAT;
int O_RDONLY;
int O_WRONLY;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int lseek(int, int, int /*<<< orphan*/);
int open(char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int);
int read(int, unsigned char *, int);
int /*<<< orphan*/ stderr;
int write(int, unsigned char *, int);
int main(int argc, char **argv) {
  int fd, fdo;
  unsigned char data[0x200000];
  int i, n, skip;
  if (argc != 3) {
    fprintf(stderr, "%s infile outfile\n", argv[0]);
    exit(-1);
  }
  fd = open(argv[1], O_RDONLY);
  if (fd == -1) {
    fprintf(stderr, "Couldn't open %s\n", argv[1]);
    perror("open()");
    exit(-1);
  }
  fdo = open(argv[2], O_WRONLY | O_CREAT);
  if (fdo == -1) {
    fprintf(stderr, "Couldn't open %s\n", argv[2]);
    perror("open()");
    exit(-1);
  }
  skip = 65536;
  i = lseek(fd, skip, SEEK_SET);
  printf("lseek'd %d bytes\n", i);
  if (i == -1) {
    perror("lseek()");
  }
  while ((n = read(fd, data, 0x200000)) > 0) {
    printf("Read %d bytes\n", n);
    i = write(fdo, data, n);
    printf("Wrote %d bytes\n", i);
  }
  close(fdo);
  close(fd);
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x200030,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11d9 <main+0x49>
mov    0x2e16(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe36(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0xffffffff,%edi
call   10b0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2df8(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    122f <main+0x9f>
mov    0x2dcd(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xdff(%rip),%rsi
call   1080 <fprintf@plt>
lea    0xe05(%rip),%rdi
call   10a0 <perror@plt>
mov    $0xffffffff,%edi
call   10b0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    0x2d7a(%rip),%rax
mov    (%rax),%esi
mov    0x2db1(%rip),%rax
or     (%rax),%esi
call   1090 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    128e <main+0xfe>
mov    0x2d6e(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
lea    0xda0(%rip),%rsi
call   1080 <fprintf@plt>
lea    0xda6(%rip),%rdi
call   10a0 <perror@plt>
mov    $0xffffffff,%edi
call   10b0 <exit@plt>
movl   $0x10000,-0x20002c(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x20002c(%rbp),%esi
mov    0x2d20(%rip),%rax
mov    (%rax),%edx
call   1050 <lseek@plt>
mov    %eax,-0x200024(%rbp)
mov    -0x200024(%rbp),%esi
lea    0xd6a(%rip),%rdi
call   1040 <printf@plt>
cmpl   $0xffffffff,-0x200024(%rbp)
jne    12e0 <main+0x150>
lea    0xd63(%rip),%rdi
call   10a0 <perror@plt>
jmp    12e5 <main+0x155>
mov    -0x14(%rbp),%edi
lea    -0x200020(%rbp),%rsi
mov    $0x200000,%edx
call   1070 <read@plt>
mov    %eax,-0x200028(%rbp)
cmp    $0x0,%eax
jle    134c <main+0x1bc>
mov    -0x200028(%rbp),%esi
lea    0xd31(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%edi
lea    -0x200020(%rbp),%rsi
mov    -0x200028(%rbp),%edx
call   1030 <write@plt>
mov    %eax,-0x200024(%rbp)
mov    -0x200024(%rbp),%esi
lea    0xd13(%rip),%rdi
call   1040 <printf@plt>
jmp    12e5 <main+0x155>
mov    -0x18(%rbp),%edi
call   1060 <close@plt>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x200030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x200008,%rsp
mov    %rsi,%r14
cmp    $0x3,%edi
jne    12bc <main+0x12c>
mov    0x8(%r14),%rdi
mov    0x2e28(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
cmp    $0xffffffff,%eax
je     12de <main+0x14e>
mov    %eax,%r15d
mov    0x10(%r14),%rdi
mov    0x2de2(%rip),%rax
mov    0x2e1b(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
call   1090 <open@plt>
cmp    $0xffffffff,%eax
je     12ed <main+0x15d>
mov    %eax,%r13d
mov    0x2dcf(%rip),%rax
mov    (%rax),%edx
mov    %r15d,%edi
mov    $0x10000,%esi
call   1050 <lseek@plt>
mov    %eax,%ebx
lea    0xe1b(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
cmp    $0xffffffff,%ebx
je     12ab <main+0x11b>
mov    %rsp,%rsi
mov    %r15d,%edi
mov    $0x200000,%edx
call   1070 <read@plt>
test   %eax,%eax
jle    1287 <main+0xf7>
mov    %eax,%ebp
lea    0xe08(%rip),%r14
mov    %rsp,%rbx
lea    0xe0d(%rip),%r12
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %ebp,%esi
call   1040 <printf@plt>
mov    %r13d,%edi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1030 <write@plt>
mov    %r12,%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    $0x200000,%edx
call   1070 <read@plt>
mov    %eax,%ebp
test   %eax,%eax
jg     1250 <main+0xc0>
mov    %r13d,%edi
call   1060 <close@plt>
mov    %r15d,%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x200008,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd8c(%rip),%rdi
call   10a0 <perror@plt>
jmp    1221 <main+0x91>
mov    0x2d0d(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xd31(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0xffffffff,%edi
call   10b0 <exit@plt>
mov    0x2ceb(%rip),%rax
mov    (%rax),%edi
mov    0x8(%r14),%rdx
jmp    12fa <main+0x16a>
mov    0x2cdc(%rip),%rax
mov    (%rax),%edi
mov    0x10(%r14),%rdx
lea    0xd12(%rip),%rsi
call   1080 <fprintf@plt>
lea    0xd18(%rip),%rdi
call   10a0 <perror@plt>
mov    $0xffffffff,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [19 x i8] c"%s infile outfile\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [18 x i8] c"Couldn't open %s\0A\00"
@.str.2 = [7 x i8] c"open()\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@SEEK_SET = global i32 0
@.str.3 = [18 x i8] c"lseek'd %d bytes\0A\00"
@.str.4 = [8 x i8] c"lseek()\00"
@.str.5 = [15 x i8] c"Read %d bytes\0A\00"
@.str.6 = [16 x i8] c"Wrote %d bytes\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca [2097152 x i8]
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 3
br i1 %13, label %14, label %21
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
%19 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %18)
%20 = call i32 @exit(i32 -1)
unreachable
21: ; preds = %2
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = load i32, i32* @O_RDONLY
%26 = call i32 @open(i8* %24, i32 %25)
store i32 %26, i32* %6
%27 = load i32, i32* %6
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %37
29: ; preds = %21
%30 = load i32, i32* @stderr
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 1
%33 = load i8*, i8** %32
%34 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %33)
%35 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%36 = call i32 @exit(i32 -1)
unreachable
37: ; preds = %21
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 2
%40 = load i8*, i8** %39
%41 = load i32, i32* @O_WRONLY
%42 = load i32, i32* @O_CREAT
%43 = or i32 %41, %42
%44 = call i32 @open(i8* %40, i32 %43)
store i32 %44, i32* %7
%45 = load i32, i32* %7
%46 = icmp eq i32 %45, -1
br i1 %46, label %47, label %55
47: ; preds = %37
%48 = load i32, i32* @stderr
%49 = load i8**, i8*** %5
%50 = getelementptr inbounds i8*, i8** %49, i64 2
%51 = load i8*, i8** %50
%52 = call i32 @fprintf(i32 %48, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %51)
%53 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%54 = call i32 @exit(i32 -1)
unreachable
55: ; preds = %37
store i32 65536, i32* %11
%56 = load i32, i32* %6
%57 = load i32, i32* %11
%58 = load i32, i32* @SEEK_SET
%59 = call i32 @lseek(i32 %56, i32 %57, i32 %58)
store i32 %59, i32* %9
%60 = load i32, i32* %9
%61 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i32 %60)
%62 = load i32, i32* %9
%63 = icmp eq i32 %62, -1
br i1 %63, label %64, label %66
64: ; preds = %55
%65 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
br label %66
66: ; preds = %64, %55
br label %67
67: ; preds = %72, %66
%68 = load i32, i32* %6
%69 = getelementptr inbounds [2097152 x i8], [2097152 x i8]* %8, i64 0, i64 0
%70 = call i32 @read(i32 %68, i8* %69, i32 2097152)
store i32 %70, i32* %10
%71 = icmp sgt i32 %70, 0
br i1 %71, label %72, label %81
72: ; preds = %67
%73 = load i32, i32* %10
%74 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i32 %73)
%75 = load i32, i32* %7
%76 = getelementptr inbounds [2097152 x i8], [2097152 x i8]* %8, i64 0, i64 0
%77 = load i32, i32* %10
%78 = call i32 @write(i32 %75, i8* %76, i32 %77)
store i32 %78, i32* %9
%79 = load i32, i32* %9
%80 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0), i32 %79)
br label %67
81: ; preds = %67
%82 = load i32, i32* %7
%83 = call i32 @close(i32 %82)
%84 = load i32, i32* %6
%85 = call i32 @close(i32 %84)
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [19 x i8] c"%s infile outfile\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [18 x i8] c"Couldn't open %s\0A\00"
@.str.2 = [7 x i8] c"open()\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@SEEK_SET = global i32 0
@.str.3 = [18 x i8] c"lseek'd %d bytes\0A\00"
@.str.4 = [8 x i8] c"lseek()\00"
@.str.5 = [15 x i8] c"Read %d bytes\0A\00"
@.str.6 = [16 x i8] c"Wrote %d bytes\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [2097152 x i8]
%4 = getelementptr inbounds [2097152 x i8], [2097152 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 3
br i1 %5, label %11, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i8*, i8** %1
%9 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = tail call i32 @exit(i32 -1)
unreachable
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = load i32, i32* @O_RDONLY
%15 = tail call i32 @open(i8* %13, i32 %14)
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %23
17: ; preds = %11
%18 = load i32, i32* @stderr
%19 = load i8*, i8** %12
%20 = tail call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %19)
%21 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%22 = tail call i32 @exit(i32 -1)
unreachable
23: ; preds = %11
%24 = getelementptr inbounds i8*, i8** %1, i64 2
%25 = load i8*, i8** %24
%26 = load i32, i32* @O_WRONLY
%27 = load i32, i32* @O_CREAT
%28 = or i32 %27, %26
%29 = tail call i32 @open(i8* %25, i32 %28)
%30 = icmp eq i32 %29, -1
br i1 %30, label %31, label %37
31: ; preds = %23
%32 = load i32, i32* @stderr
%33 = load i8*, i8** %24
%34 = tail call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %33)
%35 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%36 = tail call i32 @exit(i32 -1)
unreachable
37: ; preds = %23
%38 = load i32, i32* @SEEK_SET
%39 = tail call i32 @lseek(i32 %15, i32 65536, i32 %38)
%40 = tail call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i32 %39)
%41 = icmp eq i32 %39, -1
br i1 %41, label %42, label %44
42: ; preds = %37
%43 = tail call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
br label %44
44: ; preds = %42, %37
%45 = call i32 @read(i32 %15, i8* %4, i32 2097152)
%46 = icmp sgt i32 %45, 0
br i1 %46, label %47, label %54
47: ; preds = %44, %47
%48 = phi i32 [ %52, %47 ], [ %45, %44 ]
%49 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i32 %48)
%50 = call i32 @write(i32 %29, i8* %4, i32 %48)
%51 = tail call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0), i32 %50)
%52 = call i32 @read(i32 %15, i8* %4, i32 2097152)
%53 = icmp sgt i32 %52, 0
br i1 %53, label %47, label %54
54: ; preds = %47, %44
%55 = tail call i32 @close(i32 %29)
%56 = tail call i32 @close(i32 %15)
ret i32 0
}