void modify_filename_extention(buffer, ext) char *buffer;
char *ext;
{
  register char *p, *dot;
  for (p = buffer, dot = (char *)0; *p; p++) {
    if (*p == '.')
      dot = p;
    else if (*p == '/')
      dot = (char *)0;
  }
  if (dot)
    p = dot;
  strcpy(p, ext);
}


x86 assembly (clang, -O0):
<modify_filename_extention>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
je     118d <modify_filename_extention+0x7d>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    115a <modify_filename_extention+0x4a>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    1177 <modify_filename_extention+0x67>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    1172 <modify_filename_extention+0x62>
movq   $0x0,-0x20(%rbp)
jmp    1177 <modify_filename_extention+0x67>
jmp    117c <modify_filename_extention+0x6c>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1130 <modify_filename_extention+0x20>
cmpq   $0x0,-0x20(%rbp)
je     11a0 <modify_filename_extention+0x90>
mov    -0x20(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<modify_filename_extention>:
xor    %eax,%eax
jmp    1129 <modify_filename_extention+0x19>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %ecx,%ecx
add    $0x1,%rdi
mov    %rcx,%rax
movzbl (%rdi),%edx
mov    %rdi,%rcx
cmp    $0x2e,%dl
je     1122 <modify_filename_extention+0x12>
cmp    $0x2f,%dl
je     1120 <modify_filename_extention+0x10>
test   %dl,%dl
je     1142 <modify_filename_extention+0x32>
mov    %rax,%rcx
jmp    1122 <modify_filename_extention+0x12>
test   %rax,%rax
cmovne %rax,%rdi
jmp    1030 <strcpy@plt>

LLVM IR (-O0):
define void @modify_filename_extention(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%7 = load i8*, i8** %3
store i8* %7, i8** %5
store i8* null, i8** %6
br label %8
8: ; preds = %27, %2
%9 = load i8*, i8** %5
%10 = load i8, i8* %9
%11 = icmp ne i8 %10, 0
br i1 %11, label %12, label %30
12: ; preds = %8
%13 = load i8*, i8** %5
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp eq i32 %15, 46
br i1 %16, label %17, label %19
17: ; preds = %12
%18 = load i8*, i8** %5
store i8* %18, i8** %6
br label %26
19: ; preds = %12
%20 = load i8*, i8** %5
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp eq i32 %22, 47
br i1 %23, label %24, label %25
24: ; preds = %19
store i8* null, i8** %6
br label %25
25: ; preds = %24, %19
br label %26
26: ; preds = %25, %17
br label %27
27: ; preds = %26
%28 = load i8*, i8** %5
%29 = getelementptr inbounds i8, i8* %28, i32 1
store i8* %29, i8** %5
br label %8
30: ; preds = %8
%31 = load i8*, i8** %6
%32 = icmp ne i8* %31, null
br i1 %32, label %33, label %35
33: ; preds = %30
%34 = load i8*, i8** %6
store i8* %34, i8** %5
br label %35
35: ; preds = %33, %30
%36 = load i8*, i8** %5
%37 = load i8*, i8** %4
%38 = call i8* @strcpy(i8* %36, i8* %37)
ret void
}

LLVM IR (-O2):
define void @modify_filename_extention(i8* %0, i8* nocapture %1) {
br label %3
3: ; preds = %9, %2
%4 = phi i8* [ %0, %2 ], [ %11, %9 ]
%5 = phi i8* [ null, %2 ], [ %10, %9 ]
%6 = load i8, i8* %4
switch i8 %6, label %8 [
i8 0, label %12
i8 46, label %9
i8 47, label %7
]
7: ; preds = %3
br label %9
8: ; preds = %3
br label %9
9: ; preds = %3, %8, %7
%10 = phi i8* [ null, %7 ], [ %4, %3 ], [ %5, %8 ]
%11 = getelementptr inbounds i8, i8* %4, i64 1
br label %3
12: ; preds = %3
%13 = icmp eq i8* %5, null
%14 = select i1 %13, i8* %4, i8* %5
%15 = tail call i8* @strcpy(i8* %14, i8* dereferenceable(1) %1)
ret void
}