#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 */
typedef int /*<<< orphan*/ suffix;

/* Variables and functions */
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
char *get_suffix(char *file) {
  int i = 0;
  const char *s = file;
  static char suffix[4];
  int found = 0;
  memset(suffix, 0, sizeof(suffix));
  while (*s++ != '\0') {
    if (found && i < 3)
      suffix[i++] = *s;
    if (*s == '.') {
      if (found) {
        found = 0;
        break;
      }
      found = 1;
    }
  }
  if (!found)
    suffix[0] = 0;
  return suffix;
}


x86 assembly (clang, -O0):
<get_suffix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
lea    0x2ef0(%rip),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1030 <memset@plt>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11c4 <get_suffix+0xb4>
cmpl   $0x0,-0x1c(%rbp)
je     1192 <get_suffix+0x82>
cmpl   $0x3,-0xc(%rbp)
jge    1192 <get_suffix+0x82>
mov    -0x18(%rbp),%rax
mov    (%rax),%dl
mov    -0xc(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0xc(%rbp)
movslq %eax,%rcx
lea    0x2e9a(%rip),%rax
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    11bf <get_suffix+0xaf>
cmpl   $0x0,-0x1c(%rbp)
je     11b8 <get_suffix+0xa8>
movl   $0x0,-0x1c(%rbp)
jmp    11c4 <get_suffix+0xb4>
movl   $0x1,-0x1c(%rbp)
jmp    1145 <get_suffix+0x35>
cmpl   $0x0,-0x1c(%rbp)
jne    11d5 <get_suffix+0xc5>
movb   $0x0,0x2e54(%rip)
lea    0x2e4d(%rip),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_suffix>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
lea    0x2f0b(%rip),%r14
xor    %ebp,%ebp
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1030 <memset@plt>
mov    (%rbx),%cl
add    $0x1,%rbx
xor    %edx,%edx
nopw   0x0(%rax,%rax,1)
mov    %edx,%eax
test   %cl,%cl
je     1176 <get_suffix+0x66>
test   %eax,%eax
je     115c <get_suffix+0x4c>
cmp    $0x2,%ebp
jg     115c <get_suffix+0x4c>
movzbl (%rbx),%ecx
movslq %ebp,%rdx
add    $0x1,%ebp
mov    %cl,(%rdx,%r14,1)
movzbl (%rbx),%ecx
add    $0x1,%rbx
mov    $0x1,%edx
cmp    $0x2e,%cl
cmovne %eax,%edx
jne    1140 <get_suffix+0x30>
test   %eax,%eax
je     1140 <get_suffix+0x30>
jmp    117a <get_suffix+0x6a>
test   %eax,%eax
jne    1181 <get_suffix+0x71>
movb   $0x0,0x2ea8(%rip)
lea    0x2ea1(%rip),%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
@get_suffix.suffix = internal global [4 x i8] zeroinitializer
define i8* @get_suffix(i8* nocapture %0) {
%2 = tail call i32 @memset(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @get_suffix.suffix, i64 0, i64 0), i32 0, i32 4)
%3 = load i8, i8* %0
br label %4
4: ; preds = %20, %1
%5 = phi i8 [ %3, %1 ], [ %22, %20 ]
%6 = phi i32 [ 0, %1 ], [ %21, %20 ]
%7 = phi i8* [ %0, %1 ], [ %9, %20 ]
%8 = phi i32 [ 0, %1 ], [ %26, %20 ]
%9 = getelementptr inbounds i8, i8* %7, i64 1
%10 = icmp eq i8 %5, 0
br i1 %10, label %27, label %11
11: ; preds = %4
%12 = icmp ne i32 %8, 0
%13 = icmp slt i32 %6, 3
%14 = select i1 %12, i1 %13, i1 false
br i1 %14, label %15, label %20
15: ; preds = %11
%16 = load i8, i8* %9
%17 = add nsw i32 %6, 1
%18 = sext i32 %6 to i64
%19 = getelementptr inbounds [4 x i8], [4 x i8]* @get_suffix.suffix, i64 0, i64 %18
store i8 %16, i8* %19
br label %20
20: ; preds = %15, %11
%21 = phi i32 [ %17, %15 ], [ %6, %11 ]
%22 = load i8, i8* %9
%23 = icmp ne i8 %22, 46
%24 = xor i1 %12, true
%25 = select i1 %23, i1 true, i1 %24
%26 = select i1 %23, i32 %8, i32 1
br i1 %25, label %4, label %29
27: ; preds = %4
%28 = icmp eq i32 %8, 0
br i1 %28, label %29, label %30
29: ; preds = %20, %27
store i8 0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @get_suffix.suffix, i64 0, i64 0)
br label %30
30: ; preds = %29, %27
ret i8* getelementptr inbounds ([4 x i8], [4 x i8]* @get_suffix.suffix, i64 0, i64 0)
}