#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*/ close(int);
int creat(char const *, int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ mdea_error(char **, char *, char const *,
                              int /*<<< orphan*/);
int mdea_node_to_file_desc(struct mdea_node *, int, char **);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int mdea_node_to_file_path(struct mdea_node *node, const char *path,
                           char **error) {
  int file = creat(path, 0777);
  if (file < 0) {
    mdea_error(error, "%s: %s", path, strerror(errno));
    return -1;
  }
  int ret = mdea_node_to_file_desc(node, file, error);
  close(file);
  return ret;
}


x86 assembly (clang, -O0):
<mdea_node_to_file_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x1ff,%esi
call   1050 <creat@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    11bf <mdea_node_to_file_path+0x6f>
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    0x2e4a(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rdx
mov    %eax,%ecx
lea    0xe52(%rip),%rsi
call   1060 <mdea_error@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e0 <mdea_node_to_file_path+0x90>
mov    -0x10(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x20(%rbp),%rdx
call   1030 <mdea_node_to_file_desc@plt>
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%edi
call   1040 <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_to_file_path>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r15
mov    %rsi,%rdi
mov    $0x1ff,%esi
call   1050 <creat@plt>
test   %eax,%eax
js     118d <mdea_node_to_file_path+0x3d>
mov    %eax,%ebp
mov    %r15,%rdi
mov    %eax,%esi
mov    %r14,%rdx
call   1030 <mdea_node_to_file_desc@plt>
mov    %eax,%ebx
mov    %ebp,%edi
call   1040 <close@plt>
mov    %ebx,%eax
jmp    11b4 <mdea_node_to_file_path+0x64>
mov    0x2e4c(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe5e(%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 }
@.str = [7 x i8] c"%s: %s\00"
@errno = global i32 0
define i32 @mdea_node_to_file_path(%struct.mdea_node* %0, i8* %1, i8** %2) {
%4 = alloca i32
%5 = alloca %struct.mdea_node*
%6 = alloca i8*
%7 = alloca i8**
%8 = alloca i32
%9 = alloca i32
store %struct.mdea_node* %0, %struct.mdea_node** %5
store i8* %1, i8** %6
store i8** %2, i8*** %7
%10 = load i8*, i8** %6
%11 = call i32 @creat(i8* %10, i32 511)
store i32 %11, i32* %8
%12 = load i32, i32* %8
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %20
14: ; preds = %3
%15 = load i8**, i8*** %7
%16 = load i8*, i8** %6
%17 = load i32, i32* @errno
%18 = call i32 @strerror(i32 %17)
%19 = call i32 @mdea_error(i8** %15, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %16, i32 %18)
store i32 -1, i32* %4
br label %28
20: ; preds = %3
%21 = load %struct.mdea_node*, %struct.mdea_node** %5
%22 = load i32, i32* %8
%23 = load i8**, i8*** %7
%24 = call i32 @mdea_node_to_file_desc(%struct.mdea_node* %21, i32 %22, i8** %23)
store i32 %24, i32* %9
%25 = load i32, i32* %8
%26 = call i32 @close(i32 %25)
%27 = load i32, i32* %9
store i32 %27, i32* %4
br label %28
28: ; preds = %20, %14
%29 = load i32, i32* %4
ret i32 %29
}

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