#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 get_file_type(char *file) {
  unsigned int i;
  for (i = 0; i < strlen(file) - 1; i++) {
    if (file[i] == '.' && file[i + 1] == 'b')
      return 'b';
  }
  return 'a';
}


x86 assembly (clang, -O0):
<get_file_type>:
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
sub    $0x1,%ecx
cmp    %ecx,%eax
jae    118b <get_file_type+0x7b>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2e,%eax
jne    1178 <get_file_type+0x68>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,%ecx
movsbl (%rax,%rcx,1),%eax
cmp    $0x62,%eax
jne    1178 <get_file_type+0x68>
movb   $0x62,-0x1(%rbp)
jmp    118f <get_file_type+0x7f>
jmp    117d <get_file_type+0x6d>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1123 <get_file_type+0x13>
movb   $0x61,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_file_type>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    $0x61,%r14b
cmp    $0x1,%eax
je     1154 <get_file_type+0x44>
xor    %ebp,%ebp
jmp    1144 <get_file_type+0x34>
nopl   0x0(%rax,%rax,1)
add    $0x1,%rbp
mov    %rbx,%rdi
call   1030 <strlen@plt>
add    $0xffffffff,%eax
cmp    %rax,%rbp
jae    1154 <get_file_type+0x44>
cmpb   $0x2e,(%rbx,%rbp,1)
jne    1130 <get_file_type+0x20>
cmpb   $0x62,0x1(%rbx,%rbp,1)
jne    1130 <get_file_type+0x20>
mov    $0x62,%r14b
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define signext i8 @get_file_type(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 = %30, %1
%6 = load i32, i32* %4
%7 = load i8*, i8** %3
%8 = call i32 @strlen(i8* %7)
%9 = sub nsw i32 %8, 1
%10 = icmp ult i32 %6, %9
br i1 %10, label %11, label %33
11: ; preds = %5
%12 = load i8*, i8** %3
%13 = load i32, i32* %4
%14 = zext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %12, i64 %14
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp eq i32 %17, 46
br i1 %18, label %19, label %29
19: ; preds = %11
%20 = load i8*, i8** %3
%21 = load i32, i32* %4
%22 = add i32 %21, 1
%23 = zext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %20, i64 %23
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 98
br i1 %27, label %28, label %29
28: ; preds = %19
store i8 98, i8* %2
br label %34
29: ; preds = %19, %11
br label %30
30: ; preds = %29
%31 = load i32, i32* %4
%32 = add i32 %31, 1
store i32 %32, i32* %4
br label %5
33: ; preds = %5
store i8 97, i8* %2
br label %34
34: ; preds = %33, %28
%35 = load i8, i8* %2
ret i8 %35
}

LLVM IR (-O2):
define signext i8 @get_file_type(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = icmp eq i32 %2, 1
br i1 %3, label %19, label %4
4: ; preds = %1, %14
%5 = phi i64 [ %9, %14 ], [ 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 %14
10: ; preds = %4
%11 = getelementptr inbounds i8, i8* %0, i64 %9
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 98
br i1 %13, label %19, label %14
14: ; preds = %4, %10
%15 = tail call i32 @strlen(i8* %0)
%16 = add nsw i32 %15, -1
%17 = zext i32 %16 to i64
%18 = icmp ult i64 %9, %17
br i1 %18, label %4, label %19
19: ; preds = %10, %14, %1
%20 = phi i8 [ 97, %1 ], [ 97, %14 ], [ 98, %10 ]
ret i8 %20
}