#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*/ dump_group_end();
int /*<<< orphan*/ dump_group_start(char *);
int /*<<< orphan*/ dump_set_file(int /*<<< orphan*/);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
scalar_t__ read_and_dump_channel(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdin;
int /*<<< orphan*/ stdout;
int main(int argc, char **argv) {
  dump_set_file(stdout);
  if (argc > 1) {
    int i;
    FILE *fp;
    for (i = 1; i < argc; i++) {
      fp = fopen(argv[i], "r");
      if (!fp) {
        fprintf(stderr, "Couldn't open %s\n", argv[i]);
        exit(-1);
      }
      dump_group_start(argv[i]);
      while (read_and_dump_channel(fp) == 0)
        ;
      dump_group_end();
      fclose(fp);
    }
  } else {
    dump_group_start("stdin");
    while (read_and_dump_channel(stdin) == 0)
      ;
    dump_group_end();
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e33(%rip),%rax
mov    (%rax),%edi
call   1090 <dump_set_file@plt>
cmpl   $0x1,-0x8(%rbp)
jle    125f <main+0xdf>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    125a <main+0xda>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe2c(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1213 <main+0x93>
mov    0x2de9(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xdfe(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1060 <dump_group_start@plt>
mov    -0x20(%rbp),%rdi
call   1070 <read_and_dump_channel@plt>
cmp    $0x0,%rax
jne    123c <main+0xbc>
jmp    1224 <main+0xa4>
mov    $0x0,%al
call   1040 <dump_group_end@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11b5 <main+0x35>
jmp    1290 <main+0x110>
lea    0xdae(%rip),%rdi
call   1060 <dump_group_start@plt>
mov    0x2d76(%rip),%rax
mov    (%rax),%rdi
call   1070 <read_and_dump_channel@plt>
cmp    $0x0,%rax
jne    1289 <main+0x109>
jmp    126b <main+0xeb>
mov    $0x0,%al
call   1040 <dump_group_end@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r15
mov    %edi,%ebx
mov    0x2e3b(%rip),%rax
mov    (%rax),%edi
call   1090 <dump_set_file@plt>
cmp    $0x2,%ebx
jl     1207 <main+0x87>
mov    %ebx,%r13d
mov    $0x1,%r12d
lea    0xe4f(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    (%r15,%r12,8),%rdi
mov    %r14,%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1240 <main+0xc0>
mov    %rax,%rbx
mov    (%r15,%r12,8),%rdi
call   1060 <dump_group_start@plt>
nopl   (%rax)
mov    %rbx,%rdi
call   1070 <read_and_dump_channel@plt>
test   %rax,%rax
je     11e0 <main+0x60>
xor    %eax,%eax
call   1040 <dump_group_end@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
add    $0x1,%r12
cmp    %r13,%r12
jne    11c0 <main+0x40>
jmp    1234 <main+0xb4>
lea    0xe06(%rip),%rdi
call   1060 <dump_group_start@plt>
mov    0x2dce(%rip),%rbx
nopw   0x0(%rax,%rax,1)
mov    (%rbx),%rdi
call   1070 <read_and_dump_channel@plt>
test   %rax,%rax
je     1220 <main+0xa0>
xor    %eax,%eax
call   1040 <dump_group_end@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
mov    0x2d91(%rip),%rax
mov    (%rax),%edi
mov    (%r15,%r12,8),%rdx
lea    0xdae(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@stdout = global i32 0
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [18 x i8] c"Couldn't open %s\0A\00"
@.str.2 = [6 x i8] c"stdin\00"
@stdin = global i32* null
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* @stdout
%9 = call i32 @dump_set_file(i32 %8)
%10 = load i32, i32* %4
%11 = icmp sgt i32 %10, 1
br i1 %11, label %12, label %55
12: ; preds = %2
store i32 1, i32* %6
br label %13
13: ; preds = %51, %12
%14 = load i32, i32* %6
%15 = load i32, i32* %4
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %54
17: ; preds = %13
%18 = load i8**, i8*** %5
%19 = load i32, i32* %6
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8*, i8** %18, i64 %20
%22 = load i8*, i8** %21
%23 = call i32* @fopen(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %23, i32** %7
%24 = load i32*, i32** %7
%25 = icmp ne i32* %24, null
br i1 %25, label %35, label %26
26: ; preds = %17
%27 = load i32, i32* @stderr
%28 = load i8**, i8*** %5
%29 = load i32, i32* %6
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8*, i8** %28, i64 %30
%32 = load i8*, i8** %31
%33 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %32)
%34 = call i32 @exit(i32 -1)
unreachable
35: ; preds = %17
%36 = load i8**, i8*** %5
%37 = load i32, i32* %6
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8*, i8** %36, i64 %38
%40 = load i8*, i8** %39
%41 = call i32 @dump_group_start(i8* %40)
br label %42
42: ; preds = %46, %35
%43 = load i32*, i32** %7
%44 = call i64 @read_and_dump_channel(i32* %43)
%45 = icmp eq i64 %44, 0
br i1 %45, label %46, label %47
46: ; preds = %42
br label %42
47: ; preds = %42
%48 = call i32 (...) @dump_group_end()
%49 = load i32*, i32** %7
%50 = call i32 @fclose(i32* %49)
br label %51
51: ; preds = %47
%52 = load i32, i32* %6
%53 = add nsw i32 %52, 1
store i32 %53, i32* %6
br label %13
54: ; preds = %13
br label %64
55: ; preds = %2
%56 = call i32 @dump_group_start(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %57
57: ; preds = %61, %55
%58 = load i32*, i32** @stdin
%59 = call i64 @read_and_dump_channel(i32* %58)
%60 = icmp eq i64 %59, 0
br i1 %60, label %61, label %62
61: ; preds = %57
br label %57
62: ; preds = %57
%63 = call i32 (...) @dump_group_end()
br label %64
64: ; preds = %62, %54
ret i32 0
}

LLVM IR (-O2):
@stdout = global i32 0
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [18 x i8] c"Couldn't open %s\0A\00"
@.str.2 = [6 x i8] c"stdin\00"
@stdin = global i32* null
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = load i32, i32* @stdout
%4 = tail call i32 @dump_set_file(i32 %3)
%5 = icmp sgt i32 %0, 1
br i1 %5, label %6, label %30
6: ; preds = %2
%7 = zext i32 %0 to i64
br label %8
8: ; preds = %6, %25
%9 = phi i64 [ 1, %6 ], [ %28, %25 ]
%10 = getelementptr inbounds i8*, i8** %1, i64 %9
%11 = load i8*, i8** %10
%12 = tail call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %19
14: ; preds = %8
%15 = load i32, i32* @stderr
%16 = load i8*, i8** %10
%17 = tail call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %16)
%18 = tail call i32 @exit(i32 -1)
unreachable
19: ; preds = %8
%20 = load i8*, i8** %10
%21 = tail call i32 @dump_group_start(i8* %20)
br label %22
22: ; preds = %22, %19
%23 = tail call i64 @read_and_dump_channel(i32* %12)
%24 = icmp eq i64 %23, 0
br i1 %24, label %22, label %25
25: ; preds = %22
%26 = tail call i32 (...) @dump_group_end()
%27 = tail call i32 @fclose(i32* %12)
%28 = add nuw nsw i64 %9, 1
%29 = icmp eq i64 %28, %7
br i1 %29, label %38, label %8
30: ; preds = %2
%31 = tail call i32 @dump_group_start(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %32
32: ; preds = %32, %30
%33 = load i32*, i32** @stdin
%34 = tail call i64 @read_and_dump_channel(i32* %33)
%35 = icmp eq i64 %34, 0
br i1 %35, label %32, label %36
36: ; preds = %32
%37 = tail call i32 (...) @dump_group_end()
br label %38
38: ; preds = %25, %36
ret i32 0
}