#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__ strcasecmp(char *, char *);
char *strrchr(char *, char);
int guess_mode(char *name) {
  char *s;
  if (name == NULL)
    return 0;
  s = strrchr(name, '.');
  if (s == NULL)
    return 0;
  s++;
  if (strcasecmp(s, "ps") == 0)
    return 1;
  if (strcasecmp(s, "eps") == 0)
    return 2;
  return 0;
}


x86 assembly (clang, -O0):
<guess_mode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1143 <guess_mode+0x23>
movl   $0x0,-0x4(%rbp)
jmp    11cb <guess_mode+0xab>
mov    -0x10(%rbp),%rdi
mov    $0x2e,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    116c <guess_mode+0x4c>
movl   $0x0,-0x4(%rbp)
jmp    11cb <guess_mode+0xab>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe7e(%rip),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%rax
jne    119e <guess_mode+0x7e>
movl   $0x1,-0x4(%rbp)
jmp    11cb <guess_mode+0xab>
mov    -0x18(%rbp),%rdi
lea    0xe57(%rip),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%rax
jne    11c4 <guess_mode+0xa4>
movl   $0x2,-0x4(%rbp)
jmp    11cb <guess_mode+0xab>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<guess_mode>:
push   %r14
push   %rbx
push   %rax
xor    %ebx,%ebx
test   %rdi,%rdi
je     1175 <guess_mode+0x55>
mov    $0x2e,%esi
call   1040 <strrchr@plt>
test   %rax,%rax
je     1175 <guess_mode+0x55>
mov    %rax,%r14
add    $0x1,%r14
lea    0xeb9(%rip),%rsi
mov    %r14,%rdi
call   1030 <strcasecmp@plt>
test   %rax,%rax
je     1170 <guess_mode+0x50>
lea    0xea4(%rip),%rsi
mov    %r14,%rdi
call   1030 <strcasecmp@plt>
xor    %ebx,%ebx
test   %rax,%rax
sete   %bl
add    %ebx,%ebx
jmp    1175 <guess_mode+0x55>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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