#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*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ fsafeclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ state_expectations_alldisk(int, double *,
                                              int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int do_state_expectations(int nstates, double *expectations,
                          const char *posterior_name) {
  int errcode = 0;
  FILE *fin_d = NULL;
  if (!(fin_d = fopen(posterior_name, "rb"))) {
    fprintf(stderr, "failed to open the posterior vector file for reading\n");
    errcode = -1;
    goto end;
  }
  state_expectations_alldisk(nstates, expectations, fin_d);
end:
  fsafeclose(fin_d);
  return errcode;
}


x86 assembly (clang, -O0):
<do_state_expectations>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe93(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    11a1 <do_state_expectations+0x61>
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
lea    0xe73(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x1c(%rbp)
jmp    11b1 <do_state_expectations+0x71>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1040 <state_expectations_alldisk@plt>
mov    -0x28(%rbp),%rdi
call   1030 <fsafeclose@plt>
mov    -0x1c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_state_expectations>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %edi,%ebp
lea    0xeb0(%rip),%rsi
mov    %rdx,%rdi
call   1060 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1171 <do_state_expectations+0x31>
mov    %ebp,%edi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1040 <state_expectations_alldisk@plt>
xor    %ebp,%ebp
jmp    118b <do_state_expectations+0x4b>
mov    0x2e68(%rip),%rax
mov    (%rax),%edi
lea    0xe82(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xffffffff,%ebp
mov    %rbx,%rdi
call   1030 <fsafeclose@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.1 = [54 x i8] c"failed to open the posterior vector file for reading\0A\00"
define i32 @do_state_expectations(i32 %0, double* %1, i8* %2) {
%4 = alloca i32
%5 = alloca double*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32*
store i32 %0, i32* %4
store double* %1, double** %5
store i8* %2, i8** %6
store i32 0, i32* %7
store i32* null, i32** %8
%9 = load i8*, i8** %6
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %8
%11 = icmp ne i32* %10, null
br i1 %11, label %15, label %12
12: ; preds = %3
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %7
br label %20
15: ; preds = %3
%16 = load i32, i32* %4
%17 = load double*, double** %5
%18 = load i32*, i32** %8
%19 = call i32 @state_expectations_alldisk(i32 %16, double* %17, i32* %18)
br label %20
20: ; preds = %15, %12
%21 = load i32*, i32** %8
%22 = call i32 @fsafeclose(i32* %21)
%23 = load i32, i32* %7
ret i32 %23
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.1 = [54 x i8] c"failed to open the posterior vector file for reading\0A\00"
define i32 @do_state_expectations(i32 %0, double* %1, i8* nocapture %2) {
%4 = tail call i32* @fopen(i8* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %9
6: ; preds = %3
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.1, i64 0, i64 0))
br label %11
9: ; preds = %3
%10 = tail call i32 @state_expectations_alldisk(i32 %0, double* %1, i32* %4)
br label %11
11: ; preds = %9, %6
%12 = phi i32 [ 0, %9 ], [ -1, %6 ]
%13 = tail call i32 @fsafeclose(i32* %4)
ret i32 %12
}