#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 */
scalar_t__ strcmp(char *, char *);
char *strrchr(char *, char);
int get_filetype_by_suffix(char *name) {
  char *ext = strrchr(name, '.');
  if (ext == NULL) {
    return 0;
  }
  if (strcmp(ext, ".c") == 0)
    return 1;
  if (strcmp(ext, ".i") == 0)
    return 2;
  if (strcmp(ext, ".asm") == 0)
    return 3;
  if (strcmp(ext, ".opt") == 0)
    return 4;
  return 0;
}


x86 assembly (clang, -O0):
<get_filetype_by_suffix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2e,%esi
call   1030 <strrchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1155 <get_filetype_by_suffix+0x35>
movl   $0x0,-0x4(%rbp)
jmp    11f4 <get_filetype_by_suffix+0xd4>
mov    -0x18(%rbp),%rdi
lea    0xea0(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    117b <get_filetype_by_suffix+0x5b>
movl   $0x1,-0x4(%rbp)
jmp    11f4 <get_filetype_by_suffix+0xd4>
mov    -0x18(%rbp),%rdi
lea    0xe7d(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11a1 <get_filetype_by_suffix+0x81>
movl   $0x2,-0x4(%rbp)
jmp    11f4 <get_filetype_by_suffix+0xd4>
mov    -0x18(%rbp),%rdi
lea    0xe5a(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11c7 <get_filetype_by_suffix+0xa7>
movl   $0x3,-0x4(%rbp)
jmp    11f4 <get_filetype_by_suffix+0xd4>
mov    -0x18(%rbp),%rdi
lea    0xe39(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11ed <get_filetype_by_suffix+0xcd>
movl   $0x4,-0x4(%rbp)
jmp    11f4 <get_filetype_by_suffix+0xd4>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_filetype_by_suffix>:
push   %rbx
mov    $0x2e,%esi
call   1030 <strrchr@plt>
test   %rax,%rax
je     118e <get_filetype_by_suffix+0x6e>
mov    %rax,%rbx
lea    0xec6(%rip),%rsi
mov    %rax,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
je     1192 <get_filetype_by_suffix+0x72>
lea    0xeb5(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
je     1199 <get_filetype_by_suffix+0x79>
lea    0xea4(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
je     11a0 <get_filetype_by_suffix+0x80>
lea    0xe95(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
sete   %al
shl    $0x2,%eax
pop    %rbx
ret
xor    %eax,%eax
pop    %rbx
ret
mov    $0x1,%eax
pop    %rbx
ret
mov    $0x2,%eax
pop    %rbx
ret
mov    $0x3,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [3 x i8] c".c\00"
@.str.1 = [3 x i8] c".i\00"
@.str.2 = [5 x i8] c".asm\00"
@.str.3 = [5 x i8] c".opt\00"
define i32 @get_filetype_by_suffix(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = call i8* @strrchr(i8* %5, i8 signext 46)
store i8* %6, i8** %4
%7 = load i8*, i8** %4
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %10
9: ; preds = %1
store i32 0, i32* %2
br label %31
10: ; preds = %1
%11 = load i8*, i8** %4
%12 = call i64 @strcmp(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %10
store i32 1, i32* %2
br label %31
15: ; preds = %10
%16 = load i8*, i8** %4
%17 = call i64 @strcmp(i8* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %15
store i32 2, i32* %2
br label %31
20: ; preds = %15
%21 = load i8*, i8** %4
%22 = call i64 @strcmp(i8* %21, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %20
store i32 3, i32* %2
br label %31
25: ; preds = %20
%26 = load i8*, i8** %4
%27 = call i64 @strcmp(i8* %26, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %25
store i32 4, i32* %2
br label %31
30: ; preds = %25
store i32 0, i32* %2
br label %31
31: ; preds = %30, %29, %24, %19, %14, %9
%32 = load i32, i32* %2
ret i32 %32
}

LLVM IR (-O2):
@.str = [3 x i8] c".c\00"
@.str.1 = [3 x i8] c".i\00"
@.str.2 = [5 x i8] c".asm\00"
@.str.3 = [5 x i8] c".opt\00"
define i32 @get_filetype_by_suffix(i8* %0) {
%2 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 46)
%3 = icmp eq i8* %2, null
br i1 %3, label %17, label %4
4: ; preds = %1
%5 = tail call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i64 %5, 0
br i1 %6, label %17, label %7
7: ; preds = %4
%8 = tail call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%9 = icmp eq i64 %8, 0
br i1 %9, label %17, label %10
10: ; preds = %7
%11 = tail call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%12 = icmp eq i64 %11, 0
br i1 %12, label %17, label %13
13: ; preds = %10
%14 = tail call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%15 = icmp eq i64 %14, 0
%16 = select i1 %15, i32 4, i32 0
br label %17
17: ; preds = %13, %10, %7, %4, %1
%18 = phi i32 [ 0, %1 ], [ 1, %4 ], [ 2, %7 ], [ 3, %10 ], [ %16, %13 ]
ret i32 %18
}