#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 */
char *getenv(char *);
int /*<<< orphan*/ ps_create_directory(char *);
int /*<<< orphan*/ ps_log_open(char *);
char *strrchr(char *, char);
void ps_control_open_logfile() {
  char *filename, *slashpos;
  if ((filename = getenv("PSC_LOGFILENAME")) == NULL)
    return;
  if ((slashpos = strrchr(filename, '/'))) {
    *slashpos = 0;
    ps_create_directory(filename);
    *slashpos = '/';
  }
  ps_log_open(filename);
}


x86 assembly (clang, -O0):
<ps_control_open_logfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xeb1(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x8(%rbp)
cmp    $0x0,%rax
jne    1167 <ps_control_open_logfile+0x27>
jmp    11a3 <ps_control_open_logfile+0x63>
mov    -0x8(%rbp),%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     119a <ps_control_open_logfile+0x5a>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
call   1060 <ps_create_directory@plt>
mov    -0x10(%rbp),%rax
movb   $0x2f,(%rax)
mov    -0x8(%rbp),%rdi
call   1040 <ps_log_open@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ps_control_open_logfile>:
push   %r14
push   %rbx
push   %rax
lea    0xeb5(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     118b <ps_control_open_logfile+0x4b>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
test   %rax,%rax
je     117c <ps_control_open_logfile+0x3c>
mov    %rax,%r14
movb   $0x0,(%rax)
mov    %rbx,%rdi
call   1060 <ps_create_directory@plt>
movb   $0x2f,(%r14)
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <ps_log_open@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [16 x i8] c"PSC_LOGFILENAME\00"
define void @ps_control_open_logfile() {
%1 = alloca i8*
%2 = alloca i8*
%3 = call i8* @getenv(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
store i8* %3, i8** %1
%4 = icmp eq i8* %3, null
br i1 %4, label %5, label %6
5: ; preds = %0
br label %18
6: ; preds = %0
%7 = load i8*, i8** %1
%8 = call i8* @strrchr(i8* %7, i8 signext 47)
store i8* %8, i8** %2
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %15
10: ; preds = %6
%11 = load i8*, i8** %2
store i8 0, i8* %11
%12 = load i8*, i8** %1
%13 = call i32 @ps_create_directory(i8* %12)
%14 = load i8*, i8** %2
store i8 47, i8* %14
br label %15
15: ; preds = %10, %6
%16 = load i8*, i8** %1
%17 = call i32 @ps_log_open(i8* %16)
br label %18
18: ; preds = %15, %5
ret void
}

LLVM IR (-O2):
@.str = [16 x i8] c"PSC_LOGFILENAME\00"
define void @ps_control_open_logfile() {
%1 = tail call i8* @getenv(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%2 = icmp eq i8* %1, null
br i1 %2, label %10, label %3
3: ; preds = %0
%4 = tail call i8* @strrchr(i8* %1, i8 signext 47)
%5 = icmp eq i8* %4, null
br i1 %5, label %8, label %6
6: ; preds = %3
store i8 0, i8* %4
%7 = tail call i32 @ps_create_directory(i8* %1)
store i8 47, i8* %4
br label %8
8: ; preds = %6, %3
%9 = tail call i32 @ps_log_open(i8* %1)
br label %10
10: ; preds = %0, %8
ret void
}