#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*/ error(int, char *, char const *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
float *read_bg(int /*<<< orphan*/ *, int *, int *);
int /*<<< orphan*/ *stdin;
float *read_bg_filename(const char *filename, int *m, int *n) {
  FILE *fp = stdin;
  if (filename != 0 && !(fp = fopen(filename, "r")))
    error(2, "Cannot open file '%s'\n", filename);
  float *lp = read_bg(fp, m, n);
  if (filename != 0)
    fclose(fp);
  return lp;
}


x86 assembly (clang, -O0):
<read_bg_filename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    0x2e8d(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11a0 <read_bg_filename+0x60>
mov    -0x8(%rbp),%rdi
lea    0xe88(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11a0 <read_bg_filename+0x60>
mov    -0x8(%rbp),%rdx
mov    $0x2,%edi
lea    0xe67(%rip),%rsi
call   1050 <error@plt>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <read_bg@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11c9 <read_bg_filename+0x89>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_bg_filename>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
test   %rdi,%rdi
je     11a6 <read_bg_filename+0x66>
mov    %rdi,%rbx
lea    0xea3(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%r12
test   %rax,%rax
jne    117e <read_bg_filename+0x3e>
lea    0xe91(%rip),%rsi
mov    $0x2,%edi
mov    %rbx,%rdx
call   1050 <error@plt>
mov    %r12,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1030 <read_bg@plt>
mov    %rax,%rbx
mov    %r12,%rdi
call   1040 <fclose@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2e3b(%rip),%rax
mov    (%rax),%rdi
mov    %r15,%rsi
mov    %r14,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <read_bg@plt>

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

LLVM IR (-O2):
@stdin = global i32* null
@.str = [2 x i8] c"r\00"
@.str.1 = [23 x i8] c"Cannot open file '%s'\0A\00"
define float* @read_bg_filename(i8* %0, i32* %1, i32* %2) {
%4 = icmp eq i8* %0, null
br i1 %4, label %10, label %5
5: ; preds = %3
%6 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %13
8: ; preds = %5
%9 = tail call i32 @error(i32 2, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %13
10: ; preds = %3
%11 = load i32*, i32** @stdin
%12 = tail call float* @read_bg(i32* %11, i32* %1, i32* %2)
br label %16
13: ; preds = %8, %5
%14 = tail call float* @read_bg(i32* %6, i32* %1, i32* %2)
%15 = tail call i32 @fclose(i32* %6)
br label %16
16: ; preds = %10, %13
%17 = phi float* [ %14, %13 ], [ %12, %10 ]
ret float* %17
}