#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*/ F_OK;
scalar_t__ access(char *, int /*<<< orphan*/);
int /*<<< orphan*/ isns_assert_failed(char *, char *, int);
scalar_t__ mkdir(char *, int);
scalar_t__ strcmp(char const *, char *);
char *strdup(char const *);
unsigned int strlen(char const *);
char *strrchr(char *, char);
int __dbe_mkdir_path(const char *dirname) {
  unsigned int true_len = strlen(dirname);
  char *copy, *s;
  copy = strdup(dirname);
  while (1) {
    s = strrchr(copy, '/');
    if (s == NULL)
      break;
    *s = '\0';
    if (access(copy, F_OK) == 0)
      break;
  }
  while (strcmp(dirname, copy)) {
    unsigned int len = strlen(copy);
    do {
      if (!(len < true_len))
        isns_assert_failed("len < true_len",
                           "/scratch/repos/new/home/jordi_armengol_estape/"
                           "c-scraper/outputs/2022-01-22/02-19-57/repos/"
                           "Akasurde/open-iscsi/refs/heads/master/db-file.c",
                           133);
    } while (0);
    copy[len] = '/';
    if (mkdir(copy, 0700) < 0)
      return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<__dbe_mkdir_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1090 <strdup@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11b7 <__dbe_mkdir_path+0x47>
jmp    11e4 <__dbe_mkdir_path+0x74>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rdi
mov    0x2e0f(%rip),%rax
mov    (%rax),%esi
call   1070 <access@plt>
cmp    $0x0,%rax
jne    11df <__dbe_mkdir_path+0x6f>
jmp    11e4 <__dbe_mkdir_path+0x74>
jmp    1195 <__dbe_mkdir_path+0x25>
jmp    11e9 <__dbe_mkdir_path+0x79>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     1269 <__dbe_mkdir_path+0xf9>
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jb     1230 <__dbe_mkdir_path+0xc0>
lea    0xde1(%rip),%rdi
lea    0xde9(%rip),%rsi
mov    $0x85,%edx
call   1080 <isns_assert_failed@plt>
jmp    1235 <__dbe_mkdir_path+0xc5>
mov    -0x20(%rbp),%rax
mov    -0x2c(%rbp),%ecx
movb   $0x2f,(%rax,%rcx,1)
mov    -0x20(%rbp),%rdi
mov    $0x1c0,%esi
call   1030 <mkdir@plt>
cmp    $0x0,%rax
jge    1264 <__dbe_mkdir_path+0xf4>
movl   $0xffffffff,-0x4(%rbp)
jmp    1270 <__dbe_mkdir_path+0x100>
jmp    11e9 <__dbe_mkdir_path+0x79>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__dbe_mkdir_path>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r13
call   1040 <strlen@plt>
mov    %eax,%r14d
mov    %r13,%rdi
call   1090 <strdup@plt>
mov    %rax,%rbp
mov    0x2e40(%rip),%rbx
nopl   0x0(%rax,%rax,1)
mov    %rbp,%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
test   %rax,%rax
je     11c4 <__dbe_mkdir_path+0x54>
movb   $0x0,(%rax)
mov    (%rbx),%esi
mov    %rbp,%rdi
call   1070 <access@plt>
test   %rax,%rax
jne    11a0 <__dbe_mkdir_path+0x30>
lea    0xe35(%rip),%r15
lea    0xe3d(%rip),%r12
jmp    11f9 <__dbe_mkdir_path+0x89>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %ebx,%eax
movb   $0x2f,0x0(%rbp,%rax,1)
mov    %rbp,%rdi
mov    $0x1c0,%esi
call   1030 <mkdir@plt>
test   %rax,%rax
js     122a <__dbe_mkdir_path+0xba>
mov    %r13,%rdi
mov    %rbp,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     1231 <__dbe_mkdir_path+0xc1>
mov    %rbp,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebx
cmp    %r14d,%eax
jb     11e0 <__dbe_mkdir_path+0x70>
mov    %r15,%rdi
mov    %r12,%rsi
mov    $0x85,%edx
call   1080 <isns_assert_failed@plt>
jmp    11e0 <__dbe_mkdir_path+0x70>
mov    $0xffffffff,%eax
jmp    1233 <__dbe_mkdir_path+0xc3>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@F_OK = global i32 0
@.str = [15 x i8] c"len < true_len\00"
@.str.1 = [138 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/Akasurde/open-iscsi/refs/heads/master/db-file.c\00"
define i32 @__dbe_mkdir_path(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %3
%8 = load i8*, i8** %3
%9 = call i32 @strlen(i8* %8)
store i32 %9, i32* %4
%10 = load i8*, i8** %3
%11 = call i8* @strdup(i8* %10)
store i8* %11, i8** %5
br label %12
12: ; preds = %1, %25
%13 = load i8*, i8** %5
%14 = call i8* @strrchr(i8* %13, i8 signext 47)
store i8* %14, i8** %6
%15 = load i8*, i8** %6
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %18
17: ; preds = %12
br label %26
18: ; preds = %12
%19 = load i8*, i8** %6
store i8 0, i8* %19
%20 = load i8*, i8** %5
%21 = load i32, i32* @F_OK
%22 = call i64 @access(i8* %20, i32 %21)
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %18
br label %26
25: ; preds = %18
br label %12
26: ; preds = %24, %17
br label %27
27: ; preds = %51, %26
%28 = load i8*, i8** %3
%29 = load i8*, i8** %5
%30 = call i64 @strcmp(i8* %28, i8* %29)
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %52
32: ; preds = %27
%33 = load i8*, i8** %5
%34 = call i32 @strlen(i8* %33)
store i32 %34, i32* %7
br label %35
35: ; preds = %32
%36 = load i32, i32* %7
%37 = load i32, i32* %4
%38 = icmp ult i32 %36, %37
br i1 %38, label %41, label %39
39: ; preds = %35
%40 = call i32 @isns_assert_failed(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str.1, i64 0, i64 0), i32 133)
br label %41
41: ; preds = %39, %35
br label %42
42: ; preds = %41
%43 = load i8*, i8** %5
%44 = load i32, i32* %7
%45 = zext i32 %44 to i64
%46 = getelementptr inbounds i8, i8* %43, i64 %45
store i8 47, i8* %46
%47 = load i8*, i8** %5
%48 = call i64 @mkdir(i8* %47, i32 448)
%49 = icmp slt i64 %48, 0
br i1 %49, label %50, label %51
50: ; preds = %42
store i32 -1, i32* %2
br label %53
51: ; preds = %42
br label %27
52: ; preds = %27
store i32 0, i32* %2
br label %53
53: ; preds = %52, %50
%54 = load i32, i32* %2
ret i32 %54
}

LLVM IR (-O2):
@F_OK = global i32 0
@.str = [15 x i8] c"len < true_len\00"
@.str.1 = [138 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/Akasurde/open-iscsi/refs/heads/master/db-file.c\00"
define i32 @__dbe_mkdir_path(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = tail call i8* @strdup(i8* %0)
br label %4
4: ; preds = %7, %1
%5 = tail call i8* @strrchr(i8* dereferenceable(1) %3, i8 signext 47)
%6 = icmp eq i8* %5, null
br i1 %6, label %11, label %7
7: ; preds = %4
store i8 0, i8* %5
%8 = load i32, i32* @F_OK
%9 = tail call i64 @access(i8* %3, i32 %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %4
11: ; preds = %7, %4
br label %12
12: ; preds = %11, %20
%13 = tail call i64 @strcmp(i8* %0, i8* %3)
%14 = icmp eq i64 %13, 0
br i1 %14, label %25, label %15
15: ; preds = %12
%16 = tail call i32 @strlen(i8* %3)
%17 = icmp ult i32 %16, %2
br i1 %17, label %20, label %18
18: ; preds = %15
%19 = tail call i32 @isns_assert_failed(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str.1, i64 0, i64 0), i32 133)
br label %20
20: ; preds = %18, %15
%21 = zext i32 %16 to i64
%22 = getelementptr inbounds i8, i8* %3, i64 %21
store i8 47, i8* %22
%23 = tail call i64 @mkdir(i8* %3, i32 448)
%24 = icmp slt i64 %23, 0
br i1 %24, label %25, label %12
25: ; preds = %12, %20
%26 = phi i32 [ -1, %20 ], [ 0, %12 ]
ret i32 %26
}