#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 ssize_t;
typedef int off_t;

/* Variables and functions */
int O_CREAT;
int /*<<< orphan*/ O_RDONLY;
int O_TRUNC;
int O_WRONLY;
int /*<<< orphan*/ SEEK_CUR;
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int S_IRUSR;
int S_IWUSR;
int close(int);
int /*<<< orphan*/ exit(int);
int lseek(int, int, int /*<<< orphan*/);
int open(char *, int, ...);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int write(int, char *, int);
int main(int argc, char **argv) {
  if (argc != 3) {
    printf("wrong number of arguments\n");
    exit(5);
  }
  int sourcefile = open(argv[1], O_RDONLY);
  if (sourcefile == -1) {
    perror("open source file failed");
    exit(1);
  }
  int destfile = open(argv[2], O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
  if (destfile == -1) {
    perror("open dest file failed");
    exit(2);
  }
  ssize_t rret = 0;
  char buf[1024];
  off_t pos = lseek(sourcefile, 100, SEEK_SET);
  if (pos == -1) {
    perror("lseek");
    exit(8);
  }
  printf("position in source file before copying begins: %lld\n",
         (long long)pos);
  while ((rret = read(sourcefile, buf, 1024))) {
    if (rret == -1) {
      perror("read error");
      exit(3);
    }
    pos = lseek(sourcefile, 0, SEEK_CUR);
    if (pos == -1) {
      perror("lseek");
      exit(9);
    }
    printf("current position in source file during loop: %lld\n",
           (long long)pos);
    ssize_t wret = 0;
    ssize_t wcount = 0;
    do {
      wret = write(destfile, &buf[wcount], rret - wcount);
      if (wret == -1) {
        perror("write error");
        exit(4);
      }
      wcount += wret;
    } while (wcount < rret);
  }
  pos = lseek(destfile, 0, SEEK_END);
  if (pos == -1) {
    perror("lseek");
    exit(10);
  }
  printf("current position in dest file (end of dest file): %lld\n",
         (long long)pos);
  int ret = write(destfile, "Some extra data\n", 16);
  if (ret == -1) {
    perror("error writing extra data to dest");
    exit(11);
  }
  pos = lseek(destfile, 0, SEEK_CUR);
  if (pos == -1) {
    perror("lseek");
    exit(9);
  }
  printf("current position in dest file after writing extra data: %lld\n",
         (long long)pos);
  int scret = close(sourcefile);
  if (scret == -1) {
    perror("closing source");
    exit(6);
  }
  int dcret = close(destfile);
  if (dcret == -1) {
    perror("closing copy");
    exit(7);
  }
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11bb <main+0x3b>
lea    0xe56(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x5,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2dfe(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1080 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11f6 <main+0x76>
lea    0xe34(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    0x2d93(%rip),%rax
mov    (%rax),%esi
mov    0x2dea(%rip),%rax
or     (%rax),%esi
mov    0x2dd9(%rip),%rax
or     (%rax),%esi
mov    0x2d88(%rip),%rax
mov    (%rax),%edx
mov    0x2d97(%rip),%rax
or     (%rax),%edx
mov    $0x0,%al
call   1080 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    1255 <main+0xd5>
lea    0xded(%rip),%rdi
call   1090 <perror@plt>
mov    $0x2,%edi
call   10a0 <exit@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2d4a(%rip),%rax
mov    (%rax),%edx
mov    $0x64,%esi
call   1050 <lseek@plt>
mov    %eax,-0x424(%rbp)
cmpl   $0xffffffff,-0x424(%rbp)
jne    129b <main+0x11b>
lea    0xdbd(%rip),%rdi
call   1090 <perror@plt>
mov    $0x8,%edi
call   10a0 <exit@plt>
movslq -0x424(%rbp),%rsi
lea    0xda6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
call   1070 <read@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
je     13c6 <main+0x246>
cmpl   $0xffffffff,-0x1c(%rbp)
jne    12f0 <main+0x170>
lea    0xda3(%rip),%rdi
call   1090 <perror@plt>
mov    $0x3,%edi
call   10a0 <exit@plt>
mov    -0x14(%rbp),%edi
mov    0x2cd6(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1050 <lseek@plt>
mov    %eax,-0x424(%rbp)
cmpl   $0xffffffff,-0x424(%rbp)
jne    132c <main+0x1ac>
lea    0xd2c(%rip),%rdi
call   1090 <perror@plt>
mov    $0x9,%edi
call   10a0 <exit@plt>
movslq -0x424(%rbp),%rsi
lea    0xd55(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x428(%rbp)
movl   $0x0,-0x42c(%rbp)
mov    -0x18(%rbp),%edi
movslq -0x42c(%rbp),%rax
lea    -0x420(%rbp),%rsi
add    %rax,%rsi
mov    -0x1c(%rbp),%edx
sub    -0x42c(%rbp),%edx
call   1030 <write@plt>
mov    %eax,-0x428(%rbp)
cmpl   $0xffffffff,-0x428(%rbp)
jne    13a0 <main+0x220>
lea    0xd31(%rip),%rdi
call   1090 <perror@plt>
mov    $0x4,%edi
call   10a0 <exit@plt>
mov    -0x428(%rbp),%eax
add    -0x42c(%rbp),%eax
mov    %eax,-0x42c(%rbp)
mov    -0x42c(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jl     1355 <main+0x1d5>
jmp    12b0 <main+0x130>
mov    -0x18(%rbp),%edi
mov    0x2c08(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1050 <lseek@plt>
mov    %eax,-0x424(%rbp)
cmpl   $0xffffffff,-0x424(%rbp)
jne    1402 <main+0x282>
lea    0xc56(%rip),%rdi
call   1090 <perror@plt>
mov    $0xa,%edi
call   10a0 <exit@plt>
movslq -0x424(%rbp),%rsi
lea    0xcbe(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%edi
lea    0xce5(%rip),%rsi
mov    $0x10,%edx
call   1030 <write@plt>
mov    %eax,-0x430(%rbp)
cmpl   $0xffffffff,-0x430(%rbp)
jne    1454 <main+0x2d4>
lea    0xcd2(%rip),%rdi
call   1090 <perror@plt>
mov    $0xb,%edi
call   10a0 <exit@plt>
mov    -0x18(%rbp),%edi
mov    0x2b72(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1050 <lseek@plt>
mov    %eax,-0x424(%rbp)
cmpl   $0xffffffff,-0x424(%rbp)
jne    1490 <main+0x310>
lea    0xbc8(%rip),%rdi
call   1090 <perror@plt>
mov    $0x9,%edi
call   10a0 <exit@plt>
movslq -0x424(%rbp),%rsi
lea    0xc9a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
mov    %eax,-0x434(%rbp)
cmpl   $0xffffffff,-0x434(%rbp)
jne    14d6 <main+0x356>
lea    0xcaf(%rip),%rdi
call   1090 <perror@plt>
mov    $0x6,%edi
call   10a0 <exit@plt>
mov    -0x18(%rbp),%edi
call   1060 <close@plt>
mov    %eax,-0x438(%rbp)
cmpl   $0xffffffff,-0x438(%rbp)
jne    1507 <main+0x387>
lea    0xc8d(%rip),%rdi
call   1090 <perror@plt>
mov    $0x7,%edi
call   10a0 <exit@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x408,%rsp
cmp    $0x3,%edi
jne    11d8 <main+0x48>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
mov    0x2e14(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
call   1090 <open@plt>
cmp    $0xffffffff,%eax
jne    11ee <main+0x5e>
lea    0xe37(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    0xf98(%rip),%rdi
call   1030 <puts@plt>
mov    $0x5,%edi
call   10b0 <exit@plt>
mov    %eax,%r12d
mov    0x10(%rbx),%rdi
mov    0x2d9c(%rip),%rax
mov    0x2df5(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2de2(%rip),%rax
or     (%rax),%esi
mov    0x2d91(%rip),%rax
mov    0x2da2(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
xor    %eax,%eax
call   1090 <open@plt>
cmp    $0xffffffff,%eax
jne    1244 <main+0xb4>
lea    0xde3(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x2,%edi
call   10b0 <exit@plt>
mov    %eax,%ebp
mov    0x2d63(%rip),%rax
mov    (%rax),%edx
mov    %r12d,%edi
mov    $0x64,%esi
call   1060 <lseek@plt>
cmp    $0xffffffff,%eax
jne    1277 <main+0xe7>
lea    0xdc6(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x8,%edi
call   10b0 <exit@plt>
movslq %eax,%rsi
lea    0xdb3(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rsp,%r14
lea    0xde2(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r12d,%edi
mov    %r14,%rsi
mov    $0x400,%edx
call   1080 <read@plt>
test   %eax,%eax
je     1327 <main+0x197>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
je     1354 <main+0x1c4>
mov    0x2d0a(%rip),%rax
mov    (%rax),%edx
mov    %r12d,%edi
xor    %esi,%esi
call   1060 <lseek@plt>
cmp    $0xffffffff,%eax
je     13c0 <main+0x230>
movslq %eax,%rsi
xor    %r13d,%r13d
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
nopl   0x0(%rax,%rax,1)
movslq %r13d,%rax
lea    (%rsp,%rax,1),%rsi
mov    %ebx,%edx
sub    %eax,%edx
mov    %ebp,%edi
call   1040 <write@plt>
cmp    $0xffffffff,%eax
je     1311 <main+0x181>
add    %eax,%r13d
cmp    %ebx,%r13d
jl     12f0 <main+0x160>
jmp    12a0 <main+0x110>
lea    0xd8f(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x4,%edi
call   10b0 <exit@plt>
mov    0x2caa(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%edi
xor    %esi,%esi
call   1060 <lseek@plt>
cmp    $0xffffffff,%eax
jne    136a <main+0x1da>
lea    0xce9(%rip),%rdi
call   10a0 <perror@plt>
mov    $0xa,%edi
call   10b0 <exit@plt>
lea    0xd0e(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x3,%edi
call   10b0 <exit@plt>
movslq %eax,%rsi
lea    0xd3f(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xd69(%rip),%rsi
mov    %ebp,%edi
mov    $0x10,%edx
call   1040 <write@plt>
cmp    $0xffffffff,%eax
jne    13a9 <main+0x219>
lea    0xd62(%rip),%rdi
call   10a0 <perror@plt>
mov    $0xb,%edi
call   10b0 <exit@plt>
mov    0x2c20(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%edi
xor    %esi,%esi
call   1060 <lseek@plt>
cmp    $0xffffffff,%eax
jne    13d6 <main+0x246>
lea    0xc67(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x9,%edi
call   10b0 <exit@plt>
movslq %eax,%rsi
lea    0xd3d(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r12d,%edi
call   1070 <close@plt>
cmp    $0xffffffff,%eax
jne    140a <main+0x27a>
lea    0xd60(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x6,%edi
call   10b0 <exit@plt>
mov    %ebp,%edi
call   1070 <close@plt>
cmp    $0xffffffff,%eax
jne    142c <main+0x29c>
lea    0xd4d(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x7,%edi
call   10b0 <exit@plt>
xor    %edi,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [27 x i8] c"wrong number of arguments\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [24 x i8] c"open source file failed\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@.str.2 = [22 x i8] c"open dest file failed\00"
@SEEK_SET = global i32 0
@.str.3 = [6 x i8] c"lseek\00"
@.str.4 = [53 x i8] c"position in source file before copying begins: %lld\0A\00"
@.str.5 = [11 x i8] c"read error\00"
@SEEK_CUR = global i32 0
@.str.6 = [51 x i8] c"current position in source file during loop: %lld\0A\00"
@.str.7 = [12 x i8] c"write error\00"
@SEEK_END = global i32 0
@.str.8 = [56 x i8] c"current position in dest file (end of dest file): %lld\0A\00"
@.str.9 = [17 x i8] c"Some extra data\0A\00"
@.str.10 = [33 x i8] c"error writing extra data to dest\00"
@.str.11 = [62 x i8] c"current position in dest file after writing extra data: %lld\0A\00"
@.str.12 = [15 x i8] c"closing source\00"
@.str.13 = [13 x i8] c"closing copy\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 i32
%9 = alloca [1024 x i8]
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%16 = load i32, i32* %4
%17 = icmp ne i32 %16, 3
br i1 %17, label %18, label %21
18: ; preds = %2
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%20 = call i32 @exit(i32 5)
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 %32
29: ; preds = %21
%30 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
%31 = call i32 @exit(i32 1)
unreachable
32: ; preds = %21
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 2
%35 = load i8*, i8** %34
%36 = load i32, i32* @O_WRONLY
%37 = load i32, i32* @O_CREAT
%38 = or i32 %36, %37
%39 = load i32, i32* @O_TRUNC
%40 = or i32 %38, %39
%41 = load i32, i32* @S_IRUSR
%42 = load i32, i32* @S_IWUSR
%43 = or i32 %41, %42
%44 = call i32 (i8*, i32, ...) @open(i8* %35, i32 %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 %50
47: ; preds = %32
%48 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
%49 = call i32 @exit(i32 2)
unreachable
50: ; preds = %32
store i32 0, i32* %8
%51 = load i32, i32* %6
%52 = load i32, i32* @SEEK_SET
%53 = call i32 @lseek(i32 %51, i32 100, i32 %52)
store i32 %53, i32* %10
%54 = load i32, i32* %10
%55 = icmp eq i32 %54, -1
br i1 %55, label %56, label %59
56: ; preds = %50
%57 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%58 = call i32 @exit(i32 8)
unreachable
59: ; preds = %50
%60 = load i32, i32* %10
%61 = sext i32 %60 to i64
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.4, i64 0, i64 0), i64 %61)
br label %63
63: ; preds = %109, %59
%64 = load i32, i32* %6
%65 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%66 = call i32 @read(i32 %64, i8* %65, i32 1024)
store i32 %66, i32* %8
%67 = icmp ne i32 %66, 0
br i1 %67, label %68, label %110
68: ; preds = %63
%69 = load i32, i32* %8
%70 = icmp eq i32 %69, -1
br i1 %70, label %71, label %74
71: ; preds = %68
%72 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
%73 = call i32 @exit(i32 3)
unreachable
74: ; preds = %68
%75 = load i32, i32* %6
%76 = load i32, i32* @SEEK_CUR
%77 = call i32 @lseek(i32 %75, i32 0, i32 %76)
store i32 %77, i32* %10
%78 = load i32, i32* %10
%79 = icmp eq i32 %78, -1
br i1 %79, label %80, label %83
80: ; preds = %74
%81 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%82 = call i32 @exit(i32 9)
unreachable
83: ; preds = %74
%84 = load i32, i32* %10
%85 = sext i32 %84 to i64
%86 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.6, i64 0, i64 0), i64 %85)
store i32 0, i32* %11
store i32 0, i32* %12
br label %87
87: ; preds = %105, %83
%88 = load i32, i32* %7
%89 = load i32, i32* %12
%90 = sext i32 %89 to i64
%91 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 %90
%92 = load i32, i32* %8
%93 = load i32, i32* %12
%94 = sub nsw i32 %92, %93
%95 = call i32 @write(i32 %88, i8* %91, i32 %94)
store i32 %95, i32* %11
%96 = load i32, i32* %11
%97 = icmp eq i32 %96, -1
br i1 %97, label %98, label %101
98: ; preds = %87
%99 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0))
%100 = call i32 @exit(i32 4)
unreachable
101: ; preds = %87
%102 = load i32, i32* %11
%103 = load i32, i32* %12
%104 = add nsw i32 %103, %102
store i32 %104, i32* %12
br label %105
105: ; preds = %101
%106 = load i32, i32* %12
%107 = load i32, i32* %8
%108 = icmp slt i32 %106, %107
br i1 %108, label %87, label %109
109: ; preds = %105
br label %63
110: ; preds = %63
%111 = load i32, i32* %7
%112 = load i32, i32* @SEEK_END
%113 = call i32 @lseek(i32 %111, i32 0, i32 %112)
store i32 %113, i32* %10
%114 = load i32, i32* %10
%115 = icmp eq i32 %114, -1
br i1 %115, label %116, label %119
116: ; preds = %110
%117 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%118 = call i32 @exit(i32 10)
unreachable
119: ; preds = %110
%120 = load i32, i32* %10
%121 = sext i32 %120 to i64
%122 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.8, i64 0, i64 0), i64 %121)
%123 = load i32, i32* %7
%124 = call i32 @write(i32 %123, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.9, i64 0, i64 0), i32 16)
store i32 %124, i32* %13
%125 = load i32, i32* %13
%126 = icmp eq i32 %125, -1
br i1 %126, label %127, label %130
127: ; preds = %119
%128 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.10, i64 0, i64 0))
%129 = call i32 @exit(i32 11)
unreachable
130: ; preds = %119
%131 = load i32, i32* %7
%132 = load i32, i32* @SEEK_CUR
%133 = call i32 @lseek(i32 %131, i32 0, i32 %132)
store i32 %133, i32* %10
%134 = load i32, i32* %10
%135 = icmp eq i32 %134, -1
br i1 %135, label %136, label %139
136: ; preds = %130
%137 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%138 = call i32 @exit(i32 9)
unreachable
139: ; preds = %130
%140 = load i32, i32* %10
%141 = sext i32 %140 to i64
%142 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.11, i64 0, i64 0), i64 %141)
%143 = load i32, i32* %6
%144 = call i32 @close(i32 %143)
store i32 %144, i32* %14
%145 = load i32, i32* %14
%146 = icmp eq i32 %145, -1
br i1 %146, label %147, label %150
147: ; preds = %139
%148 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.12, i64 0, i64 0))
%149 = call i32 @exit(i32 6)
unreachable
150: ; preds = %139
%151 = load i32, i32* %7
%152 = call i32 @close(i32 %151)
store i32 %152, i32* %15
%153 = load i32, i32* %15
%154 = icmp eq i32 %153, -1
br i1 %154, label %155, label %158
155: ; preds = %150
%156 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.13, i64 0, i64 0))
%157 = call i32 @exit(i32 7)
unreachable
158: ; preds = %150
%159 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@.str.1 = [24 x i8] c"open source file failed\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@.str.2 = [22 x i8] c"open dest file failed\00"
@SEEK_SET = global i32 0
@.str.3 = [6 x i8] c"lseek\00"
@.str.4 = [53 x i8] c"position in source file before copying begins: %lld\0A\00"
@.str.5 = [11 x i8] c"read error\00"
@SEEK_CUR = global i32 0
@.str.6 = [51 x i8] c"current position in source file during loop: %lld\0A\00"
@.str.7 = [12 x i8] c"write error\00"
@SEEK_END = global i32 0
@.str.8 = [56 x i8] c"current position in dest file (end of dest file): %lld\0A\00"
@.str.9 = [17 x i8] c"Some extra data\0A\00"
@.str.10 = [33 x i8] c"error writing extra data to dest\00"
@.str.11 = [62 x i8] c"current position in dest file after writing extra data: %lld\0A\00"
@.str.12 = [15 x i8] c"closing source\00"
@.str.13 = [13 x i8] c"closing copy\00"
@str = [26 x i8] c"wrong number of arguments\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = icmp eq i32 %0, 3
br i1 %4, label %8, label %5
5: ; preds = %2
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
%7 = tail call i32 @exit(i32 5)
unreachable
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = load i32, i32* @O_RDONLY
%12 = tail call i32 (i8*, i32, ...) @open(i8* %10, i32 %11)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %17
14: ; preds = %8
%15 = tail call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
%16 = tail call i32 @exit(i32 1)
unreachable
17: ; preds = %8
%18 = getelementptr inbounds i8*, i8** %1, i64 2
%19 = load i8*, i8** %18
%20 = load i32, i32* @O_WRONLY
%21 = load i32, i32* @O_CREAT
%22 = or i32 %21, %20
%23 = load i32, i32* @O_TRUNC
%24 = or i32 %22, %23
%25 = load i32, i32* @S_IRUSR
%26 = load i32, i32* @S_IWUSR
%27 = or i32 %26, %25
%28 = tail call i32 (i8*, i32, ...) @open(i8* %19, i32 %24, i32 %27)
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %33
30: ; preds = %17
%31 = tail call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
%32 = tail call i32 @exit(i32 2)
unreachable
33: ; preds = %17
%34 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%35 = load i32, i32* @SEEK_SET
%36 = tail call i32 @lseek(i32 %12, i32 100, i32 %35)
%37 = icmp eq i32 %36, -1
br i1 %37, label %38, label %41
38: ; preds = %33
%39 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%40 = tail call i32 @exit(i32 8)
unreachable
41: ; preds = %33
%42 = sext i32 %36 to i64
%43 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @.str.4, i64 0, i64 0), i64 %42)
br label %44
44: ; preds = %69, %41
%45 = call i32 @read(i32 %12, i8* %34, i32 1024)
switch i32 %45, label %49 [
i32 0, label %72
i32 -1, label %46
]
46: ; preds = %44
%47 = tail call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
%48 = tail call i32 @exit(i32 3)
unreachable
49: ; preds = %44
%50 = load i32, i32* @SEEK_CUR
%51 = tail call i32 @lseek(i32 %12, i32 0, i32 %50)
%52 = icmp eq i32 %51, -1
br i1 %52, label %53, label %56
53: ; preds = %49
%54 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%55 = tail call i32 @exit(i32 9)
unreachable
56: ; preds = %49
%57 = sext i32 %51 to i64
%58 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @.str.6, i64 0, i64 0), i64 %57)
br label %59
59: ; preds = %69, %56
%60 = phi i32 [ 0, %56 ], [ %70, %69 ]
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %61
%63 = sub nsw i32 %45, %60
%64 = call i32 @write(i32 %28, i8* %62, i32 %63)
%65 = icmp eq i32 %64, -1
br i1 %65, label %66, label %69
66: ; preds = %59
%67 = tail call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0))
%68 = tail call i32 @exit(i32 4)
unreachable
69: ; preds = %59
%70 = add nsw i32 %64, %60
%71 = icmp slt i32 %70, %45
br i1 %71, label %59, label %44
72: ; preds = %44
%73 = load i32, i32* @SEEK_END
%74 = tail call i32 @lseek(i32 %28, i32 0, i32 %73)
%75 = icmp eq i32 %74, -1
br i1 %75, label %76, label %79
76: ; preds = %72
%77 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%78 = tail call i32 @exit(i32 10)
unreachable
79: ; preds = %72
%80 = sext i32 %74 to i64
%81 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @.str.8, i64 0, i64 0), i64 %80)
%82 = tail call i32 @write(i32 %28, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.9, i64 0, i64 0), i32 16)
%83 = icmp eq i32 %82, -1
br i1 %83, label %84, label %87
84: ; preds = %79
%85 = tail call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.10, i64 0, i64 0))
%86 = tail call i32 @exit(i32 11)
unreachable
87: ; preds = %79
%88 = load i32, i32* @SEEK_CUR
%89 = tail call i32 @lseek(i32 %28, i32 0, i32 %88)
%90 = icmp eq i32 %89, -1
br i1 %90, label %91, label %94
91: ; preds = %87
%92 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%93 = tail call i32 @exit(i32 9)
unreachable
94: ; preds = %87
%95 = sext i32 %89 to i64
%96 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([62 x i8], [62 x i8]* @.str.11, i64 0, i64 0), i64 %95)
%97 = tail call i32 @close(i32 %12)
%98 = icmp eq i32 %97, -1
br i1 %98, label %99, label %102
99: ; preds = %94
%100 = tail call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.12, i64 0, i64 0))
%101 = tail call i32 @exit(i32 6)
unreachable
102: ; preds = %94
%103 = tail call i32 @close(i32 %28)
%104 = icmp eq i32 %103, -1
br i1 %104, label %105, label %108
105: ; preds = %102
%106 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.13, i64 0, i64 0))
%107 = tail call i32 @exit(i32 7)
unreachable
108: ; preds = %102
%109 = tail call i32 @exit(i32 0)
unreachable
}