#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);
int strlen(char *const);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *output(char *const filename) {
  char *end, *str, *ending, *ret;
  str = filename;
  end = filename + strlen(filename) - 1;
  ending = (char *)malloc(sizeof(char *) * 15);
  ending = ending + 15;
  *ending = '\0';
  ending--;
  while (*end-- != '.')
    ;
  ret = (char *)malloc(sizeof(char *) * (end - str + 1));
  strncpy(str, ret, (end - str));
  return ret;
}


x86 assembly (clang, -O0):
<output>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
mov    $0x78,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
add    $0xf,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x10(%rbp)
movsbl (%rax),%eax
cmp    $0x2e,%eax
je     11b6 <output+0x86>
jmp    1196 <output+0x66>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    %rcx,%rax
add    $0x1,%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
call   1030 <strncpy@plt>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<output>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
call   1040 <strlen@plt>
movslq %eax,%r12
lea    (%r14,%r12,1),%rbx
add    $0xffffffffffffffff,%rbx
mov    $0x78,%edi
call   1050 <malloc@plt>
movb   $0x0,0xf(%rax)
lea    0x0(,%r12,8),%edi
add    $0xffffffff,%r12d
cs nopw 0x0(%rax,%rax,1)
nop
add    $0xfffffff8,%edi
add    $0xffffffff,%r12d
cmpb   $0x2e,(%rbx)
lea    -0x1(%rbx),%rbx
jne    1170 <output+0x40>
call   1050 <malloc@plt>
mov    %rax,%r15
mov    %r14,%rdi
mov    %rax,%rsi
mov    %r12d,%edx
call   1030 <strncpy@plt>
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @output(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
store i8* %7, i8** %4
%8 = load i8*, i8** %2
%9 = load i8*, i8** %2
%10 = call i32 @strlen(i8* %9)
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %8, i64 %11
%13 = getelementptr inbounds i8, i8* %12, i64 -1
store i8* %13, i8** %3
%14 = call i64 @malloc(i32 120)
%15 = inttoptr i64 %14 to i8*
store i8* %15, i8** %5
%16 = load i8*, i8** %5
%17 = getelementptr inbounds i8, i8* %16, i64 15
store i8* %17, i8** %5
%18 = load i8*, i8** %5
store i8 0, i8* %18
%19 = load i8*, i8** %5
%20 = getelementptr inbounds i8, i8* %19, i32 -1
store i8* %20, i8** %5
br label %21
21: ; preds = %27, %1
%22 = load i8*, i8** %3
%23 = getelementptr inbounds i8, i8* %22, i32 -1
store i8* %23, i8** %3
%24 = load i8, i8* %22
%25 = sext i8 %24 to i32
%26 = icmp ne i32 %25, 46
br i1 %26, label %27, label %28
27: ; preds = %21
br label %21
28: ; preds = %21
%29 = load i8*, i8** %3
%30 = load i8*, i8** %4
%31 = ptrtoint i8* %29 to i64
%32 = ptrtoint i8* %30 to i64
%33 = sub i64 %31, %32
%34 = add nsw i64 %33, 1
%35 = mul i64 8, %34
%36 = trunc i64 %35 to i32
%37 = call i64 @malloc(i32 %36)
%38 = inttoptr i64 %37 to i8*
store i8* %38, i8** %6
%39 = load i8*, i8** %4
%40 = load i8*, i8** %6
%41 = load i8*, i8** %3
%42 = load i8*, i8** %4
%43 = ptrtoint i8* %41 to i64
%44 = ptrtoint i8* %42 to i64
%45 = sub i64 %43, %44
%46 = trunc i64 %45 to i32
%47 = call i32 @strncpy(i8* %39, i8* %40, i32 %46)
%48 = load i8*, i8** %6
ret i8* %48
}

LLVM IR (-O2):
define i8* @output(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = sext i32 %2 to i64
%4 = getelementptr inbounds i8, i8* %0, i64 %3
%5 = getelementptr inbounds i8, i8* %4, i64 -1
%6 = tail call i64 @malloc(i32 120)
%7 = inttoptr i64 %6 to i8*
%8 = getelementptr inbounds i8, i8* %7, i64 15
store i8 0, i8* %8
br label %9
9: ; preds = %9, %1
%10 = phi i8* [ %5, %1 ], [ %11, %9 ]
%11 = getelementptr inbounds i8, i8* %10, i64 -1
%12 = load i8, i8* %10
%13 = icmp eq i8 %12, 46
br i1 %13, label %14, label %9
14: ; preds = %9
%15 = ptrtoint i8* %11 to i64
%16 = ptrtoint i8* %0 to i64
%17 = sub i64 %15, %16
%18 = trunc i64 %17 to i32
%19 = shl i32 %18, 3
%20 = add i32 %19, 8
%21 = tail call i64 @malloc(i32 %20)
%22 = inttoptr i64 %21 to i8*
%23 = tail call i32 @strncpy(i8* %0, i8* %22, i32 %18)
ret i8* %22
}