#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ process_fp(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdin;
int main(int argc, char *argv[]) {
  FILE *fp = stdin;
  if (2 == argc) {
    fp = fopen(argv[1], "r");
    if (!fp) {
      fprintf(stderr, "Unable to open file: %s\n", argv[1]);
      return 1;
    }
  }
  process_fp(fp);
  if (fp != stdin)
    fclose(fp);
  printf("\n");
  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    0x2e7b(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    $0x2,%eax
cmp    -0x8(%rbp),%eax
jne    11d3 <main+0x83>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe6f(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11ce <main+0x7e>
mov    0x2e2c(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe45(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    120c <main+0xbc>
jmp    11d3 <main+0x83>
mov    -0x18(%rbp),%rdi
call   1030 <process_fp@plt>
mov    -0x18(%rbp),%rax
mov    0x2e01(%rip),%rcx
cmp    (%rcx),%rax
je     11f9 <main+0xa9>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
lea    0xe19(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    0x2e8c(%rip),%r15
cmp    $0x2,%edi
jne    119c <main+0x4c>
mov    %rsi,%r14
mov    0x8(%rsi),%rdi
lea    0xe91(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    119f <main+0x4f>
mov    0x2e55(%rip),%rax
mov    (%rax),%edi
mov    0x8(%r14),%rdx
lea    0xe72(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%eax
jmp    11c0 <main+0x70>
mov    (%r15),%rbx
mov    %rbx,%rdi
call   1040 <process_fp@plt>
cmp    (%r15),%rbx
je     11b4 <main+0x64>
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

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

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