#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*/ SEEK_END;
int /*<<< orphan*/ execlp(char *, char *, char *, char *, int /*<<< orphan*/);
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[]) {
  int f;
  if (argc > 1)
    f = open(argv[1], O_RDONLY);
  else
    f = open("aa", O_RDONLY);
  int i, readCount;
  char buffer[5];
  for (i = 5; i >= 1; --i) {
    execlp("wc", "wc", "-l", "aa", 0);
    lseek(f, -3, SEEK_END);
    readCount = read(f, buffer, i);
    write(1, buffer, readCount);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    118e <main+0x3e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e61(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
jmp    11a6 <main+0x56>
mov    0x2e4b(%rip),%rax
mov    (%rax),%esi
lea    0xe62(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
movl   $0x5,-0x18(%rbp)
cmpl   $0x1,-0x18(%rbp)
jl     121e <main+0xce>
lea    0xe45(%rip),%rsi
lea    0xe41(%rip),%rdx
lea    0xe34(%rip),%rcx
xor    %r8d,%r8d
mov    %rsi,%rdi
call   1070 <execlp@plt>
mov    -0x14(%rbp),%edi
mov    0x2e07(%rip),%rax
mov    (%rax),%edx
mov    $0xfffffffd,%esi
call   1040 <lseek@plt>
mov    -0x14(%rbp),%edi
lea    -0x21(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1050 <read@plt>
mov    %eax,-0x1c(%rbp)
lea    -0x21(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    $0x1,%edi
call   1030 <write@plt>
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
jmp    11ad <main+0x5d>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x2,%edi
jl     1166 <main+0x16>
mov    0x8(%rsi),%rdi
jmp    116d <main+0x1d>
lea    0xe93(%rip),%rdi
mov    0x2e6c(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,%ebx
lea    0xe7f(%rip),%r15
lea    0xe7b(%rip),%r12
lea    0xe6e(%rip),%r13
mov    %r15,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
mov    %r13,%rcx
xor    %r8d,%r8d
call   1070 <execlp@plt>
mov    0x2e3b(%rip),%rbp
mov    0x0(%rbp),%edx
mov    %ebx,%edi
mov    $0xfffffffd,%esi
call   1040 <lseek@plt>
lea    0x3(%rsp),%r14
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x5,%edx
call   1050 <read@plt>
mov    $0x1,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %r15,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
mov    %r13,%rcx
xor    %r8d,%r8d
call   1070 <execlp@plt>
mov    0x0(%rbp),%edx
mov    %ebx,%edi
mov    $0xfffffffd,%esi
call   1040 <lseek@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x4,%edx
call   1050 <read@plt>
mov    $0x1,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %r15,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
mov    %r13,%rcx
xor    %r8d,%r8d
call   1070 <execlp@plt>
mov    0x0(%rbp),%edx
mov    %ebx,%edi
mov    $0xfffffffd,%esi
call   1040 <lseek@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x3,%edx
call   1050 <read@plt>
mov    $0x1,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %r15,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
mov    %r13,%rcx
xor    %r8d,%r8d
call   1070 <execlp@plt>
mov    0x0(%rbp),%edx
mov    %ebx,%edi
mov    $0xfffffffd,%esi
call   1040 <lseek@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x2,%edx
call   1050 <read@plt>
mov    $0x1,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %r15,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
mov    %r13,%rcx
xor    %r8d,%r8d
call   1070 <execlp@plt>
mov    0x0(%rbp),%edx
mov    %ebx,%edi
mov    $0xfffffffd,%esi
call   1040 <lseek@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1050 <read@plt>
mov    $0x1,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <write@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@O_RDONLY = global i32 0
@.str = [3 x i8] c"aa\00"
@.str.1 = [3 x i8] c"wc\00"
@.str.2 = [3 x i8] c"-l\00"
@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 [5 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp sgt i32 %10, 1
br i1 %11, label %12, label %18
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = load i32, i32* @O_RDONLY
%17 = call i32 @open(i8* %15, i32 %16)
store i32 %17, i32* %6
br label %21
18: ; preds = %2
%19 = load i32, i32* @O_RDONLY
%20 = call i32 @open(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %19)
store i32 %20, i32* %6
br label %21
21: ; preds = %18, %12
store i32 5, i32* %7
br label %22
22: ; preds = %37, %21
%23 = load i32, i32* %7
%24 = icmp sge i32 %23, 1
br i1 %24, label %25, label %40
25: ; preds = %22
%26 = call i32 @execlp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 0)
%27 = load i32, i32* %6
%28 = load i32, i32* @SEEK_END
%29 = call i32 @lseek(i32 %27, i32 -3, i32 %28)
%30 = load i32, i32* %6
%31 = getelementptr inbounds [5 x i8], [5 x i8]* %9, i64 0, i64 0
%32 = load i32, i32* %7
%33 = call i32 @read(i32 %30, i8* %31, i32 %32)
store i32 %33, i32* %8
%34 = getelementptr inbounds [5 x i8], [5 x i8]* %9, i64 0, i64 0
%35 = load i32, i32* %8
%36 = call i32 @write(i32 1, i8* %34, i32 %35)
br label %37
37: ; preds = %25
%38 = load i32, i32* %7
%39 = add nsw i32 %38, -1
store i32 %39, i32* %7
br label %22
40: ; preds = %22
ret i32 0
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@.str = [3 x i8] c"aa\00"
@.str.1 = [3 x i8] c"wc\00"
@.str.2 = [3 x i8] c"-l\00"
@SEEK_END = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [5 x i8]
%4 = icmp sgt i32 %0, 1
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
br label %8
8: ; preds = %2, %5
%9 = phi i8* [ %7, %5 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), %2 ]
%10 = load i32, i32* @O_RDONLY
%11 = tail call i32 @open(i8* %9, i32 %10)
%12 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 0
%13 = tail call i32 @execlp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 0)
%14 = load i32, i32* @SEEK_END
%15 = tail call i32 @lseek(i32 %11, i32 -3, i32 %14)
%16 = call i32 @read(i32 %11, i8* %12, i32 5)
%17 = call i32 @write(i32 1, i8* %12, i32 %16)
%18 = tail call i32 @execlp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 0)
%19 = load i32, i32* @SEEK_END
%20 = tail call i32 @lseek(i32 %11, i32 -3, i32 %19)
%21 = call i32 @read(i32 %11, i8* %12, i32 4)
%22 = call i32 @write(i32 1, i8* %12, i32 %21)
%23 = tail call i32 @execlp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 0)
%24 = load i32, i32* @SEEK_END
%25 = tail call i32 @lseek(i32 %11, i32 -3, i32 %24)
%26 = call i32 @read(i32 %11, i8* %12, i32 3)
%27 = call i32 @write(i32 1, i8* %12, i32 %26)
%28 = tail call i32 @execlp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 0)
%29 = load i32, i32* @SEEK_END
%30 = tail call i32 @lseek(i32 %11, i32 -3, i32 %29)
%31 = call i32 @read(i32 %11, i8* %12, i32 2)
%32 = call i32 @write(i32 1, i8* %12, i32 %31)
%33 = tail call i32 @execlp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 0)
%34 = load i32, i32* @SEEK_END
%35 = tail call i32 @lseek(i32 %11, i32 -3, i32 %34)
%36 = call i32 @read(i32 %11, i8* %12, i32 1)
%37 = call i32 @write(i32 1, i8* %12, i32 %36)
ret i32 0
}