int test_fext(void) {
  char *ext;
  ext = fext("somefile.beforeext.ext");
  do {
    if (!(strcmp(ext, "ext") == 0)) {
      printf("%sERROR!%s [%s:%d] %s %sFAILED!%s\n", "\x1B[1;31m", "\x1B[1;0m",
             __func__, 287, "strcmp(ext, \"ext\") == 0", "\x1B[1;31m",
             "\x1B[1;0m");
      return -1;
    }
  } while (0);
  free(ext);
  return 0;
}


x86 assembly (clang, -O0):
<test_fext>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xeb1(%rip),%rdi
mov    $0x0,%al
call   1060 <fext@plt>
cltq
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xeac(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
je     11c0 <test_fext+0x80>
lea    0xe9b(%rip),%rdi
lea    0xeb7(%rip),%r10
lea    0xeb8(%rip),%rax
lea    0xeb8(%rip),%rcx
mov    $0x11f,%r8d
lea    0xeb5(%rip),%r9
mov    %r10,%rsi
mov    %rax,%rdx
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d5 <test_fext+0x95>
jmp    11c5 <test_fext+0x85>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_fext>:
push   %rbp
push   %rbx
push   %rax
lea    0xeb6(%rip),%rdi
xor    %ebp,%ebp
xor    %eax,%eax
call   1060 <fext@plt>
movslq %eax,%rbx
lea    0xeb6(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcmp@plt>
test   %eax,%eax
je     11a6 <test_fext+0x66>
lea    0xed2(%rip),%rdx
lea    0xec3(%rip),%rsi
lea    0xe99(%rip),%rdi
lea    0xec4(%rip),%rcx
lea    0xec7(%rip),%r9
mov    $0x11f,%r8d
xor    %eax,%eax
push   %rdx
push   %rsi
call   1040 <printf@plt>
add    $0x10,%rsp
mov    $0xffffffff,%ebp
jmp    11ae <test_fext+0x6e>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [23 x i8] c"somefile.beforeext.ext\00"
@.str.1 = [4 x i8] c"ext\00"
@.str.2 = [35 x i8] c"%sERROR!%s [%s:%d] %s %sFAILED!%s\0A\00"
@.str.3 = [8 x i8] c"\1B[1;31m\00"
@.str.4 = [7 x i8] c"\1B[1;0m\00"
@__func__.test_fext = [10 x i8] c"test_fext\00"
@.str.5 = [24 x i8] c"strcmp(ext, \22ext\22) == 0\00"
define i32 @test_fext() {
%1 = alloca i32
%2 = alloca i8*
%3 = call i32 (i8*, ...) bitcast (i32 (...)* @fext to i32 (i8*, ...)*)(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%4 = sext i32 %3 to i64
%5 = inttoptr i64 %4 to i8*
store i8* %5, i8** %2
br label %6
6: ; preds = %0
%7 = load i8*, i8** %2
%8 = call i32 @strcmp(i8* %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%9 = icmp eq i32 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %6
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @__func__.test_fext, i64 0, i64 0), i32 287, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
store i32 -1, i32* %1
br label %15
12: ; preds = %6
br label %13
13: ; preds = %12
%14 = load i8*, i8** %2
store i32 0, i32* %1
br label %15
15: ; preds = %13, %10
%16 = load i32, i32* %1
ret i32 %16
}

LLVM IR (-O2):
@.str = [23 x i8] c"somefile.beforeext.ext\00"
@.str.1 = [4 x i8] c"ext\00"
@.str.2 = [35 x i8] c"%sERROR!%s [%s:%d] %s %sFAILED!%s\0A\00"
@.str.3 = [8 x i8] c"\1B[1;31m\00"
@.str.4 = [7 x i8] c"\1B[1;0m\00"
@__func__.test_fext = [10 x i8] c"test_fext\00"
@.str.5 = [24 x i8] c"strcmp(ext, \22ext\22) == 0\00"
define i32 @test_fext() {
%1 = tail call i32 (i8*, ...) bitcast (i32 (...)* @fext to i32 (i8*, ...)*)(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%2 = sext i32 %1 to i64
%3 = inttoptr i64 %2 to i8*
%4 = tail call i32 @strcmp(i8* dereferenceable(1) %3, i8* dereferenceable(4) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%5 = icmp eq i32 %4, 0
br i1 %5, label %8, label %6
6: ; preds = %0
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @__func__.test_fext, i64 0, i64 0), i32 287, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
br label %9
8: ; preds = %0
tail call void @free(i8* %3)
br label %9
9: ; preds = %8, %6
%10 = phi i32 [ 0, %8 ], [ -1, %6 ]
ret i32 %10
}