#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*/ memcpy(char *, char const *, size_t);
int /*<<< orphan*/ snprintf(char *, size_t, char *, char const *);
char *strrchr(char const *, char);
const char *formatTransparentPath(char *buf, size_t bufsiz,
                                  const char *parentPath, const char *path) {
  const char *p = strrchr(parentPath, '/');
  if (p != NULL && path[0] != '/') {
    size_t len = (p - parentPath) + 1;
    if (len < bufsiz) {
      memcpy(buf, parentPath, len);
      snprintf(buf + len, bufsiz - len, "%s", path);
      return (const char *)buf;
    }
  }
  return path;
}


x86 assembly (clang, -O0):
<formatTransparentPath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     11d9 <formatTransparentPath+0xa9>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
je     11d9 <formatTransparentPath+0xa9>
mov    -0x30(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    %rcx,%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    11d4 <formatTransparentPath+0xa4>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x38(%rbp),%rdx
call   1050 <memcpy@plt>
mov    -0x10(%rbp),%rdi
add    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%rsi
sub    -0x38(%rbp),%rsi
mov    -0x28(%rbp),%rcx
lea    0xe3e(%rip),%rdx
call   1030 <snprintf@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11e1 <formatTransparentPath+0xb1>
jmp    11d9 <formatTransparentPath+0xa9>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<formatTransparentPath>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rcx,%r14
mov    %rdx,%r13
mov    %rsi,%r15
mov    %rdi,%r12
mov    %rdx,%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
test   %rax,%rax
je     1195 <formatTransparentPath+0x65>
cmpb   $0x2f,(%r14)
je     1195 <formatTransparentPath+0x65>
mov    %rax,%rbx
sub    %r13,%rbx
add    $0x1,%rbx
cmp    %r15,%rbx
jae    1195 <formatTransparentPath+0x65>
mov    %r12,%rdi
mov    %r13,%rsi
mov    %rbx,%rdx
call   1050 <memcpy@plt>
lea    (%r12,%rbx,1),%rdi
sub    %rbx,%r15
lea    0xe78(%rip),%rdx
mov    %r15,%rsi
mov    %r14,%rcx
call   1030 <snprintf@plt>
jmp    1198 <formatTransparentPath+0x68>
mov    %r14,%r12
mov    %r12,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
define i8* @formatTransparentPath(i8* %0, i64 %1, i8* %2, i8* %3) {
%5 = tail call i8* @strrchr(i8* dereferenceable(1) %2, i8 signext 47)
%6 = icmp eq i8* %5, null
br i1 %6, label %21, label %7
7: ; preds = %4
%8 = load i8, i8* %3
%9 = icmp eq i8 %8, 47
br i1 %9, label %21, label %10
10: ; preds = %7
%11 = ptrtoint i8* %5 to i64
%12 = ptrtoint i8* %2 to i64
%13 = sub i64 %11, %12
%14 = add nsw i64 %13, 1
%15 = icmp ult i64 %14, %1
br i1 %15, label %16, label %21
16: ; preds = %10
%17 = tail call i32 @memcpy(i8* %0, i8* %2, i64 %14)
%18 = getelementptr inbounds i8, i8* %0, i64 %14
%19 = sub i64 %1, %14
%20 = tail call i32 @snprintf(i8* %18, i64 %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %3)
br label %21
21: ; preds = %4, %7, %10, %16
%22 = phi i8* [ %0, %16 ], [ %3, %10 ], [ %3, %7 ], [ %3, %4 ]
ret i8* %22
}