#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*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdin;
FILE *openfil(const char *s) {
  FILE *b;
  if (s[0] == '-' && s[1] == 0)
    b = stdin;
  else if ((b = fopen(s, "r")) == NULL) {
    fprintf(stderr, "comm: cannot open %s\n", s);
    exit(1);
  }
  return (b);
}


x86 assembly (clang, -O0):
<openfil>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    1170 <openfil+0x40>
mov    -0x8(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x0,%eax
jne    1170 <openfil+0x40>
mov    0x2e84(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x10(%rbp)
jmp    11b6 <openfil+0x86>
mov    -0x8(%rbp),%rdi
lea    0xe85(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11b1 <openfil+0x81>
mov    0x2e43(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe60(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
jmp    11b6 <openfil+0x86>
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<openfil>:
push   %rbx
mov    %rdi,%rbx
cmpb   $0x2d,(%rdi)
jne    113f <openfil+0xf>
cmpb   $0x0,0x1(%rbx)
je     1155 <openfil+0x25>
lea    0xeba(%rip),%rsi
mov    %rbx,%rdi
call   1040 <fopen@plt>
test   %rax,%rax
je     1161 <openfil+0x31>
pop    %rbx
ret
mov    0x2e8c(%rip),%rax
mov    (%rax),%rax
pop    %rbx
ret
mov    0x2e70(%rip),%rax
mov    (%rax),%edi
lea    0xe91(%rip),%rsi
mov    %rbx,%rdx
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

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

LLVM IR (-O2):
@stdin = global i32* null
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [22 x i8] c"comm: cannot open %s\0A\00"
define i32* @openfil(i8* %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 45
br i1 %3, label %4, label %10
4: ; preds = %1
%5 = getelementptr inbounds i8, i8* %0, i64 1
%6 = load i8, i8* %5
%7 = icmp eq i8 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %4
%9 = load i32*, i32** @stdin
br label %17
10: ; preds = %4, %1
%11 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %17
13: ; preds = %10
%14 = load i32, i32* @stderr
%15 = tail call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%16 = tail call i32 @exit(i32 1)
unreachable
17: ; preds = %10, %8
%18 = phi i32* [ %9, %8 ], [ %11, %10 ]
ret i32* %18
}