#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*/ create_dir(char *, int);
int /*<<< orphan*/ *fopen(char *, char *);
char *strrchr(char *, char);
FILE *create_file(char *pathname, int mode) {
  FILE *f;
  f = fopen(pathname, "w+");
  if (f == NULL) {
    char *p = strrchr(pathname, '/');
    if (p != NULL) {
      *p = '\0';
      create_dir(pathname, 0755);
      *p = '/';
      f = fopen(pathname, "w+");
    }
  }
  return (f);
}


x86 assembly (clang, -O0):
<create_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xeb6(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11b0 <create_file+0x80>
mov    -0x8(%rbp),%rdi
mov    $0x2f,%esi
call   1030 <strrchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11ab <create_file+0x7b>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
mov    $0x1ed,%esi
call   1040 <create_dir@plt>
mov    -0x20(%rbp),%rax
movb   $0x2f,(%rax)
mov    -0x8(%rbp),%rdi
lea    0xe5e(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
jmp    11b0 <create_file+0x80>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_file>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0xec2(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     1150 <create_file+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1030 <strrchr@plt>
test   %rax,%rax
je     118f <create_file+0x5f>
mov    %rax,%r14
movb   $0x0,(%rax)
mov    %rbx,%rdi
mov    $0x1ed,%esi
call   1040 <create_dir@plt>
movb   $0x2f,(%r14)
lea    0xe80(%rip),%rsi
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <fopen@plt>
xor    %eax,%eax
jmp    1148 <create_file+0x18>

LLVM IR (-O0):
@.str = [3 x i8] c"w+\00"
define i32* @create_file(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i8*
store i8* %0, i8** %3
store i32 %1, i32* %4
%7 = load i8*, i8** %3
%8 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %8, i32** %5
%9 = load i32*, i32** %5
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %24
11: ; preds = %2
%12 = load i8*, i8** %3
%13 = call i8* @strrchr(i8* %12, i8 signext 47)
store i8* %13, i8** %6
%14 = load i8*, i8** %6
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %23
16: ; preds = %11
%17 = load i8*, i8** %6
store i8 0, i8* %17
%18 = load i8*, i8** %3
%19 = call i32 @create_dir(i8* %18, i32 493)
%20 = load i8*, i8** %6
store i8 47, i8* %20
%21 = load i8*, i8** %3
%22 = call i32* @fopen(i8* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %22, i32** %5
br label %23
23: ; preds = %16, %11
br label %24
24: ; preds = %23, %2
%25 = load i32*, i32** %5
ret i32* %25
}

LLVM IR (-O2):
@.str = [3 x i8] c"w+\00"
define noalias i32* @create_file(i8* %0, i32 %1) {
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %11
5: ; preds = %2
%6 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 47)
%7 = icmp eq i8* %6, null
br i1 %7, label %11, label %8
8: ; preds = %5
store i8 0, i8* %6
%9 = tail call i32 @create_dir(i8* %0, i32 493)
store i8 47, i8* %6
%10 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %5, %8, %2
%12 = phi i32* [ %3, %2 ], [ %10, %8 ], [ null, %5 ]
ret i32* %12
}