#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 FILENAME_MAX;
int /*<<< orphan*/ linux_find_ext(char *, char *);
int /*<<< orphan*/ linux_find_path(char *, char *);
int /*<<< orphan*/ strcat(char *, char const *);
int /*<<< orphan*/ strcpy(char *, char *);
void linux_change_basename(char *new_filename, char *old_filename,
                           const char *basename) {
  char path[FILENAME_MAX], ext[FILENAME_MAX];
  linux_find_path(old_filename, path);
  linux_find_ext(old_filename, ext);
  strcpy(new_filename, path);
  strcat(new_filename, basename);
  strcat(new_filename, ".");
  strcat(new_filename, ext);
}


x86 assembly (clang, -O0):
<linux_change_basename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    0x2e8d(%rip),%rax
mov    (%rax),%ecx
mov    %rsp,%rdx
mov    %rdx,-0x20(%rbp)
mov    %rcx,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rsi
sub    %rdx,%rsi
mov    %rsi,-0x40(%rbp)
mov    %rsi,%rsp
mov    %rcx,-0x28(%rbp)
mov    (%rax),%eax
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <linux_find_path@plt>
mov    -0x38(%rbp),%rsi
mov    -0x10(%rbp),%rdi
call   1060 <linux_find_ext@plt>
mov    -0x40(%rbp),%rsi
mov    -0x8(%rbp),%rdi
call   1030 <strcpy@plt>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <strcat@plt>
mov    -0x8(%rbp),%rdi
lea    0xe27(%rip),%rsi
call   1050 <strcat@plt>
mov    -0x38(%rbp),%rsi
mov    -0x8(%rbp),%rdi
call   1050 <strcat@plt>
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<linux_change_basename>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r12
mov    %rdi,%r15
mov    0x2e8a(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rsp,%r13
sub    %rax,%r13
mov    %r13,%rsp
mov    %rsi,%rdi
mov    %rbx,%rsi
call   1040 <linux_find_path@plt>
mov    %r12,%rdi
mov    %r13,%rsi
call   1060 <linux_find_ext@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   1050 <strcat@plt>
lea    0xe53(%rip),%rsi
mov    %r15,%rdi
call   1050 <strcat@plt>
mov    %r15,%rdi
mov    %r13,%rsi
call   1050 <strcat@plt>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@FILENAME_MAX = global i32 0
@.str = [2 x i8] c".\00"
define void @linux_change_basename(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i64
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%10 = load i32, i32* @FILENAME_MAX
%11 = zext i32 %10 to i64
%12 = call i8* @llvm.stacksave()
store i8* %12, i8** %7
%13 = alloca i8, i64 %11
store i64 %11, i64* %8
%14 = load i32, i32* @FILENAME_MAX
%15 = zext i32 %14 to i64
%16 = alloca i8, i64 %15
store i64 %15, i64* %9
%17 = load i8*, i8** %5
%18 = call i32 @linux_find_path(i8* %17, i8* %13)
%19 = load i8*, i8** %5
%20 = call i32 @linux_find_ext(i8* %19, i8* %16)
%21 = load i8*, i8** %4
%22 = call i32 @strcpy(i8* %21, i8* %13)
%23 = load i8*, i8** %4
%24 = load i8*, i8** %6
%25 = call i32 @strcat(i8* %23, i8* %24)
%26 = load i8*, i8** %4
%27 = call i32 @strcat(i8* %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%28 = load i8*, i8** %4
%29 = call i32 @strcat(i8* %28, i8* %16)
%30 = load i8*, i8** %7
ret void
}

LLVM IR (-O2):
@FILENAME_MAX = global i32 0
@.str = [2 x i8] c".\00"
define void @linux_change_basename(i8* %0, i8* %1, i8* %2) {
%4 = load i32, i32* @FILENAME_MAX
%5 = zext i32 %4 to i64
%6 = alloca i8, i64 %5
%7 = alloca i8, i64 %5
%8 = call i32 @linux_find_path(i8* %1, i8* %6)
%9 = call i32 @linux_find_ext(i8* %1, i8* %7)
%10 = call i32 @strcpy(i8* %0, i8* %6)
%11 = call i32 @strcat(i8* %0, i8* %2)
%12 = call i32 @strcat(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @strcat(i8* %0, i8* %7)
ret void
}