#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 detect_filetype(char *filename) {
  int i;
  for (i = 0; i < strlen(filename); i++) {
    if (filename[i] == '.' &&
        (filename[i + 1] == 's' || filename[i + 1] == 'i')) {
      return filename[i + 1];
    }
  }
  return 'n';
}


x86 assembly (clang, -O0):
<detect_filetype>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
cmp    %ecx,%eax
jge    11b3 <detect_filetype+0xa3>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2e,%eax
jne    11a0 <detect_filetype+0x90>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x73,%eax
je     1188 <detect_filetype+0x78>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x69,%eax
jne    11a0 <detect_filetype+0x90>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x1(%rbp)
jmp    11b7 <detect_filetype+0xa7>
jmp    11a5 <detect_filetype+0x95>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1123 <detect_filetype+0x13>
movb   $0x6e,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<detect_filetype>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1030 <strlen@plt>
test   %eax,%eax
jle    115a <detect_filetype+0x4a>
xor    %ebx,%ebx
jmp    1143 <detect_filetype+0x33>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%rbx
mov    %r14,%rdi
call   1030 <strlen@plt>
cltq
cmp    %rax,%rbx
jge    115a <detect_filetype+0x4a>
cmpb   $0x2e,(%r14,%rbx,1)
jne    1130 <detect_filetype+0x20>
movzbl 0x1(%r14,%rbx,1),%eax
cmp    $0x69,%al
je     115c <detect_filetype+0x4c>
cmp    $0x73,%al
jne    1130 <detect_filetype+0x20>
jmp    115c <detect_filetype+0x4c>
mov    $0x6e,%al
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define signext i8 @detect_filetype(i8* %0) {
%2 = alloca i8
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
store i32 0, i32* %4
br label %5
5: ; preds = %44, %1
%6 = load i32, i32* %4
%7 = load i8*, i8** %3
%8 = call i32 @strlen(i8* %7)
%9 = icmp slt i32 %6, %8
br i1 %9, label %10, label %47
10: ; preds = %5
%11 = load i8*, i8** %3
%12 = load i32, i32* %4
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %11, i64 %13
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp eq i32 %16, 46
br i1 %17, label %18, label %43
18: ; preds = %10
%19 = load i8*, i8** %3
%20 = load i32, i32* %4
%21 = add nsw i32 %20, 1
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %19, i64 %22
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %25, 115
br i1 %26, label %36, label %27
27: ; preds = %18
%28 = load i8*, i8** %3
%29 = load i32, i32* %4
%30 = add nsw i32 %29, 1
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %28, i64 %31
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = icmp eq i32 %34, 105
br i1 %35, label %36, label %43
36: ; preds = %27, %18
%37 = load i8*, i8** %3
%38 = load i32, i32* %4
%39 = add nsw i32 %38, 1
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %37, i64 %40
%42 = load i8, i8* %41
store i8 %42, i8* %2
br label %48
43: ; preds = %27, %10
br label %44
44: ; preds = %43
%45 = load i32, i32* %4
%46 = add nsw i32 %45, 1
store i32 %46, i32* %4
br label %5
47: ; preds = %5
store i8 110, i8* %2
br label %48
48: ; preds = %47, %36
%49 = load i8, i8* %2
ret i8 %49
}

LLVM IR (-O2):
define signext i8 @detect_filetype(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = icmp sgt i32 %2, 0
br i1 %3, label %4, label %17
4: ; preds = %1, %13
%5 = phi i64 [ %9, %13 ], [ 0, %1 ]
%6 = getelementptr inbounds i8, i8* %0, i64 %5
%7 = load i8, i8* %6
%8 = icmp eq i8 %7, 46
%9 = add nuw nsw i64 %5, 1
br i1 %8, label %10, label %13
10: ; preds = %4
%11 = getelementptr inbounds i8, i8* %0, i64 %9
%12 = load i8, i8* %11
switch i8 %12, label %13 [
i8 115, label %17
i8 105, label %17
]
13: ; preds = %4, %10
%14 = tail call i32 @strlen(i8* %0)
%15 = sext i32 %14 to i64
%16 = icmp slt i64 %9, %15
br i1 %16, label %4, label %17
17: ; preds = %13, %10, %10, %1
%18 = phi i8 [ 110, %1 ], [ %12, %10 ], [ %12, %10 ], [ 110, %13 ]
ret i8 %18
}