#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(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ process(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdin;
int /*<<< orphan*/ strcpy(char *, char *);
int main(int argc, char *argv[]) {
  char infname[128];
  FILE *infile;
  if (argc > 1) {
    strcpy(infname, argv[1]);
    if ((infile = fopen(infname, "r")) == NULL) {
      fputs("\nUnable to open file\n", stderr);
      exit(1);
    }
    process(infile);
    fclose(infile);
  } else
    process(stdin);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    11f7 <main+0x97>
lea    -0x90(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1030 <strcpy@plt>
lea    -0x90(%rbp),%rdi
lea    0xe5b(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x98(%rbp)
cmp    $0x0,%rax
jne    11da <main+0x7a>
mov    0x2e16(%rip),%rax
mov    (%rax),%esi
lea    0xe37(%rip),%rdi
call   1050 <fputs@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x98(%rbp),%rdi
call   1060 <process@plt>
mov    -0x98(%rbp),%rdi
call   1040 <fclose@plt>
jmp    1206 <main+0xa6>
mov    0x2dea(%rip),%rax
mov    (%rax),%rdi
call   1060 <process@plt>
xor    %edi,%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x80,%rsp
cmp    $0x2,%edi
jl     11af <main+0x4f>
mov    0x8(%rsi),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1030 <strcpy@plt>
lea    0xe7d(%rip),%rsi
mov    %rbx,%rdi
call   1070 <fopen@plt>
test   %rax,%rax
jne    11c5 <main+0x65>
mov    0x2e41(%rip),%rax
mov    (%rax),%esi
lea    0xe62(%rip),%rdi
call   1050 <fputs@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    0x2e32(%rip),%rax
mov    (%rax),%rdi
call   1060 <process@plt>
xor    %edi,%edi
call   1080 <exit@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <process@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [22 x i8] c"\0AUnable to open file\0A\00"
@stderr = global i32 0
@stdin = global i32* null
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [128 x i8]
%7 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp sgt i32 %8, 1
br i1 %9, label %10, label %28
10: ; preds = %2
%11 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = call i32 @strcpy(i8* %11, i8* %14)
%16 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%17 = call i32* @fopen(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %17, i32** %7
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %23
19: ; preds = %10
%20 = load i32, i32* @stderr
%21 = call i32 @fputs(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %20)
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %10
%24 = load i32*, i32** %7
%25 = call i32 @process(i32* %24)
%26 = load i32*, i32** %7
%27 = call i32 @fclose(i32* %26)
br label %31
28: ; preds = %2
%29 = load i32*, i32** @stdin
%30 = call i32 @process(i32* %29)
br label %31
31: ; preds = %28, %23
%32 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [22 x i8] c"\0AUnable to open file\0A\00"
@stderr = global i32 0
@stdin = global i32* null
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [128 x i8]
%4 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%5 = icmp sgt i32 %0, 1
br i1 %5, label %6, label %19
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = call i32 @strcpy(i8* %4, i8* %8)
%10 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %16
12: ; preds = %6
%13 = load i32, i32* @stderr
%14 = call i32 @fputs(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %13)
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %6
%17 = call i32 @process(i32* %10)
%18 = call i32 @fclose(i32* %10)
br label %22
19: ; preds = %2
%20 = load i32*, i32** @stdin
%21 = tail call i32 @process(i32* %20)
br label %22
22: ; preds = %19, %16
%23 = call i32 @exit(i32 0)
unreachable
}