#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_FAILURE;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdin;
scalar_t__ strcmp(char *, char *);
char *strerror(int /*<<< orphan*/);
FILE *open_json_file(char filename[]) {
  FILE *file;
  if (strcmp(filename, "-") == 0) {
    file = stdin;
  } else {
    file = fopen(filename, "r");
  }
  if (!file) {
    fprintf(stderr,
            "\x1b[31m"
            "Error on openning file '%s': %s\n"
            "\x1b[0m",
            filename, strerror(errno));
    exit(EXIT_FAILURE);
  }
  return file;
}


x86 assembly (clang, -O0):
<open_json_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe99(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
jne    1189 <open_json_file+0x39>
mov    0x2e6b(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x10(%rbp)
jmp    119d <open_json_file+0x4d>
mov    -0x8(%rbp),%rdi
lea    0xe6e(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11ee <open_json_file+0x9e>
mov    0x2e29(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    0x2e0d(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rdx
mov    %rax,%rcx
lea    0xe29(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2de1(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_json_file>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0xea3(%rip),%rsi
call   1030 <strcmp@plt>
test   %rax,%rax
je     1182 <open_json_file+0x32>
lea    0xe94(%rip),%rsi
mov    %rbx,%rdi
call   1050 <fopen@plt>
test   %rax,%rax
je     1191 <open_json_file+0x41>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2e5f(%rip),%rax
mov    (%rax),%rax
test   %rax,%rax
jne    117b <open_json_file+0x2b>
mov    0x2e40(%rip),%rax
mov    (%rax),%ebp
mov    0x2e2f(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe55(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
call   1040 <fprintf@plt>
mov    0x2e05(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

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 = [42 x i8] c"\1B[31mError on openning file '%s': %s\0A\1B[0m\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
define i32* @open_json_file(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = call i64 @strcmp(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = load i32*, i32** @stdin
store i32* %8, i32** %3
br label %12
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
br label %12
12: ; preds = %9, %7
%13 = load i32*, i32** %3
%14 = icmp ne i32* %13, null
br i1 %14, label %23, label %15
15: ; preds = %12
%16 = load i32, i32* @stderr
%17 = load i8*, i8** %2
%18 = load i32, i32* @errno
%19 = call i8* @strerror(i32 %18)
%20 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i8* %17, i8* %19)
%21 = load i32, i32* @EXIT_FAILURE
%22 = call i32 @exit(i32 %21)
unreachable
23: ; preds = %12
%24 = load i32*, i32** %3
ret i32* %24
}

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 = [42 x i8] c"\1B[31mError on openning file '%s': %s\0A\1B[0m\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
define i32* @open_json_file(i8* %0) {
%2 = tail call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i64 %2, 0
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = load i32*, i32** @stdin
br label %8
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))
br label %8
8: ; preds = %6, %4
%9 = phi i32* [ %5, %4 ], [ %7, %6 ]
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %18
11: ; preds = %8
%12 = load i32, i32* @stderr
%13 = load i32, i32* @errno
%14 = tail call i8* @strerror(i32 %13)
%15 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i8* %0, i8* %14)
%16 = load i32, i32* @EXIT_FAILURE
%17 = tail call i32 @exit(i32 %16)
unreachable
18: ; preds = %8
ret i32* %9
}