#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*/ strcat(char *, char *);
int /*<<< orphan*/ strcmp(char *, char *);
size_t strlen(char *);
void change_postfix(char *filename, char *affix1, char *affix2) {
  if (!strcmp(&filename[strlen(filename) - strlen(affix1)], affix1))
    filename[strlen(filename) - strlen(affix1)] = '\0';
  strcat(filename, affix2);
}


x86 assembly (clang, -O0):
<change_postfix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x28(%rbp),%rdi
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
sub    %rcx,%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    11b5 <change_postfix+0x85>
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x38(%rbp),%rcx
mov    %rax,%rdx
mov    -0x30(%rbp),%rax
sub    %rdx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <strcat@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<change_postfix>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r12
mov    %rdi,%r15
call   1030 <strlen@plt>
mov    %rax,%rbx
mov    %r12,%rdi
call   1030 <strlen@plt>
sub    %rax,%rbx
add    %r15,%rbx
mov    %rbx,%rdi
mov    %r12,%rsi
call   1040 <strcmp@plt>
test   %eax,%eax
jne    1169 <change_postfix+0x39>
movb   $0x0,(%rbx)
mov    %r15,%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1050 <strcat@plt>

LLVM IR (-O0):
define void @change_postfix(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%7 = load i8*, i8** %4
%8 = load i8*, i8** %4
%9 = call i64 @strlen(i8* %8)
%10 = load i8*, i8** %5
%11 = call i64 @strlen(i8* %10)
%12 = sub i64 %9, %11
%13 = getelementptr inbounds i8, i8* %7, i64 %12
%14 = load i8*, i8** %5
%15 = call i32 @strcmp(i8* %13, i8* %14)
%16 = icmp ne i32 %15, 0
br i1 %16, label %25, label %17
17: ; preds = %3
%18 = load i8*, i8** %4
%19 = load i8*, i8** %4
%20 = call i64 @strlen(i8* %19)
%21 = load i8*, i8** %5
%22 = call i64 @strlen(i8* %21)
%23 = sub i64 %20, %22
%24 = getelementptr inbounds i8, i8* %18, i64 %23
store i8 0, i8* %24
br label %25
25: ; preds = %17, %3
%26 = load i8*, i8** %4
%27 = load i8*, i8** %6
%28 = call i32 @strcat(i8* %26, i8* %27)
ret void
}

LLVM IR (-O2):
define void @change_postfix(i8* %0, i8* nocapture %1, i8* %2) {
%4 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%5 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%6 = sub i64 %4, %5
%7 = getelementptr inbounds i8, i8* %0, i64 %6
%8 = tail call i32 @strcmp(i8* dereferenceable(1) %7, i8* dereferenceable(1) %1)
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %3
store i8 0, i8* %7
br label %11
11: ; preds = %10, %3
%12 = tail call i32 @strcat(i8* %0, i8* %2)
ret void
}