#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 /*<<< orphan*/ abort();
char *realloc(char *, scalar_t__);
scalar_t__ strlen(char const *);
char *ensure_directories_exist(void (*fun)(void *a, const char *d), void *a,
                               const char *fn, int pathsep) {
  static char *q = NULL;
  int i;
  q = realloc(q, strlen(fn) + 8);
  if (!q)
    abort();
  for (i = 0; fn[i]; i++) {
    if (fn[i] == '\\') {
      q[i] = '\0';
      fun(a, q);
      q[i] = pathsep;
    } else {
      q[i] = fn[i];
    }
  }
  q[i] = '\0';
  return q;
}


x86 assembly (clang, -O0):
<ensure_directories_exist>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    0x2ef2(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x28(%rbp),%rdi
mov    %rax,%rsi
add    $0x8,%rsi
call   1050 <realloc@plt>
mov    %rax,0x2ece(%rip)
cmpq   $0x0,0x2ec6(%rip)
jne    1187 <ensure_directories_exist+0x57>
mov    $0x0,%al
call   1030 <abort@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
cmpb   $0x0,(%rax,%rcx,1)
je     1219 <ensure_directories_exist+0xe9>
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x5c,%eax
jne    11ed <ensure_directories_exist+0xbd>
mov    0x2e84(%rip),%rax
movslq -0x20(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rdi
mov    0x2e6d(%rip),%rsi
call   *%rax
mov    -0x1c(%rbp),%eax
mov    %al,%dl
mov    0x2e5f(%rip),%rax
movslq -0x20(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
jmp    1206 <ensure_directories_exist+0xd6>
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    0x2e41(%rip),%rax
movslq -0x20(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
jmp    120b <ensure_directories_exist+0xdb>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    118e <ensure_directories_exist+0x5e>
mov    0x2e20(%rip),%rax
movslq -0x20(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    0x2e11(%rip),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ensure_directories_exist>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r14d
mov    %rdx,%rbx
mov    %rsi,%r15
mov    %rdi,%r13
mov    0x2ef2(%rip),%r12
mov    %rdx,%rdi
call   1040 <strlen@plt>
lea    0x8(%rax),%rsi
mov    %r12,%rdi
call   1050 <realloc@plt>
mov    %rax,0x2ed7(%rip)
test   %rax,%rax
je     11bf <ensure_directories_exist+0x8f>
mov    %rax,%rsi
xor    %ebp,%ebp
jmp    119b <ensure_directories_exist+0x6b>
cs nopw 0x0(%rax,%rax,1)
nop
movb   $0x0,(%rsi,%rbp,1)
mov    %r15,%rdi
call   *%r13
mov    0x2eaf(%rip),%rsi
mov    %r14d,%eax
mov    %al,(%rsi,%rbp,1)
add    $0x1,%rbp
movzbl (%rbx,%rbp,1),%eax
cmp    $0x5c,%al
je     1180 <ensure_directories_exist+0x50>
test   %al,%al
jne    1194 <ensure_directories_exist+0x64>
mov    %ebp,%eax
movb   $0x0,(%rsi,%rax,1)
mov    %rsi,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
@ensure_directories_exist.q = internal global i8* null
define i8* @ensure_directories_exist(void (i8*, i8*)* %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca void (i8*, i8*)*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
store void (i8*, i8*)* %0, void (i8*, i8*)** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%10 = load i8*, i8** @ensure_directories_exist.q
%11 = load i8*, i8** %7
%12 = call i64 @strlen(i8* %11)
%13 = add nsw i64 %12, 8
%14 = call i8* @realloc(i8* %10, i64 %13)
store i8* %14, i8** @ensure_directories_exist.q
%15 = load i8*, i8** @ensure_directories_exist.q
%16 = icmp ne i8* %15, null
br i1 %16, label %19, label %17
17: ; preds = %4
%18 = call i32 (...) @abort()
unreachable
19: ; preds = %4
store i32 0, i32* %9
br label %20
20: ; preds = %60, %19
%21 = load i8*, i8** %7
%22 = load i32, i32* %9
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
%25 = load i8, i8* %24
%26 = icmp ne i8 %25, 0
br i1 %26, label %27, label %63
27: ; preds = %20
%28 = load i8*, i8** %7
%29 = load i32, i32* %9
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %28, i64 %30
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp eq i32 %33, 92
br i1 %34, label %35, label %49
35: ; preds = %27
%36 = load i8*, i8** @ensure_directories_exist.q
%37 = load i32, i32* %9
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %36, i64 %38
store i8 0, i8* %39
%40 = load void (i8*, i8*)*, void (i8*, i8*)** %5
%41 = load i8*, i8** %6
%42 = load i8*, i8** @ensure_directories_exist.q
%43 = load i32, i32* %8
%44 = trunc i32 %43 to i8
%45 = load i8*, i8** @ensure_directories_exist.q
%46 = load i32, i32* %9
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8, i8* %45, i64 %47
store i8 %44, i8* %48
br label %59
49: ; preds = %27
%50 = load i8*, i8** %7
%51 = load i32, i32* %9
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i8, i8* %50, i64 %52
%54 = load i8, i8* %53
%55 = load i8*, i8** @ensure_directories_exist.q
%56 = load i32, i32* %9
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i8, i8* %55, i64 %57
store i8 %54, i8* %58
br label %59
59: ; preds = %49, %35
br label %60
60: ; preds = %59
%61 = load i32, i32* %9
%62 = add nsw i32 %61, 1
store i32 %62, i32* %9
br label %20
63: ; preds = %20
%64 = load i8*, i8** @ensure_directories_exist.q
%65 = load i32, i32* %9
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds i8, i8* %64, i64 %66
store i8 0, i8* %67
%68 = load i8*, i8** @ensure_directories_exist.q
ret i8* %68
}

LLVM IR (-O2):
@ensure_directories_exist.q = internal unnamed_addr global i8* null
define i8* @ensure_directories_exist(void (i8*, i8*)* nocapture %0, i8* %1, i8* nocapture %2, i32 %3) {
%5 = load i8*, i8** @ensure_directories_exist.q
%6 = tail call i64 @strlen(i8* dereferenceable(1) %2)
%7 = add nsw i64 %6, 8
%8 = tail call i8* @realloc(i8* %5, i64 %7)
store i8* %8, i8** @ensure_directories_exist.q
%9 = icmp eq i8* %8, null
br i1 %9, label %12, label %10
10: ; preds = %4
%11 = trunc i32 %3 to i8
br label %14
12: ; preds = %4
%13 = tail call i32 (...) @abort()
unreachable
14: ; preds = %10, %22
%15 = phi i8* [ %8, %10 ], [ %23, %22 ]
%16 = phi i64 [ 0, %10 ], [ %26, %22 ]
%17 = getelementptr inbounds i8, i8* %2, i64 %16
%18 = load i8, i8* %17
switch i8 %18, label %22 [
i8 0, label %27
i8 92, label %19
]
19: ; preds = %14
%20 = getelementptr inbounds i8, i8* %15, i64 %16
store i8 0, i8* %20
tail call void %0(i8* %1, i8* %15)
%21 = load i8*, i8** @ensure_directories_exist.q
br label %22
22: ; preds = %14, %19
%23 = phi i8* [ %21, %19 ], [ %15, %14 ]
%24 = phi i8 [ %11, %19 ], [ %18, %14 ]
%25 = getelementptr inbounds i8, i8* %23, i64 %16
store i8 %24, i8* %25
%26 = add nuw i64 %16, 1
br label %14
27: ; preds = %14
%28 = and i64 %16, 4294967295
%29 = getelementptr inbounds i8, i8* %15, i64 %28
store i8 0, i8* %29
ret i8* %15
}