#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*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ do_more(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ *stdin;
int main(int argc, char *argv[]) {
  FILE *fp;
  FILE *fp_tty = fopen("/dev/tty", "w+");
  if (fp_tty == NULL) {
    printf("Can not open or write /dev/tty!\n");
    exit(EXIT_FAILURE);
  }
  if (argc == 1)
    do_more(stdin, fp_tty);
  else
    while (--argc) {
      if ((fp = fopen(*++argv, "r")) != NULL) {
        do_more(fp, fp_tty);
        fclose(fp);
      } else {
        printf("%s is an invalid file!\n", *argv);
        exit(EXIT_FAILURE);
      }
    }
  return EXIT_SUCCESS;
}


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)
lea    0xe93(%rip),%rdi
lea    0xe95(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11a4 <main+0x54>
lea    0xe7d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2e3b(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
cmpl   $0x1,-0x8(%rbp)
jne    11c6 <main+0x76>
mov    0x2e33(%rip),%rax
mov    (%rax),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <do_more@plt>
jmp    1252 <main+0x102>
jmp    11cb <main+0x7b>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
je     124d <main+0xfd>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
mov    0x8(%rax),%rdi
lea    0xe36(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     1225 <main+0xd5>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <do_more@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
jmp    1248 <main+0xf8>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xdfc(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2d97(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
jmp    11cb <main+0x7b>
jmp    1252 <main+0x102>
mov    0x2d77(%rip),%rax
mov    (%rax),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%ebp
lea    0xe89(%rip),%rdi
lea    0xe8b(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1228 <main+0xc8>
mov    %rax,%r12
cmp    $0x1,%ebp
jne    11a8 <main+0x48>
mov    0x2e4d(%rip),%rax
mov    (%rax),%rdi
mov    %r12,%rsi
call   1060 <do_more@plt>
jmp    11f0 <main+0x90>
mov    %ebp,%r13d
mov    $0x1,%ebx
lea    0xe55(%rip),%r15
nopw   0x0(%rax,%rax,1)
mov    (%r14,%rbx,8),%rdi
mov    %r15,%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1208 <main+0xa8>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %r12,%rsi
call   1060 <do_more@plt>
mov    %rbp,%rdi
call   1040 <fclose@plt>
add    $0x1,%rbx
cmp    %ebx,%r13d
jne    11c0 <main+0x60>
mov    0x2dd9(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%r14,%rbx,8),%rsi
lea    0xdfb(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2db7(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
lea    0xdf7(%rip),%rdi
call   1030 <puts@plt>
jmp    121a <main+0xba>

LLVM IR (-O0):
@.str = [9 x i8] c"/dev/tty\00"
@.str.1 = [3 x i8] c"w+\00"
@.str.2 = [33 x i8] c"Can not open or write /dev/tty!\0A\00"
@EXIT_FAILURE = global i32 0
@stdin = global i32* null
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [24 x i8] c"%s is an invalid file!\0A\00"
@EXIT_SUCCESS = 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*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %8, i32** %7
%9 = load i32*, i32** %7
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %15
11: ; preds = %2
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
%13 = load i32, i32* @EXIT_FAILURE
%14 = call i32 @exit(i32 %13)
unreachable
15: ; preds = %2
%16 = load i32, i32* %4
%17 = icmp eq i32 %16, 1
br i1 %17, label %18, label %22
18: ; preds = %15
%19 = load i32*, i32** @stdin
%20 = load i32*, i32** %7
%21 = call i32 @do_more(i32* %19, i32* %20)
br label %47
22: ; preds = %15
br label %23
23: ; preds = %45, %22
%24 = load i32, i32* %4
%25 = add nsw i32 %24, -1
store i32 %25, i32* %4
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %46
27: ; preds = %23
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i32 1
store i8** %29, i8*** %5
%30 = load i8*, i8** %29
%31 = call i32* @fopen(i8* %30, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %31, i32** %6
%32 = icmp ne i32* %31, null
br i1 %32, label %33, label %39
33: ; preds = %27
%34 = load i32*, i32** %6
%35 = load i32*, i32** %7
%36 = call i32 @do_more(i32* %34, i32* %35)
%37 = load i32*, i32** %6
%38 = call i32 @fclose(i32* %37)
br label %45
39: ; preds = %27
%40 = load i8**, i8*** %5
%41 = load i8*, i8** %40
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i8* %41)
%43 = load i32, i32* @EXIT_FAILURE
%44 = call i32 @exit(i32 %43)
unreachable
45: ; preds = %33
br label %23
46: ; preds = %23
br label %47
47: ; preds = %46, %18
%48 = load i32, i32* @EXIT_SUCCESS
ret i32 %48
}

LLVM IR (-O2):
@.str = [9 x i8] c"/dev/tty\00"
@.str.1 = [3 x i8] c"w+\00"
@EXIT_FAILURE = global i32 0
@stdin = global i32* null
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [24 x i8] c"%s is an invalid file!\0A\00"
@EXIT_SUCCESS = global i32 0
@str = [32 x i8] c"Can not open or write /dev/tty!\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %9
5: ; preds = %2
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str, i64 0, i64 0))
%7 = load i32, i32* @EXIT_FAILURE
%8 = tail call i32 @exit(i32 %7)
unreachable
9: ; preds = %2
%10 = icmp eq i32 %0, 1
br i1 %10, label %13, label %11
11: ; preds = %9
%12 = add nsw i32 %0, -1
br label %16
13: ; preds = %9
%14 = load i32*, i32** @stdin
%15 = tail call i32 @do_more(i32* %14, i32* %3)
br label %33
16: ; preds = %11, %23
%17 = phi i32 [ %26, %23 ], [ %12, %11 ]
%18 = phi i8** [ %19, %23 ], [ %1, %11 ]
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = tail call i32* @fopen(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%22 = icmp eq i32* %21, null
br i1 %22, label %28, label %23
23: ; preds = %16
%24 = tail call i32 @do_more(i32* %21, i32* %3)
%25 = tail call i32 @fclose(i32* %21)
%26 = add nsw i32 %17, -1
%27 = icmp eq i32 %26, 0
br i1 %27, label %33, label %16
28: ; preds = %16
%29 = load i8*, i8** %19
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i8* %29)
%31 = load i32, i32* @EXIT_FAILURE
%32 = tail call i32 @exit(i32 %31)
unreachable
33: ; preds = %23, %13
%34 = load i32, i32* @EXIT_SUCCESS
ret i32 %34
}