#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 *basename(char const *);
scalar_t__ calloc(int, scalar_t__);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
char *get_new_filename(const char *from_filename) {
  char *from_basename = basename(from_filename);
  char *name;
  if (NULL ==
      (name = (char *)calloc(sizeof(char), strlen(from_basename) + 4 + 1))) {
    fprintf(stderr, "ERROR - cannot create new filename from %s\n",
            from_basename);
    return NULL;
  }
  strcpy(name, from_basename);
  strcat(name, ".exp");
  return name;
}


x86 assembly (clang, -O0):
<get_new_filename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <basename@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rsi
add    $0x4,%rsi
add    $0x1,%rsi
mov    $0x1,%edi
call   1050 <calloc@plt>
mov    %rax,%rcx
mov    %rcx,-0x20(%rbp)
xor    %eax,%eax
cmp    %rcx,%rax
jne    11cf <get_new_filename+0x6f>
mov    0x2e30(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xe43(%rip),%rsi
call   1060 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    11f4 <get_new_filename+0x94>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x20(%rbp),%rdi
lea    0xe45(%rip),%rsi
call   1080 <strcat@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_new_filename>:
push   %r14
push   %rbx
push   %rax
call   1070 <basename@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1040 <strlen@plt>
lea    0x5(%rax),%rsi
mov    $0x1,%edi
call   1050 <calloc@plt>
test   %rax,%rax
je     11a6 <get_new_filename+0x46>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
lea    0xe90(%rip),%rsi
mov    %rbx,%rdi
call   1080 <strcat@plt>
jmp    11c0 <get_new_filename+0x60>
mov    0x2e33(%rip),%rax
mov    (%rax),%edi
lea    0xe4a(%rip),%rsi
mov    %r14,%rdx
call   1060 <fprintf@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [44 x i8] c"ERROR - cannot create new filename from %s\0A\00"
@.str.1 = [5 x i8] c".exp\00"
define i8* @get_new_filename(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i8* @basename(i8* %6)
store i8* %7, i8** %4
%8 = load i8*, i8** %4
%9 = call i64 @strlen(i8* %8)
%10 = add nsw i64 %9, 4
%11 = add nsw i64 %10, 1
%12 = call i64 @calloc(i32 1, i64 %11)
%13 = inttoptr i64 %12 to i8*
store i8* %13, i8** %5
%14 = icmp eq i8* null, %13
br i1 %14, label %15, label %19
15: ; preds = %1
%16 = load i32, i32* @stderr
%17 = load i8*, i8** %4
%18 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i8* %17)
store i8* null, i8** %2
br label %26
19: ; preds = %1
%20 = load i8*, i8** %5
%21 = load i8*, i8** %4
%22 = call i32 @strcpy(i8* %20, i8* %21)
%23 = load i8*, i8** %5
%24 = call i32 @strcat(i8* %23, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%25 = load i8*, i8** %5
store i8* %25, i8** %2
br label %26
26: ; preds = %19, %15
%27 = load i8*, i8** %2
ret i8* %27
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [44 x i8] c"ERROR - cannot create new filename from %s\0A\00"
@.str.1 = [5 x i8] c".exp\00"
define i8* @get_new_filename(i8* %0) {
%2 = tail call i8* @basename(i8* %0)
%3 = tail call i64 @strlen(i8* dereferenceable(1) %2)
%4 = add nsw i64 %3, 5
%5 = tail call i64 @calloc(i32 1, i64 %4)
%6 = inttoptr i64 %5 to i8*
%7 = icmp eq i64 %5, 0
br i1 %7, label %8, label %11
8: ; preds = %1
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i8* %2)
br label %14
11: ; preds = %1
%12 = tail call i32 @strcpy(i8* %6, i8* %2)
%13 = tail call i32 @strcat(i8* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %14
14: ; preds = %11, %8
%15 = phi i8* [ null, %8 ], [ %6, %11 ]
ret i8* %15
}