#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 */

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ errmsg(char *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ rdhdr_c(char *, char *, int, int, int *, int *, int *);
int opnfil_c(char *filename, int ispec, int filenum, int *npix, int *nrast,
             int *nframe) {
  char binary[80];
  int fd;
  if (!(rdhdr_c(filename, binary, ispec, filenum, npix, nrast, nframe))) {
    errmsg("Error: Header file not found");
    return (-1);
  }
  if ((fd = open(binary, O_RDONLY)) == -1) {
    errmsg("Error: Unable to open binary file");
    return (-1);
  }
  return (fd);
}


x86 assembly (clang, -O0):
<opnfil_c>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x80(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
mov    -0x20(%rbp),%r8
mov    -0x28(%rbp),%r9
mov    -0x30(%rbp),%rax
mov    %rax,(%rsp)
call   1030 <rdhdr_c@plt>
cmp    $0x0,%eax
jne    1195 <opnfil_c+0x65>
lea    0xe7c(%rip),%rdi
call   1040 <errmsg@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d7 <opnfil_c+0xa7>
lea    -0x80(%rbp),%rdi
mov    0x2e48(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
mov    %eax,-0x84(%rbp)
cmp    $0xffffffff,%eax
jne    11ce <opnfil_c+0x9e>
lea    0xe60(%rip),%rdi
call   1040 <errmsg@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d7 <opnfil_c+0xa7>
mov    -0x84(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<opnfil_c>:
sub    $0x68,%rsp
mov    %r8,%rax
mov    %rcx,%r8
mov    %edx,%ecx
mov    %esi,%edx
mov    %r9,(%rsp)
lea    0x10(%rsp),%rsi
mov    %rax,%r9
call   1030 <rdhdr_c@plt>
test   %eax,%eax
je     1170 <opnfil_c+0x40>
mov    0x2e8e(%rip),%rax
mov    (%rax),%esi
lea    0x10(%rsp),%rdi
call   1050 <open@plt>
cmp    $0xffffffff,%eax
je     1179 <opnfil_c+0x49>
add    $0x68,%rsp
ret
lea    0xe89(%rip),%rdi
jmp    1180 <opnfil_c+0x50>
lea    0xe9d(%rip),%rdi
call   1040 <errmsg@plt>
mov    $0xffffffff,%eax
add    $0x68,%rsp
ret

LLVM IR (-O0):
@.str = [29 x i8] c"Error: Header file not found\00"
@O_RDONLY = global i32 0
@.str.1 = [34 x i8] c"Error: Unable to open binary file\00"
define i32 @opnfil_c(i8* %0, i32 %1, i32 %2, i32* %3, i32* %4, i32* %5) {
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32*
%12 = alloca i32*
%13 = alloca i32*
%14 = alloca [80 x i8]
%15 = alloca i32
store i8* %0, i8** %8
store i32 %1, i32* %9
store i32 %2, i32* %10
store i32* %3, i32** %11
store i32* %4, i32** %12
store i32* %5, i32** %13
%16 = load i8*, i8** %8
%17 = getelementptr inbounds [80 x i8], [80 x i8]* %14, i64 0, i64 0
%18 = load i32, i32* %9
%19 = load i32, i32* %10
%20 = load i32*, i32** %11
%21 = load i32*, i32** %12
%22 = load i32*, i32** %13
%23 = call i32 @rdhdr_c(i8* %16, i8* %17, i32 %18, i32 %19, i32* %20, i32* %21, i32* %22)
%24 = icmp ne i32 %23, 0
br i1 %24, label %27, label %25
25: ; preds = %6
%26 = call i32 @errmsg(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %7
br label %36
27: ; preds = %6
%28 = getelementptr inbounds [80 x i8], [80 x i8]* %14, i64 0, i64 0
%29 = load i32, i32* @O_RDONLY
%30 = call i32 @open(i8* %28, i32 %29)
store i32 %30, i32* %15
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %34
32: ; preds = %27
%33 = call i32 @errmsg(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %7
br label %36
34: ; preds = %27
%35 = load i32, i32* %15
store i32 %35, i32* %7
br label %36
36: ; preds = %34, %32, %25
%37 = load i32, i32* %7
ret i32 %37
}

LLVM IR (-O2):
@.str = [29 x i8] c"Error: Header file not found\00"
@O_RDONLY = global i32 0
@.str.1 = [34 x i8] c"Error: Unable to open binary file\00"
define i32 @opnfil_c(i8* %0, i32 %1, i32 %2, i32* %3, i32* %4, i32* %5) {
%7 = alloca [80 x i8]
%8 = getelementptr inbounds [80 x i8], [80 x i8]* %7, i64 0, i64 0
%9 = call i32 @rdhdr_c(i8* %0, i8* %8, i32 %1, i32 %2, i32* %3, i32* %4, i32* %5)
%10 = icmp eq i32 %9, 0
br i1 %10, label %15, label %11
11: ; preds = %6
%12 = load i32, i32* @O_RDONLY
%13 = call i32 @open(i8* %8, i32 %12)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %18
15: ; preds = %11, %6
%16 = phi i8* [ getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), %6 ], [ getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), %11 ]
%17 = call i32 @errmsg(i8* %16)
br label %18
18: ; preds = %15, %11
%19 = phi i32 [ %13, %11 ], [ -1, %15 ]
ret i32 %19
}