#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 *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ strcat(char *, char *);
char *strdup(char *);
char *strrchr(char *, char);
char *floname(char *f) {
  char *dup = strdup(f);
  char *bname = basename(dup);
  char *extn = NULL;
  extn = strrchr(bname, '.');
  if (extn)
    *extn = '\0';
  free(dup);
  char *result = strdup(bname);
  strcat(result, ".flo");
  return result;
}


x86 assembly (clang, -O0):
<floname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <strdup@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <basename@plt>
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x2e,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11a2 <floname+0x52>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1070 <strdup@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xe3d(%rip),%rsi
call   1060 <strcat@plt>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<floname>:
push   %r14
push   %rbx
push   %rax
call   1070 <strdup@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1050 <basename@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x2e,%esi
call   1040 <strrchr@plt>
test   %rax,%rax
je     117c <floname+0x2c>
movb   $0x0,(%rax)
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1070 <strdup@plt>
mov    %rax,%rbx
lea    0xe6a(%rip),%rsi
mov    %rax,%rdi
call   1060 <strcat@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [5 x i8] c".flo\00"
define i8* @floname(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %2
%7 = load i8*, i8** %2
%8 = call i8* @strdup(i8* %7)
store i8* %8, i8** %3
%9 = load i8*, i8** %3
%10 = call i8* @basename(i8* %9)
store i8* %10, i8** %4
store i8* null, i8** %5
%11 = load i8*, i8** %4
%12 = call i8* @strrchr(i8* %11, i8 signext 46)
store i8* %12, i8** %5
%13 = load i8*, i8** %5
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %17
15: ; preds = %1
%16 = load i8*, i8** %5
store i8 0, i8* %16
br label %17
17: ; preds = %15, %1
%18 = load i8*, i8** %3
%19 = call i32 @free(i8* %18)
%20 = load i8*, i8** %4
%21 = call i8* @strdup(i8* %20)
store i8* %21, i8** %6
%22 = load i8*, i8** %6
%23 = call i32 @strcat(i8* %22, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%24 = load i8*, i8** %6
ret i8* %24
}

LLVM IR (-O2):
@.str = [5 x i8] c".flo\00"
define i8* @floname(i8* nocapture %0) {
%2 = tail call i8* @strdup(i8* %0)
%3 = tail call i8* @basename(i8* %2)
%4 = tail call i8* @strrchr(i8* dereferenceable(1) %3, i8 signext 46)
%5 = icmp eq i8* %4, null
br i1 %5, label %7, label %6
6: ; preds = %1
store i8 0, i8* %4
br label %7
7: ; preds = %6, %1
%8 = tail call i32 @free(i8* %2)
%9 = tail call i8* @strdup(i8* %3)
%10 = tail call i32 @strcat(i8* %9, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
ret i8* %9
}