#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 */
scalar_t__ EEXIST;
char *adb_dirstart(char *);
int adb_mkdir(char *, int);
scalar_t__ errno;
int mkdirs(char *path) {
  int ret;
  char *x = path + 1;
  for (;;) {
    x = adb_dirstart(x);
    if (x == 0)
      return 0;
    *x = 0;
    ret = adb_mkdir(path, 0775);
    *x = '/';
    if ((ret < 0) && (errno != EEXIST)) {
      return ret;
    }
    x++;
  }
  return 0;
}


x86 assembly (clang, -O0):
<mkdirs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <adb_dirstart@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    115c <mkdirs+0x3c>
movl   $0x0,-0x4(%rbp)
jmp    11bb <mkdirs+0x9b>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
mov    $0x1fd,%esi
call   1040 <adb_mkdir@plt>
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%rax
movb   $0x2f,(%rax)
cmpl   $0x0,-0x14(%rbp)
jge    11aa <mkdirs+0x8a>
mov    0x2e4c(%rip),%rax
mov    (%rax),%rax
mov    0x2e4a(%rip),%rcx
cmp    (%rcx),%rax
je     11aa <mkdirs+0x8a>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11bb <mkdirs+0x9b>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1138 <mkdirs+0x18>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mkdirs>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%rbx
add    $0x1,%rdi
call   1030 <adb_dirstart@plt>
xor    %r14d,%r14d
test   %rax,%rax
je     1189 <mkdirs+0x69>
mov    %rax,%rbp
mov    0x2e92(%rip),%r15
mov    0x2e93(%rip),%r12
jmp    1164 <mkdirs+0x44>
nop
add    $0x1,%rbp
mov    %rbp,%rdi
call   1030 <adb_dirstart@plt>
mov    %rax,%rbp
test   %rax,%rax
je     1189 <mkdirs+0x69>
movb   $0x0,0x0(%rbp)
mov    %rbx,%rdi
mov    $0x1fd,%esi
call   1040 <adb_mkdir@plt>
movb   $0x2f,0x0(%rbp)
test   %eax,%eax
jns    1150 <mkdirs+0x30>
mov    (%r15),%rcx
cmp    (%r12),%rcx
je     1150 <mkdirs+0x30>
mov    %eax,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i64 0
@EEXIST = global i64 0
define i32 @mkdirs(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = getelementptr inbounds i8, i8* %6, i64 1
store i8* %7, i8** %5
br label %8
8: ; preds = %27, %1
%9 = load i8*, i8** %5
%10 = call i8* @adb_dirstart(i8* %9)
store i8* %10, i8** %5
%11 = load i8*, i8** %5
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %14
13: ; preds = %8
store i32 0, i32* %2
br label %30
14: ; preds = %8
%15 = load i8*, i8** %5
store i8 0, i8* %15
%16 = load i8*, i8** %3
%17 = call i32 @adb_mkdir(i8* %16, i32 509)
store i32 %17, i32* %4
%18 = load i8*, i8** %5
store i8 47, i8* %18
%19 = load i32, i32* %4
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %27
21: ; preds = %14
%22 = load i64, i64* @errno
%23 = load i64, i64* @EEXIST
%24 = icmp ne i64 %22, %23
br i1 %24, label %25, label %27
25: ; preds = %21
%26 = load i32, i32* %4
store i32 %26, i32* %2
br label %30
27: ; preds = %21, %14
%28 = load i8*, i8** %5
%29 = getelementptr inbounds i8, i8* %28, i32 1
store i8* %29, i8** %5
br label %8
30: ; preds = %25, %13
%31 = load i32, i32* %2
ret i32 %31
}

LLVM IR (-O2):
@errno = global i64 0
@EEXIST = global i64 0
define i32 @mkdirs(i8* %0) {
%2 = getelementptr inbounds i8, i8* %0, i64 1
%3 = tail call i8* @adb_dirstart(i8* %2)
%4 = icmp eq i8* %3, null
br i1 %4, label %17, label %5
5: ; preds = %1, %13
%6 = phi i8* [ %15, %13 ], [ %3, %1 ]
store i8 0, i8* %6
%7 = tail call i32 @adb_mkdir(i8* %0, i32 509)
store i8 47, i8* %6
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %5
%10 = load i64, i64* @errno
%11 = load i64, i64* @EEXIST
%12 = icmp eq i64 %10, %11
br i1 %12, label %13, label %17
13: ; preds = %9, %5
%14 = getelementptr inbounds i8, i8* %6, i64 1
%15 = tail call i8* @adb_dirstart(i8* %14)
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %5
17: ; preds = %13, %9, %1
%18 = phi i32 [ 0, %1 ], [ %7, %9 ], [ 0, %13 ]
ret i32 %18
}