char *os_SubstSuffix(char const *path, char const *suffix) {
  char *s = os_GetSuffixPtr(path);
  char *r;
  if (!s) {
    return xstrmerge2(path, suffix);
  }
  ((r) = (typeof(r))xcalloc((s - path + strlen(suffix) + 1), sizeof((r)[0])));
  memcpy(r, path, s - path);
  strcat(r, suffix);
  return r;
}


x86 assembly (clang, -O0):
<os_SubstSuffix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x0,%al
call   1050 <os_GetSuffixPtr@plt>
cltq
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11a6 <os_SubstSuffix+0x46>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x0,%al
call   1070 <xstrmerge2@plt>
cltq
mov    %rax,-0x8(%rbp)
jmp    1208 <os_SubstSuffix+0xa8>
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x30(%rbp),%rdi
add    %rax,%rdi
add    $0x1,%rdi
mov    $0x1,%esi
mov    $0x0,%al
call   1080 <xcalloc@plt>
cltq
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x10(%rbp),%rax
sub    %rax,%rdx
call   1040 <memcpy@plt>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <strcat@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<os_SubstSuffix>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
xor    %eax,%eax
call   1050 <os_GetSuffixPtr@plt>
test   %eax,%eax
je     11b9 <os_SubstSuffix+0x59>
movslq %eax,%r12
sub    %r15,%r12
mov    %r14,%rdi
call   1030 <strlen@plt>
lea    (%r12,%rax,1),%rdi
add    $0x1,%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1080 <xcalloc@plt>
movslq %eax,%rbx
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1040 <memcpy@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <strcat@plt>
jmp    11c9 <os_SubstSuffix+0x69>
mov    %r15,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1070 <xstrmerge2@plt>
movslq %eax,%rbx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @os_SubstSuffix(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %4
%9 = call i32 (i8*, ...) bitcast (i32 (...)* @os_GetSuffixPtr to i32 (i8*, ...)*)(i8* %8)
%10 = sext i32 %9 to i64
%11 = inttoptr i64 %10 to i8*
store i8* %11, i8** %6
%12 = load i8*, i8** %6
%13 = icmp ne i8* %12, null
br i1 %13, label %20, label %14
14: ; preds = %2
%15 = load i8*, i8** %4
%16 = load i8*, i8** %5
%17 = call i32 (i8*, i8*, ...) bitcast (i32 (...)* @xstrmerge2 to i32 (i8*, i8*, ...)*)(i8* %15, i8* %16)
%18 = sext i32 %17 to i64
%19 = inttoptr i64 %18 to i8*
store i8* %19, i8** %3
br label %44
20: ; preds = %2
%21 = load i8*, i8** %6
%22 = load i8*, i8** %4
%23 = ptrtoint i8* %21 to i64
%24 = ptrtoint i8* %22 to i64
%25 = sub i64 %23, %24
%26 = load i8*, i8** %5
%27 = call i64 @strlen(i8* %26)
%28 = add i64 %25, %27
%29 = add i64 %28, 1
%30 = call i32 (i64, i64, ...) bitcast (i32 (...)* @xcalloc to i32 (i64, i64, ...)*)(i64 %29, i64 1)
%31 = sext i32 %30 to i64
%32 = inttoptr i64 %31 to i8*
store i8* %32, i8** %7
%33 = load i8*, i8** %7
%34 = load i8*, i8** %4
%35 = load i8*, i8** %6
%36 = load i8*, i8** %4
%37 = ptrtoint i8* %35 to i64
%38 = ptrtoint i8* %36 to i64
%39 = sub i64 %37, %38
%40 = load i8*, i8** %7
%41 = load i8*, i8** %5
%42 = call i8* @strcat(i8* %40, i8* %41)
%43 = load i8*, i8** %7
store i8* %43, i8** %3
br label %44
44: ; preds = %20, %14
%45 = load i8*, i8** %3
ret i8* %45
}

LLVM IR (-O2):
define i8* @os_SubstSuffix(i8* %0, i8* %1) {
%3 = tail call i32 (i8*, ...) bitcast (i32 (...)* @os_GetSuffixPtr to i32 (i8*, ...)*)(i8* %0)
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %9
5: ; preds = %2
%6 = tail call i32 (i8*, i8*, ...) bitcast (i32 (...)* @xstrmerge2 to i32 (i8*, i8*, ...)*)(i8* %0, i8* %1)
%7 = sext i32 %6 to i64
%8 = inttoptr i64 %7 to i8*
br label %20
9: ; preds = %2
%10 = sext i32 %3 to i64
%11 = ptrtoint i8* %0 to i64
%12 = sub i64 %10, %11
%13 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%14 = add i64 %12, 1
%15 = add i64 %14, %13
%16 = tail call i32 (i64, i64, ...) bitcast (i32 (...)* @xcalloc to i32 (i64, i64, ...)*)(i64 %15, i64 1)
%17 = sext i32 %16 to i64
%18 = inttoptr i64 %17 to i8*
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 %18, i8* align 1 %0, i64 %12, i1 false)
%19 = tail call i8* @strcat(i8* dereferenceable(1) %18, i8* dereferenceable(1) %1)
br label %20
20: ; preds = %9, %5
%21 = phi i8* [ %18, %9 ], [ %8, %5 ]
ret i8* %21
}