#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 */
int strlen(char *);
char *search_ext(char *file_name) {
  int len;
  char *ext;
  ext = file_name + strlen(file_name) - 1;
  while (ext != file_name) {
    if (*ext == '/') {
      ext = NULL;
      break;
    } else if (*ext == '.') {
      ext++;
      break;
    }
    ext--;
  }
  return ext;
}


x86 assembly (clang, -O0):
<search_ext>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x8(%rbp),%rax
je     11a3 <search_ext+0x93>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    116c <search_ext+0x5c>
movq   $0x0,-0x18(%rbp)
jmp    11a3 <search_ext+0x93>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    118d <search_ext+0x7d>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    11a3 <search_ext+0x93>
jmp    1192 <search_ext+0x82>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    1141 <search_ext+0x31>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<search_ext>:
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
cltq
nopl   0x0(%rax,%rax,1)
cmp    $0x1,%rax
je     1144 <search_ext+0x34>
movzbl -0x1(%rbx,%rax,1),%ecx
add    $0xffffffffffffffff,%rax
cmp    $0x2e,%cl
je     113d <search_ext+0x2d>
cmp    $0x2f,%cl
jne    1120 <search_ext+0x10>
xor    %ebx,%ebx
jmp    1144 <search_ext+0x34>
add    %rax,%rbx
add    $0x1,%rbx
mov    %rbx,%rax
pop    %rbx
ret

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

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