#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 AACGM_v2_LoadCoefFP(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int AACGM_v2_LoadCoef(char *fname, int code) {
  FILE *fp = NULL;
  int err = -2;
  fp = fopen(fname, "r");
  if (fp == NULL) {
    return -1;
  }
  err = AACGM_v2_LoadCoefFP(fp, code);
  if (err != 0) {
    return -2;
  }
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<AACGM_v2_LoadCoef>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0xfffffffe,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea7(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1179 <AACGM_v2_LoadCoef+0x49>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ae <AACGM_v2_LoadCoef+0x7e>
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1040 <AACGM_v2_LoadCoefFP@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     119e <AACGM_v2_LoadCoef+0x6e>
movl   $0xfffffffe,-0x4(%rbp)
jmp    11ae <AACGM_v2_LoadCoef+0x7e>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<AACGM_v2_LoadCoef>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
lea    0xec4(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     116a <AACGM_v2_LoadCoef+0x3a>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %ebp,%esi
call   1040 <AACGM_v2_LoadCoefFP@plt>
mov    %eax,%ecx
mov    $0xfffffffe,%eax
test   %ecx,%ecx
jne    116f <AACGM_v2_LoadCoef+0x3f>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
jmp    116f <AACGM_v2_LoadCoef+0x3f>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
define i32 @AACGM_v2_LoadCoef(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32* null, i32** %6
store i32 -2, i32* %7
%8 = load i8*, i8** %4
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %9, i32** %6
%10 = load i32*, i32** %6
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %13
12: ; preds = %2
store i32 -1, i32* %3
br label %23
13: ; preds = %2
%14 = load i32*, i32** %6
%15 = load i32, i32* %5
%16 = call i32 @AACGM_v2_LoadCoefFP(i32* %14, i32 %15)
store i32 %16, i32* %7
%17 = load i32, i32* %7
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %13
store i32 -2, i32* %3
br label %23
20: ; preds = %13
%21 = load i32*, i32** %6
%22 = call i32 @fclose(i32* %21)
store i32 0, i32* %3
br label %23
23: ; preds = %20, %19, %12
%24 = load i32, i32* %3
ret i32 %24
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
define i32 @AACGM_v2_LoadCoef(i8* nocapture %0, i32 %1) {
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %10, label %5
5: ; preds = %2
%6 = tail call i32 @AACGM_v2_LoadCoefFP(i32* %3, i32 %1)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %5
%9 = tail call i32 @fclose(i32* %3)
br label %10
10: ; preds = %5, %2, %8
%11 = phi i32 [ 0, %8 ], [ -1, %2 ], [ -2, %5 ]
ret i32 %11
}