#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ F_OK;
int access(char *, int /*<<< orphan*/);
int /*<<< orphan*/ *fopen(char *, char *);
int mkdir(char *, int);
FILE *open_log_out(void) {
  if (access("/var/log", F_OK) == -1) {
    if (mkdir("/var/log", 0655) == -1)
      return NULL;
  }
  return fopen("/var/log/messages", "w");
}


x86 assembly (clang, -O0):
<open_log_out>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e99(%rip),%rax
mov    (%rax),%esi
lea    0xeb8(%rip),%rdi
call   1040 <access@plt>
cmp    $0xffffffff,%eax
jne    1182 <open_log_out+0x52>
lea    0xea3(%rip),%rdi
mov    $0x1ad,%esi
call   1030 <mkdir@plt>
cmp    $0xffffffff,%eax
jne    117d <open_log_out+0x4d>
movq   $0x0,-0x8(%rbp)
jmp    1199 <open_log_out+0x69>
jmp    1182 <open_log_out+0x52>
lea    0xe80(%rip),%rdi
lea    0xe8b(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_log_out>:
push   %rax
mov    0x2ea0(%rip),%rax
mov    (%rax),%esi
lea    0xebf(%rip),%rdi
call   1040 <access@plt>
cmp    $0xffffffff,%eax
jne    1161 <open_log_out+0x31>
lea    0xeae(%rip),%rdi
mov    $0x1ad,%esi
call   1030 <mkdir@plt>
cmp    $0xffffffff,%eax
je     1175 <open_log_out+0x45>
lea    0xea1(%rip),%rdi
lea    0xeac(%rip),%rsi
pop    %rax
jmp    1050 <fopen@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [9 x i8] c"/var/log\00"
@F_OK = global i32 0
@.str.1 = [18 x i8] c"/var/log/messages\00"
@.str.2 = [2 x i8] c"w\00"
define i32* @open_log_out() {
%1 = alloca i32*
%2 = load i32, i32* @F_OK
%3 = call i32 @access(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %2)
%4 = icmp eq i32 %3, -1
br i1 %4, label %5, label %10
5: ; preds = %0
%6 = call i32 @mkdir(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 429)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %9
8: ; preds = %5
store i32* null, i32** %1
br label %12
9: ; preds = %5
br label %10
10: ; preds = %9, %0
%11 = call i32* @fopen(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %11, i32** %1
br label %12
12: ; preds = %10, %8
%13 = load i32*, i32** %1
ret i32* %13
}

LLVM IR (-O2):
@.str = [9 x i8] c"/var/log\00"
@F_OK = global i32 0
@.str.1 = [18 x i8] c"/var/log/messages\00"
@.str.2 = [2 x i8] c"w\00"
define noalias i32* @open_log_out() {
%1 = load i32, i32* @F_OK
%2 = tail call i32 @access(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = icmp eq i32 %2, -1
br i1 %3, label %4, label %7
4: ; preds = %0
%5 = tail call i32 @mkdir(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 429)
%6 = icmp eq i32 %5, -1
br i1 %6, label %9, label %7
7: ; preds = %4, %0
%8 = tail call i32* @fopen(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %9
9: ; preds = %4, %7
%10 = phi i32* [ %8, %7 ], [ null, %4 ]
ret i32* %10
}