char *makefn(base, sub)
char *base;
char *sub;
{
  char *fn;
  fn = malloc(strlen(base) + strlen(sub) + 2);
  strcpy(fn, base);
  base = strrchr(fn, '.');
  if (base)
    *base = 0;
  strcat(fn, ".");
  strcat(fn, sub);
  return (fn);
}


x86 assembly (clang, -O0):
<makefn>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x20(%rbp),%rdi
add    %rax,%rdi
add    $0x2,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%rdi
mov    $0x2e,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11bb <makefn+0x6b>
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rdi
lea    0xe3a(%rip),%rsi
call   1070 <strcat@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <strcat@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<makefn>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
call   1040 <strlen@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    (%rbx,%rax,1),%rdi
add    $0x2,%rdi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
mov    $0x2e,%esi
call   1050 <strrchr@plt>
test   %rax,%rax
je     119b <makefn+0x4b>
movb   $0x0,(%rax)
mov    %rbx,%rdi
call   1040 <strlen@plt>
movw   $0x2e,(%rbx,%rax,1)
mov    %rbx,%rdi
mov    %r14,%rsi
pop    %rbx
pop    %r14
pop    %r15
jmp    1070 <strcat@plt>

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

LLVM IR (-O2):
define i8* @makefn(i8* nocapture %0, i8* nocapture %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%4 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%5 = add i64 %3, 2
%6 = add i64 %5, %4
%7 = tail call i8* @malloc(i64 %6)
%8 = tail call i8* @strcpy(i8* dereferenceable(1) %7, i8* dereferenceable(1) %0)
%9 = tail call i8* @strrchr(i8* dereferenceable(1) %7, i32 46)
%10 = icmp eq i8* %9, null
br i1 %10, label %12, label %11
11: ; preds = %2
store i8 0, i8* %9
br label %12
12: ; preds = %11, %2
%13 = tail call i64 @strlen(i8* dereferenceable(1) %7)
%14 = getelementptr i8, i8* %7, i64 %13
%15 = bitcast i8* %14 to i16*
store i16 46, i16* %15
%16 = tail call i8* @strcat(i8* dereferenceable(1) %7, i8* dereferenceable(1) %1)
ret i8* %7
}