#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*/ snprintf(char *, int, char *, char *, char *);
int strfind(char *, char *);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
int /*<<< orphan*/ substr(char *, char *, int, int);
int /*<<< orphan*/ verify_or_make_dir(char *);
char verify_or_make_parent_dirs_for(char *file_path) {
  char path_prefix[1024];
  strncpy(path_prefix, "", 1024);
  char partial_file_path[1024];
  strncpy(partial_file_path, file_path, 1024);
  int first_slash = strfind("/", partial_file_path);
  while (first_slash >= 0) {
    char dir_name[1024];
    substr(dir_name, partial_file_path, 0, first_slash);
    char dir_path[1024];
    snprintf(dir_path, 1024, "%s/%s", path_prefix, dir_name);
    if (!verify_or_make_dir(dir_path)) {
      return 0;
    }
    strncpy(path_prefix, dir_path, 1024);
    char new_file_path[1024];
    substr(new_file_path, partial_file_path, first_slash + 1,
           strlen(partial_file_path) - (first_slash + 1));
    strncpy(partial_file_path, new_file_path, 1024);
    first_slash = strfind("/", partial_file_path);
  }
  return 1;
}


x86 assembly (clang, -O0):
<verify_or_make_parent_dirs_for>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1440,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x410(%rbp),%rdi
lea    0xe84(%rip),%rsi
mov    $0x400,%edx
call   1030 <strncpy@plt>
lea    -0x810(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x400,%edx
call   1030 <strncpy@plt>
lea    -0x810(%rbp),%rsi
lea    0xe56(%rip),%rdi
call   1080 <strfind@plt>
mov    %eax,-0x814(%rbp)
cmpl   $0x0,-0x814(%rbp)
jl     12cc <verify_or_make_parent_dirs_for+0x16c>
lea    -0xc20(%rbp),%rdi
lea    -0x810(%rbp),%rsi
mov    -0x814(%rbp),%ecx
xor    %edx,%edx
call   1050 <substr@plt>
lea    -0x1020(%rbp),%rdi
lea    -0x410(%rbp),%rcx
lea    -0xc20(%rbp),%r8
mov    $0x400,%esi
lea    0xe04(%rip),%rdx
call   1060 <snprintf@plt>
lea    -0x1020(%rbp),%rdi
call   1070 <verify_or_make_dir@plt>
cmp    $0x0,%eax
jne    1221 <verify_or_make_parent_dirs_for+0xc1>
movb   $0x0,-0x1(%rbp)
jmp    12d0 <verify_or_make_parent_dirs_for+0x170>
lea    -0x410(%rbp),%rdi
lea    -0x1020(%rbp),%rsi
mov    $0x400,%edx
call   1030 <strncpy@plt>
lea    -0x1420(%rbp),%rax
mov    %rax,-0x1438(%rbp)
lea    -0x810(%rbp),%rax
mov    %rax,-0x1430(%rbp)
mov    -0x814(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1424(%rbp)
lea    -0x810(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x1438(%rbp),%rdi
mov    -0x1430(%rbp),%rsi
mov    -0x1424(%rbp),%edx
mov    %eax,%ecx
mov    -0x814(%rbp),%eax
add    $0x1,%eax
sub    %eax,%ecx
call   1050 <substr@plt>
lea    -0x810(%rbp),%rdi
lea    -0x1420(%rbp),%rsi
mov    $0x400,%edx
call   1030 <strncpy@plt>
lea    -0x810(%rbp),%rsi
lea    0xd44(%rip),%rdi
call   1080 <strfind@plt>
mov    %eax,-0x814(%rbp)
jmp    11b5 <verify_or_make_parent_dirs_for+0x55>
movb   $0x1,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
add    $0x1440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<verify_or_make_parent_dirs_for>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1408,%rsp
mov    %rdi,%rbx
lea    0xe86(%rip),%rsi
lea    0x400(%rsp),%rdi
mov    $0x400,%edx
call   1030 <strncpy@plt>
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    $0x400,%edx
call   1030 <strncpy@plt>
lea    0xe59(%rip),%rdi
mov    %rbp,%rsi
call   1080 <strfind@plt>
mov    %eax,%r15d
mov    $0x1,%al
test   %r15d,%r15d
js     1275 <verify_or_make_parent_dirs_for+0x115>
lea    0x1000(%rsp),%r12
mov    %rsp,%rbp
lea    0xc00(%rsp),%rbx
lea    0x400(%rsp),%r13
lea    0x800(%rsp),%r14
mov    %r12,%rdi
mov    %rbp,%rsi
xor    %edx,%edx
mov    %r15d,%ecx
call   1050 <substr@plt>
mov    %rbx,%rdi
mov    $0x400,%esi
lea    0xe03(%rip),%rdx
mov    %r13,%rcx
mov    %r12,%r8
call   1060 <snprintf@plt>
mov    %rbx,%rdi
call   1070 <verify_or_make_dir@plt>
test   %eax,%eax
je     1273 <verify_or_make_parent_dirs_for+0x113>
mov    %r13,%rdi
mov    %rbx,%rsi
mov    $0x400,%edx
call   1030 <strncpy@plt>
add    $0x1,%r15d
mov    %rbp,%rdi
call   1040 <strlen@plt>
sub    %r15d,%eax
mov    %r14,%rdi
mov    %rbp,%rsi
mov    %r15d,%edx
mov    %eax,%ecx
call   1050 <substr@plt>
mov    %rbp,%rdi
mov    %r14,%rsi
mov    $0x400,%edx
call   1030 <strncpy@plt>
lea    0xda4(%rip),%rdi
mov    %rbp,%rsi
call   1080 <strfind@plt>
mov    %eax,%r15d
test   %eax,%eax
jns    11e0 <verify_or_make_parent_dirs_for+0x80>
mov    $0x1,%al
jmp    1275 <verify_or_make_parent_dirs_for+0x115>
xor    %eax,%eax
add    $0x1408,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@.str.1 = [2 x i8] c"/\00"
@.str.2 = [6 x i8] c"%s/%s\00"
define signext i8 @verify_or_make_parent_dirs_for(i8* %0) {
%2 = alloca i8
%3 = alloca i8*
%4 = alloca [1024 x i8]
%5 = alloca [1024 x i8]
%6 = alloca i32
%7 = alloca [1024 x i8]
%8 = alloca [1024 x i8]
%9 = alloca [1024 x i8]
store i8* %0, i8** %3
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%11 = call i32 @strncpy(i8* %10, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i32 1024)
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%13 = load i8*, i8** %3
%14 = call i32 @strncpy(i8* %12, i8* %13, i32 1024)
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%16 = call i32 @strfind(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* %15)
store i32 %16, i32* %6
br label %17
17: ; preds = %33, %1
%18 = load i32, i32* %6
%19 = icmp sge i32 %18, 0
br i1 %19, label %20, label %52
20: ; preds = %17
%21 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%23 = load i32, i32* %6
%24 = call i32 @substr(i8* %21, i8* %22, i32 0, i32 %23)
%25 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%26 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%27 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%28 = call i32 @snprintf(i8* %25, i32 1024, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %26, i8* %27)
%29 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%30 = call i32 @verify_or_make_dir(i8* %29)
%31 = icmp ne i32 %30, 0
br i1 %31, label %33, label %32
32: ; preds = %20
store i8 0, i8* %2
br label %53
33: ; preds = %20
%34 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%35 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%36 = call i32 @strncpy(i8* %34, i8* %35, i32 1024)
%37 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%38 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%39 = load i32, i32* %6
%40 = add nsw i32 %39, 1
%41 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%42 = call i32 @strlen(i8* %41)
%43 = load i32, i32* %6
%44 = add nsw i32 %43, 1
%45 = sub nsw i32 %42, %44
%46 = call i32 @substr(i8* %37, i8* %38, i32 %40, i32 %45)
%47 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%48 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%49 = call i32 @strncpy(i8* %47, i8* %48, i32 1024)
%50 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%51 = call i32 @strfind(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* %50)
store i32 %51, i32* %6
br label %17
52: ; preds = %17
store i8 1, i8* %2
br label %53
53: ; preds = %52, %32
%54 = load i8, i8* %2
ret i8 %54
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@.str.1 = [2 x i8] c"/\00"
@.str.2 = [6 x i8] c"%s/%s\00"
define signext i8 @verify_or_make_parent_dirs_for(i8* %0) {
%2 = alloca [1024 x i8]
%3 = alloca [1024 x i8]
%4 = alloca [1024 x i8]
%5 = alloca [1024 x i8]
%6 = alloca [1024 x i8]
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%8 = call i32 @strncpy(i8* %7, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i32 1024)
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%10 = call i32 @strncpy(i8* %9, i8* %0, i32 1024)
%11 = call i32 @strfind(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* %9)
%12 = icmp sgt i32 %11, -1
br i1 %12, label %13, label %33
13: ; preds = %1
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%16 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
br label %17
17: ; preds = %13, %24
%18 = phi i32 [ %11, %13 ], [ %31, %24 ]
%19 = call i32 @substr(i8* %14, i8* %9, i32 0, i32 %18)
%20 = call i32 @snprintf(i8* %15, i32 1024, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %7, i8* %14)
%21 = call i32 @verify_or_make_dir(i8* %15)
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %17
br label %33
24: ; preds = %17
%25 = call i32 @strncpy(i8* %7, i8* %15, i32 1024)
%26 = add nuw nsw i32 %18, 1
%27 = call i32 @strlen(i8* %9)
%28 = sub nsw i32 %27, %26
%29 = call i32 @substr(i8* %16, i8* %9, i32 %26, i32 %28)
%30 = call i32 @strncpy(i8* %9, i8* %16, i32 1024)
%31 = call i32 @strfind(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* %9)
%32 = icmp sgt i32 %31, -1
br i1 %32, label %17, label %33
33: ; preds = %24, %1, %23
%34 = phi i8 [ 0, %23 ], [ 1, %1 ], [ 1, %24 ]
ret i8 %34
}