#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 st_mode;
};

/* Variables and functions */
scalar_t__ ENOENT;
scalar_t__ ENOTDIR;
int S_IFDIR;
int S_IFMT;
scalar_t__ errno;
int mkdir(char *, int);
int mkparent(char *);
scalar_t__ stat(char *, struct stat *);
int /*<<< orphan*/ warn(char *, char *);
int makepath(char *pathname) {
  struct stat statbuf;
  int err;
  if (stat(pathname, &statbuf) == 0)
    if ((statbuf.st_mode & S_IFMT) == S_IFDIR)
      return (0);
    else
      errno = ENOTDIR;
  else if (errno == ENOENT) {
    errno = 0;
    if ((err = mkparent(pathname)) != 0)
      return err;
    return mkdir(pathname, 0777);
  }
  warn("Tar: 6: %s", pathname);
  return 1;
}


x86 assembly (clang, -O0):
<makepath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1060 <stat@plt>
cmp    $0x0,%rax
jne    11a3 <makepath+0x63>
mov    -0x18(%rbp),%eax
mov    0x2e6b(%rip),%rcx
and    (%rcx),%eax
mov    0x2e42(%rip),%rcx
cmp    (%rcx),%eax
jne    118a <makepath+0x4a>
movl   $0x0,-0x4(%rbp)
jmp    121d <makepath+0xdd>
mov    0x2e67(%rip),%rax
mov    (%rax),%rcx
mov    0x2e35(%rip),%rax
mov    %rcx,(%rax)
jmp    1206 <makepath+0xc6>
mov    0x2e26(%rip),%rax
mov    (%rax),%rax
mov    0x2e0c(%rip),%rcx
cmp    (%rcx),%rax
jne    1201 <makepath+0xc1>
mov    0x2e0c(%rip),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
call   1050 <mkparent@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
je     11eb <makepath+0xab>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    121d <makepath+0xdd>
mov    -0x10(%rbp),%rdi
mov    $0x1ff,%esi
call   1040 <mkdir@plt>
mov    %eax,-0x4(%rbp)
jmp    121d <makepath+0xdd>
jmp    1206 <makepath+0xc6>
mov    -0x10(%rbp),%rsi
lea    0xdef(%rip),%rdi
call   1030 <warn@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<makepath>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0x8(%rsp),%rsi
call   1060 <stat@plt>
test   %rax,%rax
je     118f <makepath+0x4f>
mov    0x2e72(%rip),%rax
mov    (%rax),%rcx
mov    0x2e58(%rip),%rdx
cmp    (%rdx),%rcx
jne    11bd <makepath+0x7d>
movq   $0x0,(%rax)
mov    %rbx,%rdi
call   1050 <mkparent@plt>
test   %eax,%eax
jne    11d1 <makepath+0x91>
mov    %rbx,%rdi
mov    $0x1ff,%esi
call   1040 <mkdir@plt>
jmp    11d1 <makepath+0x91>
mov    0x2e42(%rip),%rax
mov    (%rax),%ecx
and    0x8(%rsp),%ecx
mov    0x2e15(%rip),%rdx
xor    %eax,%eax
cmp    (%rdx),%ecx
je     11d1 <makepath+0x91>
mov    0x2e48(%rip),%rax
mov    (%rax),%rax
mov    0x2e16(%rip),%rcx
mov    %rax,(%rcx)
lea    0xe3c(%rip),%rdi
mov    %rbx,%rsi
call   1030 <warn@plt>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@S_IFMT = global i32 0
@S_IFDIR = global i32 0
@ENOTDIR = global i64 0
@errno = global i64 0
@ENOENT = global i64 0
@.str = [11 x i8] c"Tar: 6: %s\00"
define i32 @makepath(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca %struct.stat
%5 = alloca i32
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i64 @stat(i8* %6, %struct.stat* %4)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %20
9: ; preds = %1
%10 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%11 = load i32, i32* %10
%12 = load i32, i32* @S_IFMT
%13 = and i32 %11, %12
%14 = load i32, i32* @S_IFDIR
%15 = icmp eq i32 %13, %14
br i1 %15, label %16, label %17
16: ; preds = %9
store i32 0, i32* %2
br label %37
17: ; preds = %9
%18 = load i64, i64* @ENOTDIR
store i64 %18, i64* @errno
br label %19
19: ; preds = %17
br label %34
20: ; preds = %1
%21 = load i64, i64* @errno
%22 = load i64, i64* @ENOENT
%23 = icmp eq i64 %21, %22
br i1 %23, label %24, label %33
24: ; preds = %20
store i64 0, i64* @errno
%25 = load i8*, i8** %3
%26 = call i32 @mkparent(i8* %25)
store i32 %26, i32* %5
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %24
%29 = load i32, i32* %5
store i32 %29, i32* %2
br label %37
30: ; preds = %24
%31 = load i8*, i8** %3
%32 = call i32 @mkdir(i8* %31, i32 511)
store i32 %32, i32* %2
br label %37
33: ; preds = %20
br label %34
34: ; preds = %33, %19
%35 = load i8*, i8** %3
%36 = call i32 @warn(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %35)
store i32 1, i32* %2
br label %37
37: ; preds = %34, %30, %28, %16
%38 = load i32, i32* %2
ret i32 %38
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@S_IFMT = global i32 0
@S_IFDIR = global i32 0
@ENOTDIR = global i64 0
@errno = global i64 0
@ENOENT = global i64 0
@.str = [11 x i8] c"Tar: 6: %s\00"
define i32 @makepath(i8* %0) {
%2 = alloca %struct.stat
%3 = bitcast %struct.stat* %2 to i8*
%4 = call i64 @stat(i8* %0, %struct.stat* %2)
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %15
6: ; preds = %1
%7 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%8 = load i32, i32* %7
%9 = load i32, i32* @S_IFMT
%10 = and i32 %9, %8
%11 = load i32, i32* @S_IFDIR
%12 = icmp eq i32 %10, %11
br i1 %12, label %26, label %13
13: ; preds = %6
%14 = load i64, i64* @ENOTDIR
store i64 %14, i64* @errno
br label %24
15: ; preds = %1
%16 = load i64, i64* @errno
%17 = load i64, i64* @ENOENT
%18 = icmp eq i64 %16, %17
br i1 %18, label %19, label %24
19: ; preds = %15
store i64 0, i64* @errno
%20 = call i32 @mkparent(i8* %0)
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %26
22: ; preds = %19
%23 = call i32 @mkdir(i8* %0, i32 511)
br label %26
24: ; preds = %15, %13
%25 = call i32 @warn(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %26
26: ; preds = %19, %6, %24, %22
%27 = phi i32 [ 1, %24 ], [ %23, %22 ], [ 0, %6 ], [ %20, %19 ]
ret i32 %27
}