#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 */
scalar_t__ malloc(int const);
int /*<<< orphan*/ strcat(char *, char const *);
int /*<<< orphan*/ strcpy(char *, char const *);
int const strlen(char const *);
int /*<<< orphan*/ strtok(char *, char *);
int changeFileEnding(char **newname, const char *oldname, const char *end) {
  const int aux = strlen(end);
  *newname = (char *)malloc((strlen(oldname) + aux) * sizeof(char));
  strcpy(*newname, oldname);
  strtok(*newname, ".");
  strcat(*newname, end);
  return 0;
}


x86 assembly (clang, -O0):
<changeFileEnding>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
add    -0x1c(%rbp),%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
lea    0xe4f(%rip),%rsi
call   1060 <strtok@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x18(%rbp),%rsi
call   1070 <strcat@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<changeFileEnding>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
mov    %rdx,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    %r15,%rdi
call   1040 <strlen@plt>
add    %eax,%ebp
mov    %ebp,%edi
call   1050 <malloc@plt>
mov    %rax,(%rbx)
mov    %rax,%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
mov    (%rbx),%rdi
lea    0xe6d(%rip),%rsi
call   1060 <strtok@plt>
mov    (%rbx),%rdi
mov    %r14,%rsi
call   1070 <strcat@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c".\00"
define i32 @changeFileEnding(i8** %0, i8* %1, i8* %2) {
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
store i8** %0, i8*** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%8 = load i8*, i8** %6
%9 = call i32 @strlen(i8* %8)
store i32 %9, i32* %7
%10 = load i8*, i8** %5
%11 = call i32 @strlen(i8* %10)
%12 = load i32, i32* %7
%13 = add nsw i32 %11, %12
%14 = sext i32 %13 to i64
%15 = mul i64 %14, 1
%16 = trunc i64 %15 to i32
%17 = call i64 @malloc(i32 %16)
%18 = inttoptr i64 %17 to i8*
%19 = load i8**, i8*** %4
store i8* %18, i8** %19
%20 = load i8**, i8*** %4
%21 = load i8*, i8** %20
%22 = load i8*, i8** %5
%23 = call i32 @strcpy(i8* %21, i8* %22)
%24 = load i8**, i8*** %4
%25 = load i8*, i8** %24
%26 = call i32 @strtok(i8* %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%27 = load i8**, i8*** %4
%28 = load i8*, i8** %27
%29 = load i8*, i8** %6
%30 = call i32 @strcat(i8* %28, i8* %29)
ret i32 0
}

LLVM IR (-O2):
@.str = [2 x i8] c".\00"
define i32 @changeFileEnding(i8** nocapture %0, i8* %1, i8* %2) {
%4 = tail call i32 @strlen(i8* %2)
%5 = tail call i32 @strlen(i8* %1)
%6 = add nsw i32 %5, %4
%7 = tail call i64 @malloc(i32 %6)
%8 = inttoptr i64 %7 to i8*
store i8* %8, i8** %0
%9 = tail call i32 @strcpy(i8* %8, i8* %1)
%10 = load i8*, i8** %0
%11 = tail call i32 @strtok(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%12 = load i8*, i8** %0
%13 = tail call i32 @strcat(i8* %12, i8* %2)
ret i32 0
}