#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 /*<<< orphan*/ ssize_t;

/* Variables and functions */
int /*<<< orphan*/ catwc(char *);
int /*<<< orphan*/ close(int);
int creat(char *, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fork();
int /*<<< orphan*/ read(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ wait(int *);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
int main(int argc, char **argv) {
  if (argc == 1) {
    char buf[1000];
    int fd = creat("/tmp/catwc", 0x644);
    ssize_t len;
    while ((len = read(0, buf, 1000)))
      write(fd, buf, len);
    close(fd);
    catwc("/tmp/catwc");
    exit(0);
  }
  for (int i = 1; i < argc; i++)
    if (!fork())
      catwc(argv[i]);
  for (int i = 1; i < argc; i++) {
    int status;
    wait(&status);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    1217 <main+0x97>
lea    0xe56(%rip),%rdi
mov    $0x644,%esi
call   1070 <creat@plt>
mov    %eax,-0x404(%rbp)
lea    -0x400(%rbp),%rsi
xor    %edi,%edi
mov    $0x3e8,%edx
call   1060 <read@plt>
mov    %eax,-0x408(%rbp)
cmp    $0x0,%eax
je     11f9 <main+0x79>
mov    -0x404(%rbp),%edi
lea    -0x400(%rbp),%rsi
mov    -0x408(%rbp),%edx
call   1030 <write@plt>
jmp    11ba <main+0x3a>
mov    -0x404(%rbp),%edi
call   1050 <close@plt>
lea    0xdf5(%rip),%rdi
call   1040 <catwc@plt>
xor    %edi,%edi
call   1080 <exit@plt>
movl   $0x1,-0x40c(%rbp)
mov    -0x40c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    126d <main+0xed>
mov    $0x0,%al
call   10a0 <fork@plt>
cmp    $0x0,%eax
jne    1254 <main+0xd4>
mov    -0x10(%rbp),%rax
movslq -0x40c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1040 <catwc@plt>
jmp    1259 <main+0xd9>
mov    -0x40c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40c(%rbp)
jmp    1221 <main+0xa1>
movl   $0x1,-0x410(%rbp)
mov    -0x410(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    12a6 <main+0x126>
lea    -0x414(%rbp),%rdi
call   1090 <wait@plt>
mov    -0x410(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x410(%rbp)
jmp    1277 <main+0xf7>
xor    %eax,%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x3e8,%rsp
cmp    $0x1,%edi
je     11fd <main+0x7d>
jle    11ed <main+0x6d>
mov    %rsi,%r14
mov    %edi,%ebx
mov    %edi,%r15d
mov    $0x1,%ebp
jmp    11b9 <main+0x39>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%rbp
cmp    %rbp,%r15
je     11cf <main+0x4f>
xor    %eax,%eax
call   10a0 <fork@plt>
test   %eax,%eax
jne    11b0 <main+0x30>
mov    (%r14,%rbp,8),%rdi
call   1040 <catwc@plt>
jmp    11b0 <main+0x30>
cmp    $0x2,%ebx
jl     11ed <main+0x6d>
add    $0xffffffff,%ebx
mov    %rsp,%rbp
nopw   0x0(%rax,%rax,1)
mov    %rbp,%rdi
call   1090 <wait@plt>
add    $0xffffffff,%ebx
jne    11e0 <main+0x60>
xor    %eax,%eax
add    $0x3e8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdfc(%rip),%rdi
mov    $0x644,%esi
call   1070 <creat@plt>
mov    %eax,%ebp
mov    %rsp,%rsi
xor    %edi,%edi
mov    $0x3e8,%edx
call   1060 <read@plt>
test   %eax,%eax
je     124f <main+0xcf>
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
xor    %edi,%edi
mov    %rbx,%rsi
mov    $0x3e8,%edx
call   1060 <read@plt>
test   %eax,%eax
jne    1230 <main+0xb0>
mov    %ebp,%edi
call   1050 <close@plt>
lea    0xda3(%rip),%rdi
call   1040 <catwc@plt>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [11 x i8] c"/tmp/catwc\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [1000 x i8]
%7 = alloca i32
%8 = alloca i32
%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 eq i32 %12, 1
br i1 %13, label %14, label %30
14: ; preds = %2
%15 = call i32 @creat(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 1604)
store i32 %15, i32* %7
br label %16
16: ; preds = %20, %14
%17 = getelementptr inbounds [1000 x i8], [1000 x i8]* %6, i64 0, i64 0
%18 = call i32 @read(i32 0, i8* %17, i32 1000)
store i32 %18, i32* %8
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %25
20: ; preds = %16
%21 = load i32, i32* %7
%22 = getelementptr inbounds [1000 x i8], [1000 x i8]* %6, i64 0, i64 0
%23 = load i32, i32* %8
%24 = call i32 @write(i32 %21, i8* %22, i32 %23)
br label %16
25: ; preds = %16
%26 = load i32, i32* %7
%27 = call i32 @close(i32 %26)
%28 = call i32 @catwc(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%29 = call i32 @exit(i32 0)
unreachable
30: ; preds = %2
store i32 1, i32* %9
br label %31
31: ; preds = %46, %30
%32 = load i32, i32* %9
%33 = load i32, i32* %4
%34 = icmp slt i32 %32, %33
br i1 %34, label %35, label %49
35: ; preds = %31
%36 = call i32 (...) @fork()
%37 = icmp ne i32 %36, 0
br i1 %37, label %45, label %38
38: ; preds = %35
%39 = load i8**, i8*** %5
%40 = load i32, i32* %9
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8*, i8** %39, i64 %41
%43 = load i8*, i8** %42
%44 = call i32 @catwc(i8* %43)
br label %45
45: ; preds = %38, %35
br label %46
46: ; preds = %45
%47 = load i32, i32* %9
%48 = add nsw i32 %47, 1
store i32 %48, i32* %9
br label %31
49: ; preds = %31
store i32 1, i32* %10
br label %50
50: ; preds = %56, %49
%51 = load i32, i32* %10
%52 = load i32, i32* %4
%53 = icmp slt i32 %51, %52
br i1 %53, label %54, label %59
54: ; preds = %50
%55 = call i32 @wait(i32* %11)
br label %56
56: ; preds = %54
%57 = load i32, i32* %10
%58 = add nsw i32 %57, 1
store i32 %58, i32* %10
br label %50
59: ; preds = %50
ret i32 0
}

LLVM IR (-O2):
@.str = [11 x i8] c"/tmp/catwc\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1000 x i8]
%4 = alloca i32
%5 = icmp eq i32 %0, 1
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = icmp sgt i32 %0, 1
br i1 %7, label %8, label %38
8: ; preds = %6
%9 = zext i32 %0 to i64
br label %27
10: ; preds = %2
%11 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%12 = tail call i32 @creat(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 1604)
%13 = call i32 @read(i32 0, i8* %11, i32 1000)
%14 = icmp eq i32 %13, 0
br i1 %14, label %20, label %15
15: ; preds = %10, %15
%16 = phi i32 [ %18, %15 ], [ %13, %10 ]
%17 = call i32 @write(i32 %12, i8* %11, i32 %16)
%18 = call i32 @read(i32 0, i8* %11, i32 1000)
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %15
20: ; preds = %15, %10
%21 = tail call i32 @close(i32 %12)
%22 = tail call i32 @catwc(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%23 = tail call i32 @exit(i32 0)
unreachable
24: ; preds = %35
br i1 %7, label %25, label %38
25: ; preds = %24
%26 = bitcast i32* %4 to i8*
br label %39
27: ; preds = %8, %35
%28 = phi i64 [ 1, %8 ], [ %36, %35 ]
%29 = tail call i32 (...) @fork()
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %35
31: ; preds = %27
%32 = getelementptr inbounds i8*, i8** %1, i64 %28
%33 = load i8*, i8** %32
%34 = tail call i32 @catwc(i8* %33)
br label %35
35: ; preds = %27, %31
%36 = add nuw nsw i64 %28, 1
%37 = icmp eq i64 %36, %9
br i1 %37, label %24, label %27
38: ; preds = %39, %6, %24
ret i32 0
39: ; preds = %25, %39
%40 = phi i32 [ 1, %25 ], [ %42, %39 ]
%41 = call i32 @wait(i32* %4)
%42 = add nuw nsw i32 %40, 1
%43 = icmp eq i32 %42, %0
br i1 %43, label %38, label %39
}