#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 const *);
int strlen(char const *);
int mkpath(char *out, char *dirname, const char *fname, const char div,
           size_t mxl) {
  int arlen = strlen(dirname);
  if (arlen + strlen(fname) + 2 > mxl)
    return 1;
  if (dirname[(arlen - 1)] != div) {
    dirname[(arlen)] = div;
    dirname[(arlen + 1)] = '\0';
  }
  snprintf(out, 128, "%s%s", dirname, fname);
  return 0;
}


x86 assembly (clang, -O0):
<mkpath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %cl,%al
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %al,-0x21(%rbp)
mov    %r8,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x38(%rbp),%eax
add    %ecx,%eax
add    $0x2,%eax
cltq
cmp    -0x30(%rbp),%rax
jbe    117a <mkpath+0x5a>
movl   $0x1,-0x4(%rbp)
jmp    11da <mkpath+0xba>
mov    -0x18(%rbp),%rax
mov    -0x34(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
movsbl -0x21(%rbp),%ecx
cmp    %ecx,%eax
je     11b6 <mkpath+0x96>
mov    -0x21(%rbp),%dl
mov    -0x18(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
mov    -0x34(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%r8
mov    $0x80,%esi
lea    0xe32(%rip),%rdx
call   1040 <snprintf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mkpath>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8,%r13
mov    %ecx,%r12d
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r15
mov    %rsi,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1030 <strlen@plt>
add    %ebp,%eax
add    $0x2,%eax
movslq %eax,%rcx
mov    $0x1,%eax
cmp    %r13,%rcx
ja     118d <mkpath+0x6d>
movslq %ebp,%rax
cmp    %r12b,-0x1(%rax,%rbx,1)
je     1171 <mkpath+0x51>
mov    %r12b,(%rbx,%rax,1)
movb   $0x0,0x1(%rbx,%rax,1)
lea    0xe88(%rip),%rdx
mov    %r15,%rdi
mov    $0x80,%esi
mov    %rbx,%rcx
mov    %r14,%r8
call   1040 <snprintf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [5 x i8] c"%s%s\00"
define i32 @mkpath(i8* %0, i8* %1, i8* %2, i8 signext %3, i64 %4) {
%6 = tail call i32 @strlen(i8* %1)
%7 = tail call i32 @strlen(i8* %2)
%8 = add i32 %6, 2
%9 = add i32 %8, %7
%10 = sext i32 %9 to i64
%11 = icmp ugt i64 %10, %4
br i1 %11, label %26, label %12
12: ; preds = %5
%13 = add nsw i32 %6, -1
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %1, i64 %14
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, %3
br i1 %17, label %24, label %18
18: ; preds = %12
%19 = sext i32 %6 to i64
%20 = getelementptr inbounds i8, i8* %1, i64 %19
store i8 %3, i8* %20
%21 = add nsw i32 %6, 1
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %1, i64 %22
store i8 0, i8* %23
br label %24
24: ; preds = %18, %12
%25 = tail call i32 @snprintf(i8* %0, i32 128, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %1, i8* %2)
br label %26
26: ; preds = %5, %24
%27 = phi i32 [ 0, %24 ], [ 1, %5 ]
ret i32 %27
}