#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*/ ex_nstrncpy(char *, char *, int);
int ex_open_int(char *, int, int *, int *, float *, int);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int exopen(char *path, int *mode, int *cpu_word_size, int *io_word_size,
           float *version, int *ierr, int pathlen) {
  char *name;
  int idexo;
  if (!(name = malloc((pathlen + 1) * sizeof(char)))) {
    *ierr = 1000;
    return (-1);
  }
  (void)ex_nstrncpy(name, path, pathlen);
  if ((idexo = ex_open_int(name, *mode, cpu_word_size, io_word_size, version,
                           522)) != -1) {
    free(name);
    *ierr = 0;
    return (idexo);
  }
  free(name);
  *ierr = -1;
  return (-1);
}


x86 assembly (clang, -O0):
<exopen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    0x10(%rbp),%eax
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    %r9,-0x38(%rbp)
mov    0x10(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x40(%rbp)
cmp    $0x0,%rax
jne    119a <exopen+0x5a>
mov    -0x38(%rbp),%rax
movl   $0x3e8,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    120f <exopen+0xcf>
mov    -0x40(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    0x10(%rbp),%edx
call   1060 <ex_nstrncpy@plt>
mov    -0x40(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    -0x30(%rbp),%r8
mov    $0x20a,%r9d
call   1040 <ex_open_int@plt>
mov    %eax,-0x44(%rbp)
cmp    $0xffffffff,%eax
je     11f5 <exopen+0xb5>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x44(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    120f <exopen+0xcf>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rax
movl   $0xffffffff,(%rax)
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<exopen>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r9,0x10(%rsp)
mov    %r8,0x8(%rsp)
mov    %rcx,%r12
mov    %rdx,%r13
mov    %rsi,%rbp
mov    %rdi,%r14
mov    0x50(%rsp),%r15d
lea    0x1(%r15),%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     11bc <exopen+0x7c>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
mov    %r15d,%edx
call   1060 <ex_nstrncpy@plt>
mov    0x0(%rbp),%esi
mov    %rbx,%rdi
mov    %r13,%rdx
mov    %r12,%rcx
mov    0x8(%rsp),%r8
mov    $0x20a,%r9d
call   1040 <ex_open_int@plt>
mov    %eax,%r14d
xor    %ebp,%ebp
cmp    $0xffffffff,%eax
sete   %bpl
mov    %rbx,%rdi
call   1030 <free@plt>
neg    %ebp
jmp    11c7 <exopen+0x87>
mov    $0xffffffff,%r14d
mov    $0x3e8,%ebp
mov    0x10(%rsp),%rax
mov    %ebp,(%rax)
mov    %r14d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @exopen(i8* %0, i32* %1, i32* %2, i32* %3, float* %4, i32* %5, i32 %6) {
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32*
%11 = alloca i32*
%12 = alloca i32*
%13 = alloca float*
%14 = alloca i32*
%15 = alloca i32
%16 = alloca i8*
%17 = alloca i32
store i8* %0, i8** %9
store i32* %1, i32** %10
store i32* %2, i32** %11
store i32* %3, i32** %12
store float* %4, float** %13
store i32* %5, i32** %14
store i32 %6, i32* %15
%18 = load i32, i32* %15
%19 = add nsw i32 %18, 1
%20 = sext i32 %19 to i64
%21 = mul i64 %20, 1
%22 = trunc i64 %21 to i32
%23 = call i8* @malloc(i32 %22)
store i8* %23, i8** %16
%24 = icmp ne i8* %23, null
br i1 %24, label %27, label %25
25: ; preds = %7
%26 = load i32*, i32** %14
store i32 1000, i32* %26
store i32 -1, i32* %8
br label %49
27: ; preds = %7
%28 = load i8*, i8** %16
%29 = load i8*, i8** %9
%30 = load i32, i32* %15
%31 = call i32 @ex_nstrncpy(i8* %28, i8* %29, i32 %30)
%32 = load i8*, i8** %16
%33 = load i32*, i32** %10
%34 = load i32, i32* %33
%35 = load i32*, i32** %11
%36 = load i32*, i32** %12
%37 = load float*, float** %13
%38 = call i32 @ex_open_int(i8* %32, i32 %34, i32* %35, i32* %36, float* %37, i32 522)
store i32 %38, i32* %17
%39 = icmp ne i32 %38, -1
br i1 %39, label %40, label %45
40: ; preds = %27
%41 = load i8*, i8** %16
%42 = call i32 @free(i8* %41)
%43 = load i32*, i32** %14
store i32 0, i32* %43
%44 = load i32, i32* %17
store i32 %44, i32* %8
br label %49
45: ; preds = %27
%46 = load i8*, i8** %16
%47 = call i32 @free(i8* %46)
%48 = load i32*, i32** %14
store i32 -1, i32* %48
store i32 -1, i32* %8
br label %49
49: ; preds = %45, %40, %25
%50 = load i32, i32* %8
ret i32 %50
}

LLVM IR (-O2):
define i32 @exopen(i8* %0, i32* nocapture %1, i32* %2, i32* %3, float* %4, i32* nocapture writeonly %5, i32 %6) {
%8 = add nsw i32 %6, 1
%9 = tail call i8* @malloc(i32 %8)
%10 = icmp eq i8* %9, null
br i1 %10, label %18, label %11
11: ; preds = %7
%12 = tail call i32 @ex_nstrncpy(i8* %9, i8* %0, i32 %6)
%13 = load i32, i32* %1
%14 = tail call i32 @ex_open_int(i8* %9, i32 %13, i32* %2, i32* %3, float* %4, i32 522)
%15 = icmp eq i32 %14, -1
%16 = tail call i32 @free(i8* %9)
%17 = sext i1 %15 to i32
br label %18
18: ; preds = %11, %7
%19 = phi i32 [ 1000, %7 ], [ %17, %11 ]
%20 = phi i32 [ -1, %7 ], [ %14, %11 ]
store i32 %19, i32* %5
ret i32 %20
}