#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 stat {
  int dummy;
};

/* Variables and functions */
scalar_t__ ENOENT;
scalar_t__ errno;
scalar_t__ mkdir(char *, int);
scalar_t__ stat(char *, struct stat *);
int /*<<< orphan*/ strcpy(char *, char const *);
char *strrchr(char *, char);
int /*<<< orphan*/ umask(int /*<<< orphan*/);
int make_pathname(const char *pathname) {
  char *p, path[1024];
  struct stat stbuf;
  strcpy(path, pathname);
  p = strrchr(path, '/');
  if (p == NULL)
    return 1;
  *p = 0;
  if (stat(path, &stbuf)) {
    if (errno != ENOENT)
      return 1;
    umask(0);
    if (mkdir(path, 0755))
      return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<make_pathname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x420(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x420(%rbp),%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    119b <make_pathname+0x4b>
movl   $0x1,-0x4(%rbp)
jmp    121f <make_pathname+0xcf>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x420(%rbp),%rdi
lea    -0x428(%rbp),%rsi
call   1070 <stat@plt>
cmp    $0x0,%rax
je     1218 <make_pathname+0xc8>
mov    0x2e1a(%rip),%rax
mov    (%rax),%rax
mov    0x2e00(%rip),%rcx
cmp    (%rcx),%rax
je     11e5 <make_pathname+0x95>
movl   $0x1,-0x4(%rbp)
jmp    121f <make_pathname+0xcf>
xor    %edi,%edi
call   1060 <umask@plt>
lea    -0x420(%rbp),%rdi
mov    $0x1ed,%esi
call   1040 <mkdir@plt>
cmp    $0x0,%rax
je     1213 <make_pathname+0xc3>
movl   $0x1,-0x4(%rbp)
jmp    121f <make_pathname+0xcf>
jmp    1218 <make_pathname+0xc8>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<make_pathname>:
push   %rbx
sub    $0x410,%rsp
mov    %rdi,%rsi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
mov    $0x1,%ebx
test   %rax,%rax
je     11c9 <make_pathname+0x79>
movb   $0x0,(%rax)
lea    0x10(%rsp),%rdi
lea    0x8(%rsp),%rsi
call   1070 <stat@plt>
test   %rax,%rax
je     11c7 <make_pathname+0x77>
mov    0x2e43(%rip),%rax
mov    (%rax),%rax
mov    0x2e29(%rip),%rcx
cmp    (%rcx),%rax
jne    11c9 <make_pathname+0x79>
xor    %edi,%edi
call   1060 <umask@plt>
lea    0x10(%rsp),%rdi
mov    $0x1ed,%esi
call   1040 <mkdir@plt>
test   %rax,%rax
jne    11c9 <make_pathname+0x79>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x410,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@errno = global i64 0
@ENOENT = global i64 0
define i32 @make_pathname(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [1024 x i8]
%6 = alloca %struct.stat
store i8* %0, i8** %3
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%8 = load i8*, i8** %3
%9 = call i32 @strcpy(i8* %7, i8* %8)
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%11 = call i8* @strrchr(i8* %10, i8 signext 47)
store i8* %11, i8** %4
%12 = load i8*, i8** %4
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %15
14: ; preds = %1
store i32 1, i32* %2
br label %33
15: ; preds = %1
%16 = load i8*, i8** %4
store i8 0, i8* %16
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%18 = call i64 @stat(i8* %17, %struct.stat* %6)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %32
20: ; preds = %15
%21 = load i64, i64* @errno
%22 = load i64, i64* @ENOENT
%23 = icmp ne i64 %21, %22
br i1 %23, label %24, label %25
24: ; preds = %20
store i32 1, i32* %2
br label %33
25: ; preds = %20
%26 = call i32 @umask(i32 0)
%27 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%28 = call i64 @mkdir(i8* %27, i32 493)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %25
store i32 1, i32* %2
br label %33
31: ; preds = %25
br label %32
32: ; preds = %31, %15
store i32 0, i32* %2
br label %33
33: ; preds = %32, %30, %24, %14
%34 = load i32, i32* %2
ret i32 %34
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@errno = global i64 0
@ENOENT = global i64 0
define i32 @make_pathname(i8* %0) {
%2 = alloca [1024 x i8]
%3 = alloca %struct.stat
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%5 = bitcast %struct.stat* %3 to i8*
%6 = call i32 @strcpy(i8* %4, i8* %0)
%7 = call i8* @strrchr(i8* %4, i8 signext 47)
%8 = icmp eq i8* %7, null
br i1 %8, label %21, label %9
9: ; preds = %1
store i8 0, i8* %7
%10 = call i64 @stat(i8* %4, %struct.stat* %3)
%11 = icmp eq i64 %10, 0
br i1 %11, label %20, label %12
12: ; preds = %9
%13 = load i64, i64* @errno
%14 = load i64, i64* @ENOENT
%15 = icmp eq i64 %13, %14
br i1 %15, label %16, label %21
16: ; preds = %12
%17 = call i32 @umask(i32 0)
%18 = call i64 @mkdir(i8* %4, i32 493)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %16, %9
br label %21
21: ; preds = %16, %12, %1, %20
%22 = phi i32 [ 0, %20 ], [ 1, %1 ], [ 1, %12 ], [ 1, %16 ]
ret i32 %22
}