#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*/ strcpy(char *, char const *);
int /*<<< orphan*/ strncpy(char *, char const *, size_t);
char *strrchr(char const *, char);
void cgltf_combine_paths(char *path, const char *base, const char *uri) {
  const char *s0 = strrchr(base, '/');
  const char *s1 = strrchr(base, '\\');
  const char *slash = s0 ? (s1 && s1 > s0 ? s1 : s0) : s1;
  if (slash) {
    size_t prefix = slash - base + 1;
    strncpy(path, base, prefix);
    strcpy(path + prefix, uri);
  } else {
    strcpy(path, uri);
  }
}


x86 assembly (clang, -O0):
<cgltf_combine_paths>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x5c,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11ae <cgltf_combine_paths+0x7e>
cmpq   $0x0,-0x28(%rbp)
je     1199 <cgltf_combine_paths+0x69>
mov    -0x28(%rbp),%rax
cmp    -0x20(%rbp),%rax
jbe    1199 <cgltf_combine_paths+0x69>
mov    -0x28(%rbp),%rax
mov    %rax,-0x40(%rbp)
jmp    11a1 <cgltf_combine_paths+0x71>
mov    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,-0x48(%rbp)
jmp    11b6 <cgltf_combine_paths+0x86>
mov    -0x28(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1203 <cgltf_combine_paths+0xd3>
mov    -0x30(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x38(%rbp),%rdx
call   1030 <strncpy@plt>
mov    -0x8(%rbp),%rdi
add    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strcpy@plt>
jmp    1210 <cgltf_combine_paths+0xe0>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strcpy@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cgltf_combine_paths>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r12
mov    %rdi,%r15
mov    %rsi,%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
mov    %rax,%r13
mov    %r12,%rdi
mov    $0x5c,%esi
call   1050 <strrchr@plt>
cmp    %r13,%rax
mov    %r13,%rbx
cmova  %rax,%rbx
test   %rax,%rax
cmove  %r13,%rbx
test   %r13,%r13
cmove  %rax,%rbx
test   %rbx,%rbx
je     1195 <cgltf_combine_paths+0x65>
sub    %r12,%rbx
lea    0x1(%rbx),%rdx
mov    %r15,%rdi
mov    %r12,%rsi
call   1030 <strncpy@plt>
add    %rbx,%r15
add    $0x1,%r15
mov    %r15,%rdi
mov    %r14,%rsi
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1040 <strcpy@plt>

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

LLVM IR (-O2):
define void @cgltf_combine_paths(i8* %0, i8* %1, i8* %2) {
%4 = tail call i8* @strrchr(i8* dereferenceable(1) %1, i8 signext 47)
%5 = tail call i8* @strrchr(i8* dereferenceable(1) %1, i8 signext 92)
%6 = icmp eq i8* %4, null
%7 = icmp ne i8* %5, null
%8 = icmp ugt i8* %5, %4
%9 = select i1 %7, i1 %8, i1 false
%10 = select i1 %6, i1 true, i1 %9
%11 = select i1 %10, i8* %5, i8* %4
%12 = icmp eq i8* %11, null
br i1 %12, label %20, label %13
13: ; preds = %3
%14 = ptrtoint i8* %11 to i64
%15 = ptrtoint i8* %1 to i64
%16 = sub i64 %14, %15
%17 = add nsw i64 %16, 1
%18 = tail call i32 @strncpy(i8* %0, i8* %1, i64 %17)
%19 = getelementptr inbounds i8, i8* %0, i64 %17
br label %20
20: ; preds = %3, %13
%21 = phi i8* [ %19, %13 ], [ %0, %3 ]
%22 = tail call i32 @strcpy(i8* %21, i8* %2)
ret void
}