#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 const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int read_conllx(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdin;
int /*<<< orphan*/ strlen(char const *);
scalar_t__ strncmp(char const *, char *, int /*<<< orphan*/);
int open_conllx(const char *filename) {
  FILE *fp;
  if (strncmp(filename, "-", strlen(filename)) == 0) {
    fp = stdin;
  } else {
    fp = fopen(filename, "r");
    if (fp == NULL) {
      fprintf(stderr, "no such file or directory: %s\n", filename);
      return -1;
    }
  }
  if (read_conllx(fp) == -1) {
    fprintf(stderr, "Failed to read %s\n", filename);
    return -1;
  }
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<open_conllx>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x20(%rbp),%rdi
mov    %eax,%edx
lea    0xe76(%rip),%rsi
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    11ac <open_conllx+0x4c>
mov    0x2e48(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
jmp    11f5 <open_conllx+0x95>
mov    -0x10(%rbp),%rdi
lea    0xe4b(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11f0 <open_conllx+0x90>
mov    0x2e06(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe25(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    123c <open_conllx+0xdc>
jmp    11f5 <open_conllx+0x95>
mov    -0x18(%rbp),%rdi
call   1040 <read_conllx@plt>
cmp    $0xffffffff,%eax
jne    122c <open_conllx+0xcc>
mov    0x2dca(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe08(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    123c <open_conllx+0xdc>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_conllx>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1060 <strlen@plt>
lea    0xe8d(%rip),%rsi
mov    %r14,%rdi
mov    %eax,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     11ab <open_conllx+0x4b>
lea    0xe79(%rip),%rsi
mov    %r14,%rdi
call   1080 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11b5 <open_conllx+0x55>
mov    0x2e38(%rip),%rax
mov    (%rax),%edi
lea    0xe5b(%rip),%rsi
jmp    11de <open_conllx+0x7e>
mov    0x2e36(%rip),%rax
mov    (%rax),%rbx
mov    %rbx,%rdi
call   1040 <read_conllx@plt>
cmp    $0xffffffff,%eax
je     11ce <open_conllx+0x6e>
mov    %rbx,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
jmp    11eb <open_conllx+0x8b>
mov    0x2e03(%rip),%rax
mov    (%rax),%edi
lea    0xe45(%rip),%rsi
mov    %r14,%rdx
call   1070 <fprintf@plt>
mov    $0xffffffff,%eax
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"
@stderr = global i32 0
@.str.2 = [31 x i8] c"no such file or directory: %s\0A\00"
@.str.3 = [19 x i8] c"Failed to read %s\0A\00"
define i32 @open_conllx(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = load i8*, i8** %3
%7 = call i32 @strlen(i8* %6)
%8 = call i64 @strncmp(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %1
%11 = load i32*, i32** @stdin
store i32* %11, i32** %4
br label %22
12: ; preds = %1
%13 = load i8*, i8** %3
%14 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %14, i32** %4
%15 = load i32*, i32** %4
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %21
17: ; preds = %12
%18 = load i32, i32* @stderr
%19 = load i8*, i8** %3
%20 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i8* %19)
store i32 -1, i32* %2
br label %33
21: ; preds = %12
br label %22
22: ; preds = %21, %10
%23 = load i32*, i32** %4
%24 = call i32 @read_conllx(i32* %23)
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %30
26: ; preds = %22
%27 = load i32, i32* @stderr
%28 = load i8*, i8** %3
%29 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %28)
store i32 -1, i32* %2
br label %33
30: ; preds = %22
%31 = load i32*, i32** %4
%32 = call i32 @fclose(i32* %31)
store i32 0, i32* %2
br label %33
33: ; preds = %30, %26, %17
%34 = load i32, i32* %2
ret i32 %34
}

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