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

/* Variables and functions */
int /*<<< orphan*/ *_open_readfile(char *, int *, int);
int /*<<< orphan*/ cat_file(int /*<<< orphan*/ *);
int errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *stdin;
scalar_t__ waitpid(int, int /*<<< orphan*/ *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int err = 0;
  for (int ix = 1; ix <= argc; ix++) {
    if (ix == argc) {
      if (argc == 1) {
        cat_file(stdin);
      }
    } else {
      bool flag;
      FILE *fp = _open_readfile((argv[ix]), (&flag), false);
      if (fp == NULL) {
        err = errno;
        break;
      }
      cat_file(fp);
      fclose(fp);
      if (flag) {
        while (waitpid(-1, NULL, 0) > 0)
          ;
      }
    }
  }
  return err;
}


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)
movl   $0x0,-0x14(%rbp)
movl   $0x1,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     122e <main+0xee>
mov    -0x18(%rbp),%eax
cmp    -0x8(%rbp),%eax
jne    119a <main+0x5a>
cmpl   $0x1,-0x8(%rbp)
jne    1195 <main+0x55>
mov    0x2e5b(%rip),%rax
mov    (%rax),%rdi
call   1060 <cat_file@plt>
jmp    121b <main+0xdb>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    -0x1c(%rbp),%rsi
xor    %edx,%edx
call   1050 <_open_readfile@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11d1 <main+0x91>
mov    0x2e11(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
jmp    122e <main+0xee>
mov    -0x28(%rbp),%rdi
call   1060 <cat_file@plt>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
cmpl   $0x0,-0x1c(%rbp)
je     1216 <main+0xd6>
jmp    11f2 <main+0xb2>
mov    $0xffffffff,%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1040 <waitpid@plt>
cmp    $0x0,%rax
jle    1211 <main+0xd1>
jmp    11f2 <main+0xb2>
jmp    1216 <main+0xd6>
jmp    121b <main+0xdb>
jmp    1220 <main+0xe0>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1164 <main+0x24>
mov    -0x14(%rbp),%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
test   %edi,%edi
jle    11e5 <main+0xa5>
mov    %rsi,%r14
mov    %edi,%r12d
mov    %edi,%r13d
lea    0x1(%r12),%ebp
mov    $0x1,%r15d
jmp    1179 <main+0x39>
nopl   0x0(%rax)
add    $0x1,%r15
cmp    %rbp,%r15
je     11e5 <main+0xa5>
cmp    %r13,%r15
jne    11a0 <main+0x60>
cmp    $0x1,%r12d
jne    1170 <main+0x30>
mov    0x2e5d(%rip),%rax
mov    (%rax),%rdi
call   1060 <cat_file@plt>
jmp    1170 <main+0x30>
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%r14,%r15,8),%rdi
lea    0x4(%rsp),%rsi
xor    %edx,%edx
call   1050 <_open_readfile@plt>
test   %rax,%rax
je     11e9 <main+0xa9>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <cat_file@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
cmpl   $0x0,0x4(%rsp)
je     1170 <main+0x30>
nop
mov    $0xffffffff,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1040 <waitpid@plt>
test   %rax,%rax
jg     11d0 <main+0x90>
jmp    1170 <main+0x30>
xor    %eax,%eax
jmp    11f2 <main+0xb2>
mov    0x2de8(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdin = global i32* null
@errno = 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*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i32 1, i32* %7
br label %10
10: ; preds = %51, %2
%11 = load i32, i32* %7
%12 = load i32, i32* %4
%13 = icmp sle i32 %11, %12
br i1 %13, label %14, label %54
14: ; preds = %10
%15 = load i32, i32* %7
%16 = load i32, i32* %4
%17 = icmp eq i32 %15, %16
br i1 %17, label %18, label %25
18: ; preds = %14
%19 = load i32, i32* %4
%20 = icmp eq i32 %19, 1
br i1 %20, label %21, label %24
21: ; preds = %18
%22 = load i32*, i32** @stdin
%23 = call i32 @cat_file(i32* %22)
br label %24
24: ; preds = %21, %18
br label %50
25: ; preds = %14
%26 = load i8**, i8*** %5
%27 = load i32, i32* %7
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8*, i8** %26, i64 %28
%30 = load i8*, i8** %29
%31 = call i32* @_open_readfile(i8* %30, i32* %8, i32 0)
store i32* %31, i32** %9
%32 = load i32*, i32** %9
%33 = icmp eq i32* %32, null
br i1 %33, label %34, label %36
34: ; preds = %25
%35 = load i32, i32* @errno
store i32 %35, i32* %6
br label %54
36: ; preds = %25
%37 = load i32*, i32** %9
%38 = call i32 @cat_file(i32* %37)
%39 = load i32*, i32** %9
%40 = call i32 @fclose(i32* %39)
%41 = load i32, i32* %8
%42 = icmp ne i32 %41, 0
br i1 %42, label %43, label %49
43: ; preds = %36
br label %44
44: ; preds = %47, %43
%45 = call i64 @waitpid(i32 -1, i32* null, i32 0)
%46 = icmp sgt i64 %45, 0
br i1 %46, label %47, label %48
47: ; preds = %44
br label %44
48: ; preds = %44
br label %49
49: ; preds = %48, %36
br label %50
50: ; preds = %49, %24
br label %51
51: ; preds = %50
%52 = load i32, i32* %7
%53 = add nsw i32 %52, 1
store i32 %53, i32* %7
br label %10
54: ; preds = %34, %10
%55 = load i32, i32* %6
ret i32 %55
}

LLVM IR (-O2):
@stdin = global i32* null
@errno = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = icmp slt i32 %0, 1
br i1 %4, label %38, label %5
5: ; preds = %2
%6 = bitcast i32* %3 to i8*
%7 = icmp eq i32 %0, 1
%8 = zext i32 %0 to i64
%9 = add nuw i32 %0, 1
%10 = zext i32 %9 to i64
br label %11
11: ; preds = %5, %35
%12 = phi i64 [ 1, %5 ], [ %36, %35 ]
%13 = icmp eq i64 %12, %8
br i1 %13, label %14, label %18
14: ; preds = %11
br i1 %7, label %15, label %35
15: ; preds = %14
%16 = load i32*, i32** @stdin
%17 = call i32 @cat_file(i32* %16)
br label %35
18: ; preds = %11
%19 = getelementptr inbounds i8*, i8** %1, i64 %12
%20 = load i8*, i8** %19
%21 = call i32* @_open_readfile(i8* %20, i32* %3, i32 0)
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %25
23: ; preds = %18
%24 = load i32, i32* @errno
br label %38
25: ; preds = %18
%26 = call i32 @cat_file(i32* %21)
%27 = call i32 @fclose(i32* %21)
%28 = load i32, i32* %3
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %25
br label %35
31: ; preds = %25, %31
%32 = call i64 @waitpid(i32 -1, i32* null, i32 0)
%33 = icmp sgt i64 %32, 0
br i1 %33, label %31, label %34
34: ; preds = %31
br label %35
35: ; preds = %34, %30, %15, %14
%36 = add nuw nsw i64 %12, 1
%37 = icmp eq i64 %36, %10
br i1 %37, label %38, label %11
38: ; preds = %35, %2, %23
%39 = phi i32 [ %24, %23 ], [ 0, %2 ], [ 0, %35 ]
ret i32 %39
}