#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*/ fprintf(int /*<<< orphan*/, char *, char const *,
                           char const *, char const *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcat(char *, char const *);
int /*<<< orphan*/ strcmp(char const *, char const *);
int /*<<< orphan*/ strcpy(char *, char const *);
size_t strlen(char const *);
char *__qunit_utils_changefileext(char const *fname, char const *src_ext,
                                  char const *tgt_ext, char *out_buff) {
  if (!strcmp(&fname[strlen(fname) - strlen(src_ext)], src_ext)) {
    strcpy(out_buff, fname);
    strcpy(&out_buff[strlen(fname) - strlen(src_ext)], tgt_ext);
  } else {
    fprintf(stderr,
            "WARNING: %s is not a %s file. Appending the %s extension...",
            fname, src_ext, tgt_ext);
    strcpy(out_buff, fname);
    strcat(out_buff, tgt_ext);
  }
  return out_buff;
}


x86 assembly (clang, -O0):
<__qunit_utils_changefileext>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x30(%rbp),%rdi
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
sub    %rcx,%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    11f3 <__qunit_utils_changefileext+0xa3>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x40(%rbp),%rdi
mov    %rax,%rcx
mov    -0x38(%rbp),%rax
sub    %rcx,%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcpy@plt>
jmp    122e <__qunit_utils_changefileext+0xde>
mov    0x2de6(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%r8
lea    0xdf1(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1070 <strcat@plt>
mov    -0x20(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__qunit_utils_changefileext>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rcx,%r15
mov    %rdx,%r14
mov    %rsi,%r12
mov    %rdi,%r13
call   1040 <strlen@plt>
mov    %rax,%rbx
mov    %r12,%rdi
call   1040 <strlen@plt>
sub    %rax,%rbx
add    %r13,%rbx
mov    %rbx,%rdi
mov    %r12,%rsi
call   1050 <strcmp@plt>
test   %eax,%eax
je     11c0 <__qunit_utils_changefileext+0x70>
mov    0x2e4f(%rip),%rax
mov    (%rax),%edi
lea    0xe66(%rip),%rsi
mov    %r13,%rdx
mov    %r12,%rcx
mov    %r14,%r8
call   1060 <fprintf@plt>
mov    %r15,%rdi
mov    %r13,%rsi
call   1030 <strcpy@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   1070 <strcat@plt>
jmp    11ef <__qunit_utils_changefileext+0x9f>
mov    %r15,%rdi
mov    %r13,%rsi
call   1030 <strcpy@plt>
mov    %r13,%rdi
call   1040 <strlen@plt>
mov    %rax,%rbx
mov    %r12,%rdi
call   1040 <strlen@plt>
sub    %rax,%rbx
add    %r15,%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    %r15,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [60 x i8] c"WARNING: %s is not a %s file. Appending the %s extension...\00"
define i8* @__qunit_utils_changefileext(i8* %0, i8* %1, i8* %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i8* %3, i8** %8
%9 = load i8*, i8** %5
%10 = load i8*, i8** %5
%11 = call i64 @strlen(i8* %10)
%12 = load i8*, i8** %6
%13 = call i64 @strlen(i8* %12)
%14 = sub i64 %11, %13
%15 = getelementptr inbounds i8, i8* %9, i64 %14
%16 = load i8*, i8** %6
%17 = call i32 @strcmp(i8* %15, i8* %16)
%18 = icmp ne i32 %17, 0
br i1 %18, label %32, label %19
19: ; preds = %4
%20 = load i8*, i8** %8
%21 = load i8*, i8** %5
%22 = call i32 @strcpy(i8* %20, i8* %21)
%23 = load i8*, i8** %8
%24 = load i8*, i8** %5
%25 = call i64 @strlen(i8* %24)
%26 = load i8*, i8** %6
%27 = call i64 @strlen(i8* %26)
%28 = sub i64 %25, %27
%29 = getelementptr inbounds i8, i8* %23, i64 %28
%30 = load i8*, i8** %7
%31 = call i32 @strcpy(i8* %29, i8* %30)
br label %44
32: ; preds = %4
%33 = load i32, i32* @stderr
%34 = load i8*, i8** %5
%35 = load i8*, i8** %6
%36 = load i8*, i8** %7
%37 = call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str, i64 0, i64 0), i8* %34, i8* %35, i8* %36)
%38 = load i8*, i8** %8
%39 = load i8*, i8** %5
%40 = call i32 @strcpy(i8* %38, i8* %39)
%41 = load i8*, i8** %8
%42 = load i8*, i8** %7
%43 = call i32 @strcat(i8* %41, i8* %42)
br label %44
44: ; preds = %32, %19
%45 = load i8*, i8** %8
ret i8* %45
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [60 x i8] c"WARNING: %s is not a %s file. Appending the %s extension...\00"
define i8* @__qunit_utils_changefileext(i8* %0, i8* %1, i8* %2, i8* returned %3) {
%5 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%6 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%7 = sub i64 %5, %6
%8 = getelementptr inbounds i8, i8* %0, i64 %7
%9 = tail call i32 @strcmp(i8* dereferenceable(1) %8, i8* dereferenceable(1) %1)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %18
11: ; preds = %4
%12 = tail call i32 @strcpy(i8* %3, i8* %0)
%13 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%14 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%15 = sub i64 %13, %14
%16 = getelementptr inbounds i8, i8* %3, i64 %15
%17 = tail call i32 @strcpy(i8* %16, i8* %2)
br label %23
18: ; preds = %4
%19 = load i32, i32* @stderr
%20 = tail call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1, i8* %2)
%21 = tail call i32 @strcpy(i8* %3, i8* %0)
%22 = tail call i32 @strcat(i8* %3, i8* %2)
br label %23
23: ; preds = %18, %11
ret i8* %3
}