#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 const *, char *);
int /*<<< orphan*/ perror(char const *);
int /*<<< orphan*/ *stdin;
int /*<<< orphan*/ strcmp(char const *, char *);
int /*<<< orphan*/ sym_read_file(int /*<<< orphan*/ *);
void sym_read_file_by_name(const char *name) {
  FILE *file;
  if (!strcmp(name, "-"))
    file = stdin;
  else {
    file = fopen(name, "r");
    if (!file) {
      perror(name);
      exit(1);
    }
  }
  sym_read_file(file);
  if (file != stdin)
    (void)fclose(file);
}


x86 assembly (clang, -O0):
<sym_read_file_by_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe89(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    1198 <sym_read_file_by_name+0x38>
mov    0x2e5c(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x10(%rbp)
jmp    11cf <sym_read_file_by_name+0x6f>
mov    -0x8(%rbp),%rdi
lea    0xe5f(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11ca <sym_read_file_by_name+0x6a>
mov    -0x8(%rbp),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    11cf <sym_read_file_by_name+0x6f>
mov    -0x10(%rbp),%rdi
call   1060 <sym_read_file@plt>
mov    -0x10(%rbp),%rax
mov    0x2e05(%rip),%rcx
cmp    (%rcx),%rax
je     11f5 <sym_read_file_by_name+0x95>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sym_read_file_by_name>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0xe92(%rip),%rsi
call   1040 <strcmp@plt>
test   %eax,%eax
je     11a0 <sym_read_file_by_name+0x40>
lea    0xe84(%rip),%rsi
mov    %r14,%rdi
call   1050 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11aa <sym_read_file_by_name+0x4a>
mov    %r14,%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    0x2e41(%rip),%rax
mov    (%rax),%rbx
mov    %rbx,%rdi
call   1060 <sym_read_file@plt>
mov    0x2e2f(%rip),%rax
cmp    (%rax),%rbx
je     11cd <sym_read_file_by_name+0x6d>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <fclose@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [2 x i8] c"-\00"
@stdin = global i32* null
@.str.1 = [2 x i8] c"r\00"
define void @sym_read_file_by_name(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = call i32 @strcmp(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp ne i32 %5, 0
br i1 %6, label %9, label %7
7: ; preds = %1
%8 = load i32*, i32** @stdin
store i32* %8, i32** %3
br label %19
9: ; preds = %1
%10 = load i8*, i8** %2
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %11, i32** %3
%12 = load i32*, i32** %3
%13 = icmp ne i32* %12, null
br i1 %13, label %18, label %14
14: ; preds = %9
%15 = load i8*, i8** %2
%16 = call i32 @perror(i8* %15)
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %9
br label %19
19: ; preds = %18, %7
%20 = load i32*, i32** %3
%21 = call i32 @sym_read_file(i32* %20)
%22 = load i32*, i32** %3
%23 = load i32*, i32** @stdin
%24 = icmp ne i32* %22, %23
br i1 %24, label %25, label %28
25: ; preds = %19
%26 = load i32*, i32** %3
%27 = call i32 @fclose(i32* %26)
br label %28
28: ; preds = %25, %19
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"-\00"
@stdin = global i32* null
@.str.1 = [2 x i8] c"r\00"
define void @sym_read_file_by_name(i8* nocapture %0) {
%2 = tail call i32 @strcmp(i8* dereferenceable(1) %0, i8* dereferenceable(2) getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i32 %2, 0
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = load i32*, i32** @stdin
br label %12
6: ; preds = %1
%7 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %12
9: ; preds = %6
%10 = tail call i32 @perror(i8* %0)
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %6, %4
%13 = phi i32* [ %7, %6 ], [ %5, %4 ]
%14 = tail call i32 @sym_read_file(i32* %13)
%15 = load i32*, i32** @stdin
%16 = icmp eq i32* %13, %15
br i1 %16, label %19, label %17
17: ; preds = %12
%18 = tail call i32 @fclose(i32* %13)
br label %19
19: ; preds = %17, %12
ret void
}