#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 */
int S_IRGRP;
int S_IROTH;
int S_IRUSR;
int S_IWUSR;
int S_IXGRP;
int S_IXOTH;
int S_IXUSR;
int /*<<< orphan*/ mkdir(char *, int);
char *strchr(char *, char);
void makedirs(char *path) {
  char *first_slash = path;
  while ((first_slash = strchr(first_slash + 1, '/'))) {
    *first_slash = '\0';
    mkdir(path,
          S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
    *first_slash = '/';
  }
}


x86 assembly (clang, -O0):
<makedirs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
add    $0x1,%rdi
mov    $0x2f,%esi
call   1040 <strchr@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     11af <makedirs+0x8f>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
mov    0x2e4a(%rip),%rax
mov    (%rax),%esi
mov    0x2e69(%rip),%rax
or     (%rax),%esi
mov    0x2e68(%rip),%rax
or     (%rax),%esi
mov    0x2e3f(%rip),%rax
or     (%rax),%esi
mov    0x2e46(%rip),%rax
or     (%rax),%esi
mov    0x2e25(%rip),%rax
or     (%rax),%esi
mov    0x2e4c(%rip),%rax
or     (%rax),%esi
call   1030 <mkdir@plt>
mov    -0x10(%rbp),%rax
movb   $0x2f,(%rax)
jmp    1134 <makedirs+0x14>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<makedirs>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
add    $0x1,%rdi
mov    $0x2f,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11b0 <makedirs+0x90>
mov    %rax,%rbx
mov    0x2e75(%rip),%rbp
mov    0x2e7e(%rip),%r15
mov    0x2e5f(%rip),%r12
mov    0x2e88(%rip),%r13
movb   $0x0,(%rbx)
mov    0x2e6e(%rip),%rax
mov    (%rax),%esi
mov    0x2e3d(%rip),%rax
or     (%rax),%esi
mov    0x2e64(%rip),%rax
or     (%rax),%esi
or     0x0(%rbp),%esi
or     (%r15),%esi
or     (%r12),%esi
or     0x0(%r13),%esi
mov    %r14,%rdi
call   1030 <mkdir@plt>
movb   $0x2f,(%rbx)
add    $0x1,%rbx
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1040 <strchr@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1160 <makedirs+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IXUSR = global i32 0
@S_IRGRP = global i32 0
@S_IXGRP = global i32 0
@S_IROTH = global i32 0
@S_IXOTH = global i32 0
define void @makedirs(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
store i8* %0, i8** %2
%4 = load i8*, i8** %2
store i8* %4, i8** %3
br label %5
5: ; preds = %10, %1
%6 = load i8*, i8** %3
%7 = getelementptr inbounds i8, i8* %6, i64 1
%8 = call i8* @strchr(i8* %7, i8 signext 47)
store i8* %8, i8** %3
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %28
10: ; preds = %5
%11 = load i8*, i8** %3
store i8 0, i8* %11
%12 = load i8*, i8** %2
%13 = load i32, i32* @S_IRUSR
%14 = load i32, i32* @S_IWUSR
%15 = or i32 %13, %14
%16 = load i32, i32* @S_IXUSR
%17 = or i32 %15, %16
%18 = load i32, i32* @S_IRGRP
%19 = or i32 %17, %18
%20 = load i32, i32* @S_IXGRP
%21 = or i32 %19, %20
%22 = load i32, i32* @S_IROTH
%23 = or i32 %21, %22
%24 = load i32, i32* @S_IXOTH
%25 = or i32 %23, %24
%26 = call i32 @mkdir(i8* %12, i32 %25)
%27 = load i8*, i8** %3
store i8 47, i8* %27
br label %5
28: ; preds = %5
ret void
}

LLVM IR (-O2):
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IXUSR = global i32 0
@S_IRGRP = global i32 0
@S_IXGRP = global i32 0
@S_IROTH = global i32 0
@S_IXOTH = global i32 0
define void @makedirs(i8* %0) {
%2 = getelementptr inbounds i8, i8* %0, i64 1
%3 = tail call i8* @strchr(i8* %2, i8 signext 47)
%4 = icmp eq i8* %3, null
br i1 %4, label %24, label %5
5: ; preds = %1, %5
%6 = phi i8* [ %22, %5 ], [ %3, %1 ]
store i8 0, i8* %6
%7 = load i32, i32* @S_IRUSR
%8 = load i32, i32* @S_IWUSR
%9 = or i32 %8, %7
%10 = load i32, i32* @S_IXUSR
%11 = or i32 %9, %10
%12 = load i32, i32* @S_IRGRP
%13 = or i32 %11, %12
%14 = load i32, i32* @S_IXGRP
%15 = or i32 %13, %14
%16 = load i32, i32* @S_IROTH
%17 = or i32 %15, %16
%18 = load i32, i32* @S_IXOTH
%19 = or i32 %17, %18
%20 = tail call i32 @mkdir(i8* %0, i32 %19)
store i8 47, i8* %6
%21 = getelementptr inbounds i8, i8* %6, i64 1
%22 = tail call i8* @strchr(i8* %21, i8 signext 47)
%23 = icmp eq i8* %22, null
br i1 %23, label %24, label %5
24: ; preds = %5, %1
ret void
}