#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*/ cgio_close_file(int);
int /*<<< orphan*/ cgio_get_file_type(int, int *);
int cgio_get_node_id(int, double, char *, double *);
int /*<<< orphan*/ cgio_get_root_id(int, double *);
scalar_t__ cgio_open_file(char const *, int /*<<< orphan*/, int /*<<< orphan*/,
                          int *);
int cg_is_cgns(const char *filename, int *file_type) {
  int cgio, ierr;
  double rootid, childid;
  *file_type = 0;
  if (cgio_open_file(filename, 0, 0, &cgio))
    return 1;
  cgio_get_root_id(cgio, &rootid);
  cgio_get_file_type(cgio, file_type);
  ierr = cgio_get_node_id(cgio, rootid, "CGNSLibraryVersion", &childid);
  cgio_close_file(cgio);
  return ierr ? 1 : 0;
}


x86 assembly (clang, -O0):
<cg_is_cgns>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
xor    %edx,%edx
lea    -0x1c(%rbp),%rcx
mov    %edx,%esi
call   1040 <cgio_open_file@plt>
cmp    $0x0,%rax
je     1191 <cg_is_cgns+0x41>
movl   $0x1,-0x4(%rbp)
jmp    11df <cg_is_cgns+0x8f>
mov    -0x1c(%rbp),%edi
lea    -0x28(%rbp),%rsi
call   1060 <cgio_get_root_id@plt>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1070 <cgio_get_file_type@plt>
mov    -0x1c(%rbp),%edi
movsd  -0x28(%rbp),%xmm0
lea    0xe48(%rip),%rsi
lea    -0x30(%rbp),%rdx
call   1050 <cgio_get_node_id@plt>
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%edi
call   1030 <cgio_close_file@plt>
mov    -0x20(%rbp),%edx
xor    %eax,%eax
mov    $0x1,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cg_is_cgns>:
push   %rbx
sub    $0x20,%rsp
mov    %rsi,%rbx
movl   $0x0,(%rsi)
lea    0xc(%rsp),%rcx
xor    %esi,%esi
xor    %edx,%edx
call   1040 <cgio_open_file@plt>
mov    %rax,%rcx
mov    $0x1,%eax
test   %rcx,%rcx
jne    11c0 <cg_is_cgns+0x70>
mov    0xc(%rsp),%edi
lea    0x10(%rsp),%rsi
call   1060 <cgio_get_root_id@plt>
mov    0xc(%rsp),%edi
mov    %rbx,%rsi
call   1070 <cgio_get_file_type@plt>
mov    0xc(%rsp),%edi
movsd  0x10(%rsp),%xmm0
lea    0xe5c(%rip),%rsi
lea    0x18(%rsp),%rdx
call   1050 <cgio_get_node_id@plt>
mov    %eax,%ebx
mov    0xc(%rsp),%edi
call   1030 <cgio_close_file@plt>
xor    %eax,%eax
test   %ebx,%ebx
setne  %al
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [19 x i8] c"CGNSLibraryVersion\00"
define i32 @cg_is_cgns(i8* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca double
%9 = alloca double
store i8* %0, i8** %4
store i32* %1, i32** %5
%10 = load i32*, i32** %5
store i32 0, i32* %10
%11 = load i8*, i8** %4
%12 = call i64 @cgio_open_file(i8* %11, i32 0, i32 0, i32* %6)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %2
store i32 1, i32* %3
br label %30
15: ; preds = %2
%16 = load i32, i32* %6
%17 = call i32 @cgio_get_root_id(i32 %16, double* %8)
%18 = load i32, i32* %6
%19 = load i32*, i32** %5
%20 = call i32 @cgio_get_file_type(i32 %18, i32* %19)
%21 = load i32, i32* %6
%22 = load double, double* %8
%23 = call i32 @cgio_get_node_id(i32 %21, double %22, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), double* %9)
store i32 %23, i32* %7
%24 = load i32, i32* %6
%25 = call i32 @cgio_close_file(i32 %24)
%26 = load i32, i32* %7
%27 = icmp ne i32 %26, 0
%28 = zext i1 %27 to i64
%29 = select i1 %27, i32 1, i32 0
store i32 %29, i32* %3
br label %30
30: ; preds = %15, %14
%31 = load i32, i32* %3
ret i32 %31
}

LLVM IR (-O2):
@.str = [19 x i8] c"CGNSLibraryVersion\00"
define i32 @cg_is_cgns(i8* %0, i32* %1) {
%3 = alloca i32
%4 = alloca double
%5 = alloca double
%6 = bitcast i32* %3 to i8*
%7 = bitcast double* %4 to i8*
%8 = bitcast double* %5 to i8*
store i32 0, i32* %1
%9 = call i64 @cgio_open_file(i8* %0, i32 0, i32 0, i32* %3)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %23
11: ; preds = %2
%12 = load i32, i32* %3
%13 = call i32 @cgio_get_root_id(i32 %12, double* %4)
%14 = load i32, i32* %3
%15 = call i32 @cgio_get_file_type(i32 %14, i32* %1)
%16 = load i32, i32* %3
%17 = load double, double* %4
%18 = call i32 @cgio_get_node_id(i32 %16, double %17, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), double* %5)
%19 = load i32, i32* %3
%20 = call i32 @cgio_close_file(i32 %19)
%21 = icmp ne i32 %18, 0
%22 = zext i1 %21 to i32
br label %23
23: ; preds = %2, %11
%24 = phi i32 [ %22, %11 ], [ 1, %2 ]
ret i32 %24
}