#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 *strrchr(char const *, char);
char *xstrdup(char const *);
char *xstrmerge1(char *, char const *);
char *xstrmerge2(char const *, char const *);
char *os_SubstSuffix(char const *path, char const *suffix) {
  char *dp;
  char *sp;
  char *r;
  if (path == NULL)
    return NULL;
  sp = strrchr(path, '/');
  dp = strrchr(path, '.');
  if (dp == NULL || (sp != NULL && sp > dp)) {
    return xstrmerge2(path, suffix);
  }
  r = xstrdup(path);
  r[dp - path] = 0;
  return xstrmerge1(r, suffix);
}


x86 assembly (clang, -O0):
<os_SubstSuffix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1168 <os_SubstSuffix+0x28>
movq   $0x0,-0x8(%rbp)
jmp    11f7 <os_SubstSuffix+0xb7>
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1030 <strrchr@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2e,%esi
call   1030 <strrchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11b0 <os_SubstSuffix+0x70>
cmpq   $0x0,-0x28(%rbp)
je     11c6 <os_SubstSuffix+0x86>
mov    -0x28(%rbp),%rax
cmp    -0x20(%rbp),%rax
jbe    11c6 <os_SubstSuffix+0x86>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <xstrmerge2@plt>
mov    %rax,-0x8(%rbp)
jmp    11f7 <os_SubstSuffix+0xb7>
mov    -0x10(%rbp),%rdi
call   1040 <xstrdup@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    -0x10(%rbp),%rdx
sub    %rdx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <xstrmerge1@plt>
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
test   %rdi,%rdi
je     1195 <os_SubstSuffix+0x55>
mov    %rsi,%r14
mov    %rdi,%rbx
mov    $0x2f,%esi
call   1030 <strrchr@plt>
mov    %rax,%r12
mov    %rbx,%rdi
mov    $0x2e,%esi
call   1030 <strrchr@plt>
test   %rax,%rax
je     117f <os_SubstSuffix+0x3f>
mov    %rax,%r15
test   %r12,%r12
je     11a3 <os_SubstSuffix+0x63>
cmp    %r15,%r12
jbe    11a3 <os_SubstSuffix+0x63>
mov    %rbx,%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1060 <xstrmerge2@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    %rbx,%rdi
call   1040 <xstrdup@plt>
sub    %rbx,%r15
movb   $0x0,(%rax,%r15,1)
mov    %rax,%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1050 <xstrmerge1@plt>

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*
%8 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%9 = load i8*, i8** %4
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %12
11: ; preds = %2
store i8* null, i8** %3
br label %43
12: ; preds = %2
%13 = load i8*, i8** %4
%14 = call i8* @strrchr(i8* %13, i8 signext 47)
store i8* %14, i8** %7
%15 = load i8*, i8** %4
%16 = call i8* @strrchr(i8* %15, i8 signext 46)
store i8* %16, i8** %6
%17 = load i8*, i8** %6
%18 = icmp eq i8* %17, null
br i1 %18, label %26, label %19
19: ; preds = %12
%20 = load i8*, i8** %7
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %30
22: ; preds = %19
%23 = load i8*, i8** %7
%24 = load i8*, i8** %6
%25 = icmp ugt i8* %23, %24
br i1 %25, label %26, label %30
26: ; preds = %22, %12
%27 = load i8*, i8** %4
%28 = load i8*, i8** %5
%29 = call i8* @xstrmerge2(i8* %27, i8* %28)
store i8* %29, i8** %3
br label %43
30: ; preds = %22, %19
%31 = load i8*, i8** %4
%32 = call i8* @xstrdup(i8* %31)
store i8* %32, i8** %8
%33 = load i8*, i8** %8
%34 = load i8*, i8** %6
%35 = load i8*, i8** %4
%36 = ptrtoint i8* %34 to i64
%37 = ptrtoint i8* %35 to i64
%38 = sub i64 %36, %37
%39 = getelementptr inbounds i8, i8* %33, i64 %38
store i8 0, i8* %39
%40 = load i8*, i8** %8
%41 = load i8*, i8** %5
%42 = call i8* @xstrmerge1(i8* %40, i8* %41)
store i8* %42, i8** %3
br label %43
43: ; preds = %30, %26, %11
%44 = load i8*, i8** %3
ret i8* %44
}

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