#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 */
scalar_t__ ENOENT;
int creat(char const *, int);
int /*<<< orphan*/ create_parent_directory_hierarchy(char const *, int);
scalar_t__ errno;
int set_output_stream(const char *pathname, int mode) {
  int fd;
  if (((fd = creat(pathname, mode)) < 0) && (errno == ENOENT)) {
    create_parent_directory_hierarchy(pathname, 0755);
    return creat(pathname, mode);
  }
  return fd;
}


x86 assembly (clang, -O0):
<set_output_stream>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1030 <creat@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    1183 <set_output_stream+0x63>
mov    0x2e92(%rip),%rax
mov    (%rax),%rax
mov    0x2e78(%rip),%rcx
cmp    (%rcx),%rax
jne    1183 <set_output_stream+0x63>
mov    -0x10(%rbp),%rdi
mov    $0x1ed,%esi
call   1040 <create_parent_directory_hierarchy@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1030 <creat@plt>
mov    %eax,-0x4(%rbp)
jmp    1189 <set_output_stream+0x69>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_output_stream>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
call   1030 <creat@plt>
test   %eax,%eax
jns    1164 <set_output_stream+0x44>
mov    0x2ea8(%rip),%rcx
mov    (%rcx),%rcx
mov    0x2e8e(%rip),%rdx
cmp    (%rdx),%rcx
jne    1164 <set_output_stream+0x44>
mov    %rbx,%rdi
mov    $0x1ed,%esi
call   1040 <create_parent_directory_hierarchy@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <creat@plt>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i64 0
@ENOENT = global i64 0
define i32 @set_output_stream(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%7 = load i8*, i8** %4
%8 = load i32, i32* %5
%9 = call i32 @creat(i8* %7, i32 %8)
store i32 %9, i32* %6
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %21
11: ; preds = %2
%12 = load i64, i64* @errno
%13 = load i64, i64* @ENOENT
%14 = icmp eq i64 %12, %13
br i1 %14, label %15, label %21
15: ; preds = %11
%16 = load i8*, i8** %4
%17 = call i32 @create_parent_directory_hierarchy(i8* %16, i32 493)
%18 = load i8*, i8** %4
%19 = load i32, i32* %5
%20 = call i32 @creat(i8* %18, i32 %19)
store i32 %20, i32* %3
br label %23
21: ; preds = %11, %2
%22 = load i32, i32* %6
store i32 %22, i32* %3
br label %23
23: ; preds = %21, %15
%24 = load i32, i32* %3
ret i32 %24
}

LLVM IR (-O2):
@errno = global i64 0
@ENOENT = global i64 0
define i32 @set_output_stream(i8* %0, i32 %1) {
%3 = tail call i32 @creat(i8* %0, i32 %1)
%4 = icmp slt i32 %3, 0
br i1 %4, label %5, label %12
5: ; preds = %2
%6 = load i64, i64* @errno
%7 = load i64, i64* @ENOENT
%8 = icmp eq i64 %6, %7
br i1 %8, label %9, label %12
9: ; preds = %5
%10 = tail call i32 @create_parent_directory_hierarchy(i8* %0, i32 493)
%11 = tail call i32 @creat(i8* %0, i32 %1)
br label %12
12: ; preds = %2, %5, %9
%13 = phi i32 [ %11, %9 ], [ %3, %5 ], [ %3, %2 ]
ret i32 %13
}