#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 /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ SEEK_END;
int atoi(char *);
int /*<<< orphan*/ lseek(int, int, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/, ...);
int read(int, char *, int);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char **argv) {
  if (argc < 4)
    return 1;
  int n = atoi(argv[1]);
  int fd1 = open(argv[2], O_WRONLY, 0644);
  int fd2 = open(argv[3], O_RDONLY);
  lseek(fd1, n, SEEK_END);
  int len;
  char buf[1000];
  while ((len = read(fd2, buf, 1000)))
    write(fd1, buf, len);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x8(%rbp)
jge    117f <main+0x2f>
movl   $0x1,-0x4(%rbp)
jmp    121c <main+0xcc>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    0x2e2a(%rip),%rax
mov    (%rax),%esi
mov    $0x1a4,%edx
mov    $0x0,%al
call   1060 <open@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
mov    0x2e22(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1060 <open@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    0x2e11(%rip),%rax
mov    (%rax),%edx
call   1040 <lseek@plt>
mov    -0x1c(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0x3e8,%edx
call   1050 <read@plt>
mov    %eax,-0x20(%rbp)
cmp    $0x0,%eax
je     1215 <main+0xc5>
mov    -0x18(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    -0x20(%rbp),%edx
call   1030 <write@plt>
jmp    11de <main+0x8e>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x3e8,%rsp
mov    $0x1,%r14d
cmp    $0x4,%edi
jl     1200 <main+0xb0>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
call   1070 <atoi@plt>
mov    %eax,%ebp
mov    0x10(%rbx),%rdi
mov    0x2e43(%rip),%rax
mov    (%rax),%esi
xor    %r14d,%r14d
mov    $0x1a4,%edx
xor    %eax,%eax
call   1060 <open@plt>
mov    %eax,%r15d
mov    0x18(%rbx),%rdi
mov    0x2e3c(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
call   1060 <open@plt>
mov    %eax,%ebx
mov    0x2e32(%rip),%rax
mov    (%rax),%edx
mov    %r15d,%edi
mov    %ebp,%esi
call   1040 <lseek@plt>
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0x3e8,%edx
call   1050 <read@plt>
test   %eax,%eax
je     1200 <main+0xb0>
mov    %rsp,%rbp
nopl   0x0(%rax,%rax,1)
mov    %r15d,%edi
mov    %rbp,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x3e8,%edx
call   1050 <read@plt>
test   %eax,%eax
jne    11e0 <main+0x90>
mov    %r14d,%eax
add    $0x3e8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@O_WRONLY = global i32 0
@O_RDONLY = global i32 0
@SEEK_END = global i32 0
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 i32
%10 = alloca [1000 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 4
br i1 %12, label %13, label %14
13: ; preds = %2
store i32 1, i32* %3
br label %44
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i32 @atoi(i8* %17)
store i32 %18, i32* %6
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 2
%21 = load i8*, i8** %20
%22 = load i32, i32* @O_WRONLY
%23 = call i32 (i8*, i32, ...) @open(i8* %21, i32 %22, i32 420)
store i32 %23, i32* %7
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 3
%26 = load i8*, i8** %25
%27 = load i32, i32* @O_RDONLY
%28 = call i32 (i8*, i32, ...) @open(i8* %26, i32 %27)
store i32 %28, i32* %8
%29 = load i32, i32* %7
%30 = load i32, i32* %6
%31 = load i32, i32* @SEEK_END
%32 = call i32 @lseek(i32 %29, i32 %30, i32 %31)
br label %33
33: ; preds = %38, %14
%34 = load i32, i32* %8
%35 = getelementptr inbounds [1000 x i8], [1000 x i8]* %10, i64 0, i64 0
%36 = call i32 @read(i32 %34, i8* %35, i32 1000)
store i32 %36, i32* %9
%37 = icmp ne i32 %36, 0
br i1 %37, label %38, label %43
38: ; preds = %33
%39 = load i32, i32* %7
%40 = getelementptr inbounds [1000 x i8], [1000 x i8]* %10, i64 0, i64 0
%41 = load i32, i32* %9
%42 = call i32 @write(i32 %39, i8* %40, i32 %41)
br label %33
43: ; preds = %33
store i32 0, i32* %3
br label %44
44: ; preds = %43, %13
%45 = load i32, i32* %3
ret i32 %45
}

LLVM IR (-O2):
@O_WRONLY = global i32 0
@O_RDONLY = global i32 0
@SEEK_END = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1000 x i8]
%4 = icmp slt i32 %0, 4
br i1 %4, label %28, label %5
5: ; preds = %2
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
%8 = tail call i32 @atoi(i8* %7)
%9 = getelementptr inbounds i8*, i8** %1, i64 2
%10 = load i8*, i8** %9
%11 = load i32, i32* @O_WRONLY
%12 = tail call i32 (i8*, i32, ...) @open(i8* %10, i32 %11, i32 420)
%13 = getelementptr inbounds i8*, i8** %1, i64 3
%14 = load i8*, i8** %13
%15 = load i32, i32* @O_RDONLY
%16 = tail call i32 (i8*, i32, ...) @open(i8* %14, i32 %15)
%17 = load i32, i32* @SEEK_END
%18 = tail call i32 @lseek(i32 %12, i32 %8, i32 %17)
%19 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%20 = call i32 @read(i32 %16, i8* %19, i32 1000)
%21 = icmp eq i32 %20, 0
br i1 %21, label %27, label %22
22: ; preds = %5, %22
%23 = phi i32 [ %25, %22 ], [ %20, %5 ]
%24 = call i32 @write(i32 %12, i8* %19, i32 %23)
%25 = call i32 @read(i32 %16, i8* %19, i32 1000)
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %22
27: ; preds = %22, %5
br label %28
28: ; preds = %2, %27
%29 = phi i32 [ 0, %27 ], [ 1, %2 ]
ret i32 %29
}