#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 *malloc(int);
int /*<<< orphan*/ memcpy(char *, char const *, int);
int strlen(char const *);
char *fill_output_filename(const char *infile, char function) {
  int copylen, alloclen;
  char *outfile;
  copylen = strlen(infile);
  if (infile[copylen - 2] == '.' && infile[copylen - 1] == 'e' &&
      function == 'd') {
    copylen -= 2;
    alloclen = copylen;
  } else {
    alloclen = copylen + 2;
  }
  outfile = malloc(alloclen + 1);
  memcpy(outfile, infile, copylen);
  if (alloclen > copylen) {
    outfile[copylen] = '.';
    outfile[copylen + 1] = function;
  }
  outfile[alloclen] = '\0';
  return outfile;
}


x86 assembly (clang, -O0):
<fill_output_filename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
sub    $0x2,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2e,%eax
jne    11a3 <fill_output_filename+0x73>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x65,%eax
jne    11a3 <fill_output_filename+0x73>
movsbl -0x9(%rbp),%eax
cmp    $0x64,%eax
jne    11a3 <fill_output_filename+0x73>
mov    -0x10(%rbp),%eax
sub    $0x2,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    11ac <fill_output_filename+0x7c>
mov    -0x10(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
add    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%edx
call   1040 <memcpy@plt>
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
jle    11f6 <fill_output_filename+0xc6>
mov    -0x20(%rbp),%rax
movslq -0x10(%rbp),%rcx
movb   $0x2e,(%rax,%rcx,1)
mov    -0x9(%rbp),%dl
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fill_output_filename>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r14d
mov    %rdi,%r15
call   1030 <strlen@plt>
mov    %eax,%r12d
movslq %eax,%rbp
cmpb   $0x2e,-0x2(%r15,%rbp,1)
jne    1168 <fill_output_filename+0x38>
cmp    $0x64,%r14b
jne    1168 <fill_output_filename+0x38>
cmpb   $0x65,-0x1(%rbp,%r15,1)
jne    1168 <fill_output_filename+0x38>
add    $0xfffffffffffffffe,%rbp
mov    %ebp,%r12d
jmp    116e <fill_output_filename+0x3e>
mov    %r12d,%ebp
add    $0x2,%ebp
lea    0x1(%rbp),%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
mov    %r12d,%edx
call   1040 <memcpy@plt>
cmp    %r12d,%ebp
jle    1198 <fill_output_filename+0x68>
movslq %r12d,%rax
movb   $0x2e,(%rbx,%rax,1)
mov    %r14b,0x1(%rbx,%rax,1)
movslq %ebp,%rax
movb   $0x0,(%rbx,%rax,1)
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @fill_output_filename(i8* %0, i8 signext %1) {
%3 = alloca i8*
%4 = alloca i8
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
store i8* %0, i8** %3
store i8 %1, i8* %4
%8 = load i8*, i8** %3
%9 = call i32 @strlen(i8* %8)
store i32 %9, i32* %5
%10 = load i8*, i8** %3
%11 = load i32, i32* %5
%12 = sub nsw i32 %11, 2
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %10, i64 %13
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp eq i32 %16, 46
br i1 %17, label %18, label %35
18: ; preds = %2
%19 = load i8*, i8** %3
%20 = load i32, i32* %5
%21 = sub nsw i32 %20, 1
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %19, i64 %22
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %25, 101
br i1 %26, label %27, label %35
27: ; preds = %18
%28 = load i8, i8* %4
%29 = sext i8 %28 to i32
%30 = icmp eq i32 %29, 100
br i1 %30, label %31, label %35
31: ; preds = %27
%32 = load i32, i32* %5
%33 = sub nsw i32 %32, 2
store i32 %33, i32* %5
%34 = load i32, i32* %5
store i32 %34, i32* %6
br label %38
35: ; preds = %27, %18, %2
%36 = load i32, i32* %5
%37 = add nsw i32 %36, 2
store i32 %37, i32* %6
br label %38
38: ; preds = %35, %31
%39 = load i32, i32* %6
%40 = add nsw i32 %39, 1
%41 = call i8* @malloc(i32 %40)
store i8* %41, i8** %7
%42 = load i8*, i8** %7
%43 = load i8*, i8** %3
%44 = load i32, i32* %5
%45 = call i32 @memcpy(i8* %42, i8* %43, i32 %44)
%46 = load i32, i32* %6
%47 = load i32, i32* %5
%48 = icmp sgt i32 %46, %47
br i1 %48, label %49, label %60
49: ; preds = %38
%50 = load i8*, i8** %7
%51 = load i32, i32* %5
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i8, i8* %50, i64 %52
store i8 46, i8* %53
%54 = load i8, i8* %4
%55 = load i8*, i8** %7
%56 = load i32, i32* %5
%57 = add nsw i32 %56, 1
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i8, i8* %55, i64 %58
store i8 %54, i8* %59
br label %60
60: ; preds = %49, %38
%61 = load i8*, i8** %7
%62 = load i32, i32* %6
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds i8, i8* %61, i64 %63
store i8 0, i8* %64
%65 = load i8*, i8** %7
ret i8* %65
}

LLVM IR (-O2):
define i8* @fill_output_filename(i8* %0, i8 signext %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = add nsw i32 %3, -2
%5 = sext i32 %4 to i64
%6 = getelementptr inbounds i8, i8* %0, i64 %5
%7 = load i8, i8* %6
%8 = icmp eq i8 %7, 46
br i1 %8, label %9, label %17
9: ; preds = %2
%10 = add nsw i32 %3, -1
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %0, i64 %11
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 101
%15 = icmp eq i8 %1, 100
%16 = and i1 %15, %14
br i1 %16, label %19, label %17
17: ; preds = %9, %2
%18 = add nsw i32 %3, 2
br label %19
19: ; preds = %9, %17
%20 = phi i32 [ %18, %17 ], [ %4, %9 ]
%21 = phi i32 [ %3, %17 ], [ %4, %9 ]
%22 = add nsw i32 %20, 1
%23 = tail call i8* @malloc(i32 %22)
%24 = tail call i32 @memcpy(i8* %23, i8* %0, i32 %21)
%25 = icmp sgt i32 %20, %21
br i1 %25, label %26, label %32
26: ; preds = %19
%27 = sext i32 %21 to i64
%28 = getelementptr inbounds i8, i8* %23, i64 %27
store i8 46, i8* %28
%29 = add nsw i32 %21, 1
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %23, i64 %30
store i8 %1, i8* %31
br label %32
32: ; preds = %26, %19
%33 = sext i32 %20 to i64
%34 = getelementptr inbounds i8, i8* %23, i64 %33
store i8 0, i8* %34
ret i8* %23
}