#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 */
char *dos_unix_name(char const *, char const *, int);
int /*<<< orphan*/ free(char *);
char *get_last_separator(char const *);
char *strdup(char const *);
char *strndup(char const *, int);
char *dos_unix_path_rec(const char *upath, const char *dospath, int force) {
  const char *p = get_last_separator(dospath);
  if (!p) {
    return dos_unix_name(upath, dospath, force);
  }
  char *part1 = strndup(dospath, p - dospath);
  char *part2 = strdup(p + 1);
  char *path = dos_unix_path_rec(upath, part1, force);
  char *ret = 0;
  if (path) {
    ret = dos_unix_name(path, part2, force);
    free(path);
  }
  free(part1);
  free(part2);
  return ret;
}


x86 assembly (clang, -O0):
<dos_unix_path_rec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <get_last_separator@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11a4 <dos_unix_path_rec+0x44>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1070 <dos_unix_name@plt>
mov    %rax,-0x8(%rbp)
jmp    122d <dos_unix_path_rec+0xcd>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%esi
call   1050 <strndup@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
add    $0x1,%rdi
call   1080 <strdup@plt>
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1060 <dos_unix_path_rec@plt>
mov    %rax,-0x40(%rbp)
movq   $0x0,-0x48(%rbp)
cmpq   $0x0,-0x40(%rbp)
je     1213 <dos_unix_path_rec+0xb3>
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1070 <dos_unix_name@plt>
mov    %rax,-0x48(%rbp)
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x48(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dos_unix_path_rec>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r12d
mov    %rsi,%rbx
mov    %rdi,%r13
mov    %rsi,%rdi
call   1040 <get_last_separator@plt>
test   %rax,%rax
je     11d3 <dos_unix_path_rec+0x73>
mov    %rax,%rbp
mov    %ebp,%esi
sub    %ebx,%esi
mov    %rbx,%rdi
call   1050 <strndup@plt>
mov    %rax,%r14
add    $0x1,%rbp
mov    %rbp,%rdi
call   1080 <strdup@plt>
mov    %rax,%r15
mov    %r13,%rdi
mov    %r14,%rsi
mov    %r12d,%edx
call   1060 <dos_unix_path_rec@plt>
test   %rax,%rax
je     11ef <dos_unix_path_rec+0x8f>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %r15,%rsi
mov    %r12d,%edx
call   1070 <dos_unix_name@plt>
mov    %rax,%rbx
mov    %rbp,%rdi
call   1030 <free@plt>
jmp    11f1 <dos_unix_path_rec+0x91>
mov    %r13,%rdi
mov    %rbx,%rsi
mov    %r12d,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <dos_unix_name@plt>
xor    %ebx,%ebx
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @dos_unix_path_rec(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%13 = load i8*, i8** %6
%14 = call i8* @get_last_separator(i8* %13)
store i8* %14, i8** %8
%15 = load i8*, i8** %8
%16 = icmp ne i8* %15, null
br i1 %16, label %22, label %17
17: ; preds = %3
%18 = load i8*, i8** %5
%19 = load i8*, i8** %6
%20 = load i32, i32* %7
%21 = call i8* @dos_unix_name(i8* %18, i8* %19, i32 %20)
store i8* %21, i8** %4
br label %53
22: ; preds = %3
%23 = load i8*, i8** %6
%24 = load i8*, i8** %8
%25 = load i8*, i8** %6
%26 = ptrtoint i8* %24 to i64
%27 = ptrtoint i8* %25 to i64
%28 = sub i64 %26, %27
%29 = trunc i64 %28 to i32
%30 = call i8* @strndup(i8* %23, i32 %29)
store i8* %30, i8** %9
%31 = load i8*, i8** %8
%32 = getelementptr inbounds i8, i8* %31, i64 1
%33 = call i8* @strdup(i8* %32)
store i8* %33, i8** %10
%34 = load i8*, i8** %5
%35 = load i8*, i8** %9
%36 = load i32, i32* %7
%37 = call i8* @dos_unix_path_rec(i8* %34, i8* %35, i32 %36)
store i8* %37, i8** %11
store i8* null, i8** %12
%38 = load i8*, i8** %11
%39 = icmp ne i8* %38, null
br i1 %39, label %40, label %47
40: ; preds = %22
%41 = load i8*, i8** %11
%42 = load i8*, i8** %10
%43 = load i32, i32* %7
%44 = call i8* @dos_unix_name(i8* %41, i8* %42, i32 %43)
store i8* %44, i8** %12
%45 = load i8*, i8** %11
%46 = call i32 @free(i8* %45)
br label %47
47: ; preds = %40, %22
%48 = load i8*, i8** %9
%49 = call i32 @free(i8* %48)
%50 = load i8*, i8** %10
%51 = call i32 @free(i8* %50)
%52 = load i8*, i8** %12
store i8* %52, i8** %4
br label %53
53: ; preds = %47, %17
%54 = load i8*, i8** %4
ret i8* %54
}

LLVM IR (-O2):
define i8* @dos_unix_path_rec(i8* %0, i8* %1, i32 %2) {
%4 = tail call i8* @get_last_separator(i8* %1)
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %8
6: ; preds = %3
%7 = tail call i8* @dos_unix_name(i8* %0, i8* %1, i32 %2)
br label %25
8: ; preds = %3
%9 = ptrtoint i8* %4 to i64
%10 = ptrtoint i8* %1 to i64
%11 = sub i64 %9, %10
%12 = trunc i64 %11 to i32
%13 = tail call i8* @strndup(i8* %1, i32 %12)
%14 = getelementptr inbounds i8, i8* %4, i64 1
%15 = tail call i8* @strdup(i8* %14)
%16 = tail call i8* @dos_unix_path_rec(i8* %0, i8* %13, i32 %2)
%17 = icmp eq i8* %16, null
br i1 %17, label %21, label %18
18: ; preds = %8
%19 = tail call i8* @dos_unix_name(i8* %16, i8* %15, i32 %2)
%20 = tail call i32 @free(i8* %16)
br label %21
21: ; preds = %18, %8
%22 = phi i8* [ %19, %18 ], [ null, %8 ]
%23 = tail call i32 @free(i8* %13)
%24 = tail call i32 @free(i8* %15)
br label %25
25: ; preds = %21, %6
%26 = phi i8* [ %22, %21 ], [ %7, %6 ]
ret i8* %26
}