#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 /*<<< orphan*/ O_RDONLY;
int O_TRUNC;
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 | O_TRUNC, 0755);
  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    0x2e0e(%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    0x2df0(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1090 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1231 <main+0xa1>
mov    0x2dc3(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xdfd(%rip),%rsi
call   1080 <fprintf@plt>
lea    0xe03(%rip),%rdi
call   10a0 <perror@plt>
mov    $0xffffffff,%edi
call   10b0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    0x2d70(%rip),%rax
mov    (%rax),%esi
mov    0x2daf(%rip),%rax
or     (%rax),%esi
mov    0x2d9e(%rip),%rax
or     (%rax),%esi
mov    $0x1ed,%edx
mov    $0x0,%al
call   1090 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    12a0 <main+0x110>
mov    0x2d54(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
lea    0xd8e(%rip),%rsi
call   1080 <fprintf@plt>
lea    0xd94(%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    0x2d06(%rip),%rax
mov    (%rax),%edx
call   1050 <lseek@plt>
mov    %eax,-0x200024(%rbp)
mov    -0x200024(%rbp),%esi
lea    0xd58(%rip),%rdi
call   1040 <printf@plt>
cmpl   $0xffffffff,-0x200024(%rbp)
jne    12f2 <main+0x162>
lea    0xd51(%rip),%rdi
call   10a0 <perror@plt>
jmp    12f7 <main+0x167>
mov    -0x14(%rbp),%edi
lea    -0x200020(%rbp),%rsi
mov    $0x200000,%edx
call   1070 <read@plt>
mov    %eax,-0x200028(%rbp)
cmp    $0x0,%eax
jle    135e <main+0x1ce>
mov    -0x200028(%rbp),%esi
lea    0xd1f(%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    0xd01(%rip),%rdi
call   1040 <printf@plt>
jmp    12f7 <main+0x167>
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    12cc <main+0x13c>
mov    0x8(%r14),%rdi
mov    0x2e20(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
call   1090 <open@plt>
cmp    $0xffffffff,%eax
je     12ee <main+0x15e>
mov    %eax,%r15d
mov    0x2ddc(%rip),%rax
mov    0x2e1d(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x10(%r14),%rdi
mov    0x2e06(%rip),%rax
or     (%rax),%esi
mov    $0x1ed,%edx
xor    %eax,%eax
call   1090 <open@plt>
cmp    $0xffffffff,%eax
je     12fd <main+0x16d>
mov    %eax,%r13d
mov    0x2db5(%rip),%rax
mov    (%rax),%edx
mov    %r15d,%edi
mov    $0x10000,%esi
call   1050 <lseek@plt>
mov    %eax,%ebx
lea    0xe09(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
cmp    $0xffffffff,%ebx
je     12bb <main+0x12b>
mov    %rsp,%rsi
mov    %r15d,%edi
mov    $0x200000,%edx
call   1070 <read@plt>
test   %eax,%eax
jle    1297 <main+0x107>
mov    %eax,%ebp
lea    0xdf6(%rip),%r14
mov    %rsp,%rbx
lea    0xdfb(%rip),%r12
nopw   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     1260 <main+0xd0>
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    0xd7c(%rip),%rdi
call   10a0 <perror@plt>
jmp    1233 <main+0xa3>
mov    0x2cf5(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xd21(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0xffffffff,%edi
call   10b0 <exit@plt>
mov    0x2cd3(%rip),%rax
mov    (%rax),%edi
mov    0x8(%r14),%rdx
jmp    130a <main+0x17a>
mov    0x2cc4(%rip),%rax
mov    (%rax),%edi
mov    0x10(%r14),%rdx
lea    0xd02(%rip),%rsi
call   1080 <fprintf@plt>
lea    0xd08(%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
@O_TRUNC = 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 (i8*, 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 = load i32, i32* @O_TRUNC
%45 = or i32 %43, %44
%46 = call i32 (i8*, i32, ...) @open(i8* %40, i32 %45, i32 493)
store i32 %46, i32* %7
%47 = load i32, i32* %7
%48 = icmp eq i32 %47, -1
br i1 %48, label %49, label %57
49: ; preds = %37
%50 = load i32, i32* @stderr
%51 = load i8**, i8*** %5
%52 = getelementptr inbounds i8*, i8** %51, i64 2
%53 = load i8*, i8** %52
%54 = call i32 @fprintf(i32 %50, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %53)
%55 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%56 = call i32 @exit(i32 -1)
unreachable
57: ; preds = %37
store i32 65536, i32* %11
%58 = load i32, i32* %6
%59 = load i32, i32* %11
%60 = load i32, i32* @SEEK_SET
%61 = call i32 @lseek(i32 %58, i32 %59, i32 %60)
store i32 %61, i32* %9
%62 = load i32, i32* %9
%63 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i32 %62)
%64 = load i32, i32* %9
%65 = icmp eq i32 %64, -1
br i1 %65, label %66, label %68
66: ; preds = %57
%67 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
br label %68
68: ; preds = %66, %57
br label %69
69: ; preds = %74, %68
%70 = load i32, i32* %6
%71 = getelementptr inbounds [2097152 x i8], [2097152 x i8]* %8, i64 0, i64 0
%72 = call i32 @read(i32 %70, i8* %71, i32 2097152)
store i32 %72, i32* %10
%73 = icmp sgt i32 %72, 0
br i1 %73, label %74, label %83
74: ; preds = %69
%75 = load i32, i32* %10
%76 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i32 %75)
%77 = load i32, i32* %7
%78 = getelementptr inbounds [2097152 x i8], [2097152 x i8]* %8, i64 0, i64 0
%79 = load i32, i32* %10
%80 = call i32 @write(i32 %77, i8* %78, i32 %79)
store i32 %80, i32* %9
%81 = load i32, i32* %9
%82 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0), i32 %81)
br label %69
83: ; preds = %69
%84 = load i32, i32* %7
%85 = call i32 @close(i32 %84)
%86 = load i32, i32* %6
%87 = call i32 @close(i32 %86)
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
@O_TRUNC = 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 (i8*, 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 = load i32, i32* @O_TRUNC
%30 = or i32 %28, %29
%31 = tail call i32 (i8*, i32, ...) @open(i8* %25, i32 %30, i32 493)
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %39
33: ; preds = %23
%34 = load i32, i32* @stderr
%35 = load i8*, i8** %24
%36 = tail call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %35)
%37 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%38 = tail call i32 @exit(i32 -1)
unreachable
39: ; preds = %23
%40 = load i32, i32* @SEEK_SET
%41 = tail call i32 @lseek(i32 %15, i32 65536, i32 %40)
%42 = tail call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i32 %41)
%43 = icmp eq i32 %41, -1
br i1 %43, label %44, label %46
44: ; preds = %39
%45 = tail call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
br label %46
46: ; preds = %44, %39
%47 = call i32 @read(i32 %15, i8* %4, i32 2097152)
%48 = icmp sgt i32 %47, 0
br i1 %48, label %49, label %56
49: ; preds = %46, %49
%50 = phi i32 [ %54, %49 ], [ %47, %46 ]
%51 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i32 %50)
%52 = call i32 @write(i32 %31, i8* %4, i32 %50)
%53 = tail call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0), i32 %52)
%54 = call i32 @read(i32 %15, i8* %4, i32 2097152)
%55 = icmp sgt i32 %54, 0
br i1 %55, label %49, label %56
56: ; preds = %49, %46
%57 = tail call i32 @close(i32 %31)
%58 = tail call i32 @close(i32 %15)
ret i32 0
}