#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 *malloc(scalar_t__);
int /*<<< orphan*/ memcpy(char *, char *, int);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
scalar_t__ strrchr(char *, char);
char *_upse_resolve_path(char *f, char *newfile) {
  static char *ret;
  char *tp1;
  tp1 = ((char *)strrchr(f, '\\'));
  {
    char *tp3;
    tp3 = ((char *)strrchr(f, '/'));
    if (tp1 < tp3)
      tp1 = tp3;
  }
  if (!tp1) {
    ret = malloc(strlen(newfile) + 1);
    strcpy(ret, newfile);
  } else {
    ret = malloc(tp1 - f + 2 + strlen(newfile));
    memcpy(ret, f, tp1 - f);
    ret[tp1 - f] = '/';
    ret[tp1 - f + 1] = 0;
    strcat(ret, newfile);
  }
  return (ret);
}


x86 assembly (clang, -O0):
<_upse_resolve_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x5c,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    11aa <_upse_resolve_path+0x4a>
mov    -0x20(%rbp),%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11e6 <_upse_resolve_path+0x86>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1070 <malloc@plt>
mov    %rax,0x2e87(%rip)
mov    0x2e80(%rip),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
jmp    126f <_upse_resolve_path+0x10f>
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
add    $0x2,%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x28(%rbp),%rdi
add    %rax,%rdi
call   1070 <malloc@plt>
mov    %rax,0x2e43(%rip)
mov    0x2e3c(%rip),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
call   1060 <memcpy@plt>
mov    0x2e1f(%rip),%rax
mov    -0x18(%rbp),%rcx
mov    -0x8(%rbp),%rdx
sub    %rdx,%rcx
movb   $0x2f,(%rax,%rcx,1)
mov    0x2e09(%rip),%rax
mov    -0x18(%rbp),%rcx
mov    -0x8(%rbp),%rdx
sub    %rdx,%rcx
movb   $0x0,0x1(%rax,%rcx,1)
mov    0x2df2(%rip),%rdi
mov    -0x10(%rbp),%rsi
call   1080 <strcat@plt>
mov    0x2de2(%rip),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_upse_resolve_path>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    $0x5c,%esi
call   1050 <strrchr@plt>
mov    %rax,%rbx
mov    %r15,%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
cmp    %rax,%rbx
cmovb  %rax,%rbx
test   %rbx,%rbx
je     11d4 <_upse_resolve_path+0x74>
sub    %r15,%rbx
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    (%rbx,%rax,1),%rdi
add    $0x2,%rdi
call   1070 <malloc@plt>
mov    %rax,0x2ea8(%rip)
mov    %rax,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1060 <memcpy@plt>
mov    0x2e94(%rip),%rdi
movw   $0x2f,(%rdi,%rbx,1)
mov    %r14,%rsi
call   1080 <strcat@plt>
jmp    11f7 <_upse_resolve_path+0x97>
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%rdi
call   1070 <malloc@plt>
mov    %rax,0x2e6c(%rip)
mov    %rax,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    0x2e5a(%rip),%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@_upse_resolve_path.ret = internal unnamed_addr global i8* null
define i8* @_upse_resolve_path(i8* %0, i8* %1) {
%3 = tail call i64 @strrchr(i8* %0, i8 signext 92)
%4 = inttoptr i64 %3 to i8*
%5 = tail call i64 @strrchr(i8* %0, i8 signext 47)
%6 = inttoptr i64 %5 to i8*
%7 = icmp ult i8* %4, %6
%8 = select i1 %7, i8* %6, i8* %4
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %15
10: ; preds = %2
%11 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%12 = add nsw i64 %11, 1
%13 = tail call i8* @malloc(i64 %12)
store i8* %13, i8** @_upse_resolve_path.ret
%14 = tail call i32 @strcpy(i8* %13, i8* %1)
br label %30
15: ; preds = %2
%16 = ptrtoint i8* %8 to i64
%17 = ptrtoint i8* %0 to i64
%18 = sub i64 %16, %17
%19 = add nsw i64 %18, 2
%20 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%21 = add nsw i64 %19, %20
%22 = tail call i8* @malloc(i64 %21)
store i8* %22, i8** @_upse_resolve_path.ret
%23 = trunc i64 %18 to i32
%24 = tail call i32 @memcpy(i8* %22, i8* %0, i32 %23)
%25 = load i8*, i8** @_upse_resolve_path.ret
%26 = getelementptr inbounds i8, i8* %25, i64 %18
store i8 47, i8* %26
%27 = add nsw i64 %18, 1
%28 = getelementptr inbounds i8, i8* %25, i64 %27
store i8 0, i8* %28
%29 = tail call i32 @strcat(i8* %25, i8* %1)
br label %30
30: ; preds = %15, %10
%31 = load i8*, i8** @_upse_resolve_path.ret
ret i8* %31
}