#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 */
struct mdea_node {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ mdea_error(char **, char *, char const *,
                              int /*<<< orphan*/);
int mdea_node_from_file_desc(int, struct mdea_node **, char **);
int open(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int mdea_node_from_file_path(const char *path, struct mdea_node **node,
                             char **error) {
  int file = open(path, O_RDONLY);
  if (file < 0) {
    mdea_error(error, "%s: %s", path, strerror(errno));
    return -1;
  }
  int ret = mdea_node_from_file_desc(file, node, error);
  close(file);
  return ret;
}


x86 assembly (clang, -O0):
<mdea_node_from_file_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e79(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    11c3 <mdea_node_from_file_path+0x73>
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    0x2e3e(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rdx
mov    %eax,%ecx
lea    0xe4e(%rip),%rsi
call   1060 <mdea_error@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e4 <mdea_node_from_file_path+0x94>
mov    -0x24(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1040 <mdea_node_from_file_desc@plt>
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%edi
call   1030 <close@plt>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mdea_node_from_file_path>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
mov    0x2e81(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
test   %eax,%eax
js     118e <mdea_node_from_file_path+0x3e>
mov    %eax,%ebp
mov    %eax,%edi
mov    %r15,%rsi
mov    %r14,%rdx
call   1040 <mdea_node_from_file_desc@plt>
mov    %eax,%ebx
mov    %ebp,%edi
call   1030 <close@plt>
mov    %ebx,%eax
jmp    11b5 <mdea_node_from_file_path+0x65>
mov    0x2e43(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe5d(%rip),%rsi
mov    %r14,%rdi
mov    %rbx,%rdx
mov    %eax,%ecx
call   1060 <mdea_error@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.mdea_node = type { i32 }
@O_RDONLY = global i32 0
@.str = [7 x i8] c"%s: %s\00"
@errno = global i32 0
define i32 @mdea_node_from_file_path(i8* %0, %struct.mdea_node** %1, i8** %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca %struct.mdea_node**
%7 = alloca i8**
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %5
store %struct.mdea_node** %1, %struct.mdea_node*** %6
store i8** %2, i8*** %7
%10 = load i8*, i8** %5
%11 = load i32, i32* @O_RDONLY
%12 = call i32 @open(i8* %10, i32 %11)
store i32 %12, i32* %8
%13 = load i32, i32* %8
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %21
15: ; preds = %3
%16 = load i8**, i8*** %7
%17 = load i8*, i8** %5
%18 = load i32, i32* @errno
%19 = call i32 @strerror(i32 %18)
%20 = call i32 @mdea_error(i8** %16, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %17, i32 %19)
store i32 -1, i32* %4
br label %29
21: ; preds = %3
%22 = load i32, i32* %8
%23 = load %struct.mdea_node**, %struct.mdea_node*** %6
%24 = load i8**, i8*** %7
%25 = call i32 @mdea_node_from_file_desc(i32 %22, %struct.mdea_node** %23, i8** %24)
store i32 %25, i32* %9
%26 = load i32, i32* %8
%27 = call i32 @close(i32 %26)
%28 = load i32, i32* %9
store i32 %28, i32* %4
br label %29
29: ; preds = %21, %15
%30 = load i32, i32* %4
ret i32 %30
}

LLVM IR (-O2):
%struct.mdea_node = type { i32 }
@O_RDONLY = global i32 0
@.str = [7 x i8] c"%s: %s\00"
@errno = global i32 0
define i32 @mdea_node_from_file_path(i8* %0, %struct.mdea_node** %1, i8** %2) {
%4 = load i32, i32* @O_RDONLY
%5 = tail call i32 @open(i8* %0, i32 %4)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %11
7: ; preds = %3
%8 = load i32, i32* @errno
%9 = tail call i32 @strerror(i32 %8)
%10 = tail call i32 @mdea_error(i8** %2, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %9)
br label %14
11: ; preds = %3
%12 = tail call i32 @mdea_node_from_file_desc(i32 %5, %struct.mdea_node** %1, i8** %2)
%13 = tail call i32 @close(i32 %5)
br label %14
14: ; preds = %11, %7
%15 = phi i32 [ -1, %7 ], [ %12, %11 ]
ret i32 %15
}