#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 *, ...);
int read_particles_from_file(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdin;
scalar_t__ strcmp(char const *, char *);
int nn_read_input_file(const char *filename) {
  int ok = 1;
  FILE *file = NULL;
  if (!filename) {
    fprintf(stderr, "Error: No input file provided.\n");
    ok = 0;
  } else if (strcmp(filename, "-") == 0) {
    ok = read_particles_from_file(stdin);
  } else {
    file = fopen(filename, "r");
    if (!file) {
      fprintf(stderr, "Error: Failed to open input file %s\n", filename);
      ok = 0;
    } else {
      ok = read_particles_from_file(file);
      fclose(file);
    }
  }
  return ok;
}


x86 assembly (clang, -O0):
<nn_read_input_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
movq   $0x0,-0x18(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1199 <nn_read_input_file+0x49>
mov    0x2e5b(%rip),%rax
mov    (%rax),%edi
lea    0xe7a(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x0,-0xc(%rbp)
jmp    122f <nn_read_input_file+0xdf>
mov    -0x8(%rbp),%rdi
lea    0xe7c(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11ca <nn_read_input_file+0x7a>
mov    0x2e2e(%rip),%rax
mov    (%rax),%rdi
call   1070 <read_particles_from_file@plt>
mov    %eax,-0xc(%rbp)
jmp    122a <nn_read_input_file+0xda>
mov    -0x8(%rbp),%rdi
lea    0xe4d(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1210 <nn_read_input_file+0xc0>
mov    0x2de8(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe27(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x0,-0xc(%rbp)
jmp    1225 <nn_read_input_file+0xd5>
mov    -0x18(%rbp),%rdi
call   1070 <read_particles_from_file@plt>
mov    %eax,-0xc(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
jmp    122a <nn_read_input_file+0xda>
jmp    122f <nn_read_input_file+0xdf>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nn_read_input_file>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     119a <nn_read_input_file+0x4a>
mov    %rdi,%rbx
lea    0xebd(%rip),%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
je     11b3 <nn_read_input_file+0x63>
lea    0xeae(%rip),%rsi
mov    %rbx,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     11c9 <nn_read_input_file+0x79>
mov    %rax,%r14
mov    %rax,%rdi
call   1070 <read_particles_from_file@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    %ebx,%eax
jmp    11e5 <nn_read_input_file+0x95>
mov    0x2e37(%rip),%rax
mov    (%rax),%edi
lea    0xe56(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    11e3 <nn_read_input_file+0x93>
mov    0x2e2e(%rip),%rax
mov    (%rax),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1070 <read_particles_from_file@plt>
mov    0x2e08(%rip),%rax
mov    (%rax),%edi
lea    0xe4b(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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