#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 *basename2(char *);
int /*<<< orphan*/ strcat(char *, char const *);
char *strrchr(char *, char);
char *set_suffix_i(char *filename, const char *suffix) {
  char *p, *p2;
  if (!(p = basename2(filename)))
    p = filename;
  if ((p2 = strrchr(p, '.')))
    if (p2 != p)
      *p2 = 0;
  strcat(filename, suffix);
  return filename;
}


x86 assembly (clang, -O0):
<set_suffix_i>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <basename2@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    115f <set_suffix_i+0x2f>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x2e,%esi
call   1030 <strrchr@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     1195 <set_suffix_i+0x65>
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
je     1190 <set_suffix_i+0x60>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
jmp    1195 <set_suffix_i+0x65>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <strcat@plt>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_suffix_i>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
call   1040 <basename2@plt>
mov    %rax,%rbx
test   %rax,%rax
cmove  %r15,%rbx
mov    %rbx,%rdi
mov    $0x2e,%esi
call   1030 <strrchr@plt>
test   %rax,%rax
je     1164 <set_suffix_i+0x34>
cmp    %rbx,%rax
je     1164 <set_suffix_i+0x34>
movb   $0x0,(%rax)
mov    %r15,%rdi
mov    %r14,%rsi
call   1050 <strcat@plt>
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @set_suffix_i(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 i8* @basename2(i8* %7)
store i8* %8, i8** %5
%9 = icmp ne i8* %8, null
br i1 %9, label %12, label %10
10: ; preds = %2
%11 = load i8*, i8** %3
store i8* %11, i8** %5
br label %12
12: ; preds = %10, %2
%13 = load i8*, i8** %5
%14 = call i8* @strrchr(i8* %13, i8 signext 46)
store i8* %14, i8** %6
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %23
16: ; preds = %12
%17 = load i8*, i8** %6
%18 = load i8*, i8** %5
%19 = icmp ne i8* %17, %18
br i1 %19, label %20, label %22
20: ; preds = %16
%21 = load i8*, i8** %6
store i8 0, i8* %21
br label %22
22: ; preds = %20, %16
br label %23
23: ; preds = %22, %12
%24 = load i8*, i8** %3
%25 = load i8*, i8** %4
%26 = call i32 @strcat(i8* %24, i8* %25)
%27 = load i8*, i8** %3
ret i8* %27
}

LLVM IR (-O2):
define i8* @set_suffix_i(i8* returned %0, i8* %1) {
%3 = tail call i8* @basename2(i8* %0)
%4 = icmp eq i8* %3, null
%5 = select i1 %4, i8* %0, i8* %3
%6 = tail call i8* @strrchr(i8* dereferenceable(1) %5, i8 signext 46)
%7 = icmp eq i8* %6, null
%8 = icmp eq i8* %6, %5
%9 = or i1 %7, %8
br i1 %9, label %11, label %10
10: ; preds = %2
store i8 0, i8* %6
br label %11
11: ; preds = %10, %2
%12 = tail call i32 @strcat(i8* %0, i8* %1)
ret i8* %0
}