char *filename_ext(char *infile) {
  char ext[] = "hex";
  static char fixed_filename[255];
  int i, dot;
  dot = 0;
  i = 0;
  while (*infile) {
    if (*infile == '.')
      dot = i;
    fixed_filename[i++] = *infile++;
  }
  dot++;
  for (i = 0; i < 4; i++)
    fixed_filename[i + dot] = ext[i];
  return &fixed_filename[0];
}


x86 assembly (clang, -O0):
<filename_ext>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    0xef2(%rip),%eax
mov    %eax,-0xc(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     1170 <filename_ext+0x70>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    1142 <filename_ext+0x42>
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%dl
mov    -0x10(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x10(%rbp)
movslq %eax,%rcx
lea    0x2ec8(%rip),%rax
mov    %dl,(%rax,%rcx,1)
jmp    111f <filename_ext+0x1f>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x4,-0x10(%rbp)
jge    11b3 <filename_ext+0xb3>
movslq -0x10(%rbp),%rax
mov    -0xc(%rbp,%rax,1),%dl
mov    -0x10(%rbp),%eax
add    -0x14(%rbp),%eax
movslq %eax,%rcx
lea    0x2e8e(%rip),%rax
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1180 <filename_ext+0x80>
lea    0x2e76(%rip),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<filename_ext>:
xor    %ecx,%ecx
lea    0x2f27(%rip),%rax
xor    %esi,%esi
jmp    1119 <filename_ext+0x19>
nopl   (%rax)
mov    %ecx,%esi
mov    %dl,(%rcx,%rax,1)
add    $0x1,%rcx
movzbl (%rdi,%rcx,1),%edx
cmp    $0x2e,%dl
je     1110 <filename_ext+0x10>
test   %dl,%dl
jne    1112 <filename_ext+0x12>
add    $0x1,%esi
movslq %esi,%rcx
movl   $0x786568,(%rcx,%rax,1)
ret

LLVM IR (-O0):
@__const.filename_ext.ext = [4 x i8] c"hex\00"
@filename_ext.fixed_filename = internal global [255 x i8] zeroinitializer
define i8* @filename_ext(i8* %0) {
%2 = alloca i8*
%3 = alloca [4 x i8]
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %2
%6 = bitcast [4 x i8]* %3 to i8*
store i32 0, i32* %5
store i32 0, i32* %4
br label %7
7: ; preds = %18, %1
%8 = load i8*, i8** %2
%9 = load i8, i8* %8
%10 = icmp ne i8 %9, 0
br i1 %10, label %11, label %26
11: ; preds = %7
%12 = load i8*, i8** %2
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp eq i32 %14, 46
br i1 %15, label %16, label %18
16: ; preds = %11
%17 = load i32, i32* %4
store i32 %17, i32* %5
br label %18
18: ; preds = %16, %11
%19 = load i8*, i8** %2
%20 = getelementptr inbounds i8, i8* %19, i32 1
store i8* %20, i8** %2
%21 = load i8, i8* %19
%22 = load i32, i32* %4
%23 = add nsw i32 %22, 1
store i32 %23, i32* %4
%24 = sext i32 %22 to i64
%25 = getelementptr inbounds [255 x i8], [255 x i8]* @filename_ext.fixed_filename, i64 0, i64 %24
store i8 %21, i8* %25
br label %7
26: ; preds = %7
%27 = load i32, i32* %5
%28 = add nsw i32 %27, 1
store i32 %28, i32* %5
store i32 0, i32* %4
br label %29
29: ; preds = %42, %26
%30 = load i32, i32* %4
%31 = icmp slt i32 %30, 4
br i1 %31, label %32, label %45
32: ; preds = %29
%33 = load i32, i32* %4
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 %34
%36 = load i8, i8* %35
%37 = load i32, i32* %4
%38 = load i32, i32* %5
%39 = add nsw i32 %37, %38
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [255 x i8], [255 x i8]* @filename_ext.fixed_filename, i64 0, i64 %40
store i8 %36, i8* %41
br label %42
42: ; preds = %32
%43 = load i32, i32* %4
%44 = add nsw i32 %43, 1
store i32 %44, i32* %4
br label %29
45: ; preds = %29
ret i8* getelementptr inbounds ([255 x i8], [255 x i8]* @filename_ext.fixed_filename, i64 0, i64 0)
}

LLVM IR (-O2):
@filename_ext.fixed_filename = internal global [255 x i8] zeroinitializer
define i8* @filename_ext(i8* nocapture %0) {
br label %2
2: ; preds = %9, %1
%3 = phi i64 [ %12, %9 ], [ 0, %1 ]
%4 = phi i8* [ %11, %9 ], [ %0, %1 ]
%5 = phi i32 [ %10, %9 ], [ 0, %1 ]
%6 = load i8, i8* %4
switch i8 %6, label %9 [
i8 0, label %14
i8 46, label %7
]
7: ; preds = %2
%8 = trunc i64 %3 to i32
br label %9
9: ; preds = %2, %7
%10 = phi i32 [ %8, %7 ], [ %5, %2 ]
%11 = getelementptr inbounds i8, i8* %4, i64 1
%12 = add nuw i64 %3, 1
%13 = getelementptr inbounds [255 x i8], [255 x i8]* @filename_ext.fixed_filename, i64 0, i64 %3
store i8 %6, i8* %13
br label %2
14: ; preds = %2
%15 = add i32 %5, 1
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [255 x i8], [255 x i8]* @filename_ext.fixed_filename, i64 0, i64 %16
store i8 104, i8* %17
%18 = add i32 %5, 2
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [255 x i8], [255 x i8]* @filename_ext.fixed_filename, i64 0, i64 %19
store i8 101, i8* %20
%21 = add i32 %5, 3
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [255 x i8], [255 x i8]* @filename_ext.fixed_filename, i64 0, i64 %22
store i8 120, i8* %23
%24 = add i32 %5, 4
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [255 x i8], [255 x i8]* @filename_ext.fixed_filename, i64 0, i64 %25
store i8 0, i8* %26
ret i8* getelementptr inbounds ([255 x i8], [255 x i8]* @filename_ext.fixed_filename, i64 0, i64 0)
}