#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__ char_is_one_of(char const *, char const);
char *find_nth_chr(char const *, char const, int);
scalar_t__ starts_with(char const *, char *);
size_t strlen(char const *);
size_t get_mods_len(const char *str) {
  static const char FIXED_LENGTH_FILEMODS[] = "p~.htre";
  size_t result = 0;
  if (str[0] != ':') {
  } else if (char_is_one_of(FIXED_LENGTH_FILEMODS, str[1])) {
    result = 2;
  } else if (starts_with(str, ":s") || starts_with(str, ":gs")) {
    const char *p;
    result = (str[1] == 'g') ? 3 : 2;
    p = find_nth_chr(str, str[result], 3);
    if (p != NULL)
      result = (p - str) + 1;
    else
      result = strlen(str);
  }
  return result;
}


x86 assembly (clang, -O0):
<get_mods_len>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3a,%eax
je     1169 <get_mods_len+0x29>
jmp    1243 <get_mods_len+0x103>
mov    -0x8(%rbp),%rax
lea    0xe8c(%rip),%rdi
movsbl 0x1(%rax),%esi
call   1040 <char_is_one_of@plt>
cmp    $0x0,%rax
je     1194 <get_mods_len+0x54>
movq   $0x2,-0x10(%rbp)
jmp    123e <get_mods_len+0xfe>
mov    -0x8(%rbp),%rdi
lea    0xe69(%rip),%rsi
call   1060 <starts_with@plt>
cmp    $0x0,%rax
jne    11c8 <get_mods_len+0x88>
mov    -0x8(%rbp),%rdi
lea    0xe52(%rip),%rsi
call   1060 <starts_with@plt>
cmp    $0x0,%rax
je     1239 <get_mods_len+0xf9>
mov    -0x8(%rbp),%rax
movsbl 0x1(%rax),%edx
mov    $0x2,%eax
mov    $0x3,%ecx
cmp    $0x67,%edx
cmove  %ecx,%eax
cltq
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    $0x3,%edx
movsbl (%rax,%rcx,1),%esi
call   1050 <find_nth_chr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1227 <get_mods_len+0xe7>
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1234 <get_mods_len+0xf4>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x10(%rbp)
jmp    1239 <get_mods_len+0xf9>
jmp    123e <get_mods_len+0xfe>
jmp    1243 <get_mods_len+0x103>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_mods_len>:
push   %rbx
cmpb   $0x3a,(%rdi)
jne    11b9 <get_mods_len+0x79>
mov    %rdi,%rbx
movsbl 0x1(%rdi),%esi
lea    0xeac(%rip),%rdi
call   1040 <char_is_one_of@plt>
mov    %rax,%rcx
mov    $0x2,%eax
test   %rcx,%rcx
je     1168 <get_mods_len+0x28>
pop    %rbx
ret
lea    0xe99(%rip),%rsi
mov    %rbx,%rdi
call   1060 <starts_with@plt>
test   %rax,%rax
jne    1190 <get_mods_len+0x50>
lea    0xe88(%rip),%rsi
mov    %rbx,%rdi
call   1060 <starts_with@plt>
test   %rax,%rax
je     11b9 <get_mods_len+0x79>
xor    %eax,%eax
cmpb   $0x67,0x1(%rbx)
sete   %al
movsbl 0x2(%rax,%rbx,1),%esi
mov    %rbx,%rdi
mov    $0x3,%edx
call   1050 <find_nth_chr@plt>
test   %rax,%rax
je     11bd <get_mods_len+0x7d>
sub    %rbx,%rax
add    $0x1,%rax
pop    %rbx
ret
xor    %eax,%eax
pop    %rbx
ret
mov    %rbx,%rdi
pop    %rbx
jmp    1030 <strlen@plt>

LLVM IR (-O0):
@get_mods_len.FIXED_LENGTH_FILEMODS = internal constant [8 x i8] c"p~.htre\00"
@.str = [3 x i8] c":s\00"
@.str.1 = [4 x i8] c":gs\00"
define i64 @get_mods_len(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i8*
store i8* %0, i8** %2
store i64 0, i64* %3
%5 = load i8*, i8** %2
%6 = getelementptr inbounds i8, i8* %5, i64 0
%7 = load i8, i8* %6
%8 = sext i8 %7 to i32
%9 = icmp ne i32 %8, 58
br i1 %9, label %10, label %11
10: ; preds = %1
br label %56
11: ; preds = %1
%12 = load i8*, i8** %2
%13 = getelementptr inbounds i8, i8* %12, i64 1
%14 = load i8, i8* %13
%15 = call i64 @char_is_one_of(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @get_mods_len.FIXED_LENGTH_FILEMODS, i64 0, i64 0), i8 signext %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %11
store i64 2, i64* %3
br label %55
18: ; preds = %11
%19 = load i8*, i8** %2
%20 = call i64 @starts_with(i8* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%21 = icmp ne i64 %20, 0
br i1 %21, label %26, label %22
22: ; preds = %18
%23 = load i8*, i8** %2
%24 = call i64 @starts_with(i8* %23, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %54
26: ; preds = %22, %18
%27 = load i8*, i8** %2
%28 = getelementptr inbounds i8, i8* %27, i64 1
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp eq i32 %30, 103
%32 = zext i1 %31 to i64
%33 = select i1 %31, i32 3, i32 2
%34 = sext i32 %33 to i64
store i64 %34, i64* %3
%35 = load i8*, i8** %2
%36 = load i8*, i8** %2
%37 = load i64, i64* %3
%38 = getelementptr inbounds i8, i8* %36, i64 %37
%39 = load i8, i8* %38
%40 = call i8* @find_nth_chr(i8* %35, i8 signext %39, i32 3)
store i8* %40, i8** %4
%41 = load i8*, i8** %4
%42 = icmp ne i8* %41, null
br i1 %42, label %43, label %50
43: ; preds = %26
%44 = load i8*, i8** %4
%45 = load i8*, i8** %2
%46 = ptrtoint i8* %44 to i64
%47 = ptrtoint i8* %45 to i64
%48 = sub i64 %46, %47
%49 = add nsw i64 %48, 1
store i64 %49, i64* %3
br label %53
50: ; preds = %26
%51 = load i8*, i8** %2
%52 = call i64 @strlen(i8* %51)
store i64 %52, i64* %3
br label %53
53: ; preds = %50, %43
br label %54
54: ; preds = %53, %22
br label %55
55: ; preds = %54, %17
br label %56
56: ; preds = %55, %10
%57 = load i64, i64* %3
ret i64 %57
}

LLVM IR (-O2):
@get_mods_len.FIXED_LENGTH_FILEMODS = internal constant [8 x i8] c"p~.htre\00"
@.str = [3 x i8] c":s\00"
@.str.1 = [4 x i8] c":gs\00"
define i64 @get_mods_len(i8* %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 58
br i1 %3, label %4, label %30
4: ; preds = %1
%5 = getelementptr inbounds i8, i8* %0, i64 1
%6 = load i8, i8* %5
%7 = tail call i64 @char_is_one_of(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @get_mods_len.FIXED_LENGTH_FILEMODS, i64 0, i64 0), i8 signext %6)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %30
9: ; preds = %4
%10 = tail call i64 @starts_with(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %9
%13 = tail call i64 @starts_with(i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
br i1 %14, label %30, label %15
15: ; preds = %12, %9
%16 = load i8, i8* %5
%17 = icmp eq i8 %16, 103
%18 = select i1 %17, i64 3, i64 2
%19 = getelementptr inbounds i8, i8* %0, i64 %18
%20 = load i8, i8* %19
%21 = tail call i8* @find_nth_chr(i8* %0, i8 signext %20, i32 3)
%22 = icmp eq i8* %21, null
br i1 %22, label %28, label %23
23: ; preds = %15
%24 = ptrtoint i8* %21 to i64
%25 = ptrtoint i8* %0 to i64
%26 = sub i64 1, %25
%27 = add i64 %26, %24
br label %30
28: ; preds = %15
%29 = tail call i64 @strlen(i8* %0)
br label %30
30: ; preds = %23, %28, %4, %12, %1
%31 = phi i64 [ 0, %1 ], [ 0, %12 ], [ 2, %4 ], [ %27, %23 ], [ %29, %28 ]
ret i64 %31
}