#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 scalar_t__ uint64_t;

/* 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*/ free(char *);
char *get_dir(char *, scalar_t__, int *);
int /*<<< orphan*/ mkdir(char *, int);
int mkdirp(char *dir) {
  uint64_t i;
  int fin = 0;
  char *r_dir;
  for (i = 0; fin != 1; i++) {
    r_dir = get_dir(dir, i, &fin);
    mkdir(r_dir,
          S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
    free(r_dir);
  }
  return 0;
}


x86 assembly (clang, -O0):
<mkdirp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x14(%rbp)
movq   $0x0,-0x10(%rbp)
cmpl   $0x1,-0x14(%rbp)
je     11cc <mkdirp+0x9c>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    -0x14(%rbp),%rdx
call   1040 <get_dir@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    0x2e3b(%rip),%rax
mov    (%rax),%esi
mov    0x2e5a(%rip),%rax
or     (%rax),%esi
mov    0x2e59(%rip),%rax
or     (%rax),%esi
mov    0x2e30(%rip),%rax
or     (%rax),%esi
mov    0x2e37(%rip),%rax
or     (%rax),%esi
mov    0x2e16(%rip),%rax
or     (%rax),%esi
mov    0x2e3d(%rip),%rax
or     (%rax),%esi
call   1050 <mkdir@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    114b <mkdirp+0x1b>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mkdirp>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
movl   $0x0,0x4(%rsp)
xor    %ebx,%ebx
mov    0x2e81(%rip),%rbp
mov    0x2e62(%rip),%r15
mov    0x2e8b(%rip),%r13
nopl   (%rax)
mov    %r14,%rdi
mov    %rbx,%rsi
lea    0x4(%rsp),%rdx
call   1040 <get_dir@plt>
mov    %rax,%r12
mov    0x2e5e(%rip),%rax
mov    (%rax),%esi
mov    0x2e2d(%rip),%rax
or     (%rax),%esi
mov    0x2e54(%rip),%rax
or     (%rax),%esi
mov    0x2e2b(%rip),%rax
or     (%rax),%esi
or     0x0(%rbp),%esi
or     (%r15),%esi
or     0x0(%r13),%esi
mov    %r12,%rdi
call   1050 <mkdir@plt>
mov    %r12,%rdi
call   1030 <free@plt>
add    $0x1,%rbx
cmpl   $0x1,0x4(%rsp)
jne    1160 <mkdirp+0x30>
xor    %eax,%eax
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 i32 @mkdirp(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i32
%5 = alloca i8*
store i8* %0, i8** %2
store i32 0, i32* %4
store i64 0, i64* %3
br label %6
6: ; preds = %30, %1
%7 = load i32, i32* %4
%8 = icmp ne i32 %7, 1
br i1 %8, label %9, label %33
9: ; preds = %6
%10 = load i8*, i8** %2
%11 = load i64, i64* %3
%12 = call i8* @get_dir(i8* %10, i64 %11, i32* %4)
store i8* %12, i8** %5
%13 = load i8*, i8** %5
%14 = load i32, i32* @S_IRUSR
%15 = load i32, i32* @S_IWUSR
%16 = or i32 %14, %15
%17 = load i32, i32* @S_IXUSR
%18 = or i32 %16, %17
%19 = load i32, i32* @S_IRGRP
%20 = or i32 %18, %19
%21 = load i32, i32* @S_IXGRP
%22 = or i32 %20, %21
%23 = load i32, i32* @S_IROTH
%24 = or i32 %22, %23
%25 = load i32, i32* @S_IXOTH
%26 = or i32 %24, %25
%27 = call i32 @mkdir(i8* %13, i32 %26)
%28 = load i8*, i8** %5
%29 = call i32 @free(i8* %28)
br label %30
30: ; preds = %9
%31 = load i64, i64* %3
%32 = add nsw i64 %31, 1
store i64 %32, i64* %3
br label %6
33: ; preds = %6
ret i32 0
}

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 i32 @mkdirp(i8* %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
store i32 0, i32* %2
br label %4
4: ; preds = %1, %4
%5 = phi i64 [ 0, %1 ], [ %22, %4 ]
%6 = call i8* @get_dir(i8* %0, i64 %5, i32* %2)
%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 = call i32 @mkdir(i8* %6, i32 %19)
%21 = call i32 @free(i8* %6)
%22 = add nuw nsw i64 %5, 1
%23 = load i32, i32* %2
%24 = icmp eq i32 %23, 1
br i1 %24, label %25, label %4
25: ; preds = %4
ret i32 0
}