#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 /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
size_t strnlen(char *, size_t);
scalar_t__ strtouint64(char *);
void parse_cos_mask_type(char *str, int *scope, unsigned *id) {
  size_t len = 0;
  ;
  ;
  ;
  len = strnlen(str, (size_t)22);
  if (len == 22) {
    printf("Error converting allocation COS string!\n");
    exit(EXIT_FAILURE);
  }
  if (len > 1 && (str[len - 1] == 'c' || str[len - 1] == 'C')) {
    *scope = 2;
    str[len - 1] = '\0';
  } else if (len > 1 && (str[len - 1] == 'd' || str[len - 1] == 'D')) {
    *scope = 1;
    str[len - 1] = '\0';
  } else {
    *scope = 0;
  }
  *id = (unsigned)strtouint64(str);
}


x86 assembly (clang, -O0):
<parse_cos_mask_type>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x16,%esi
call   1040 <strnlen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x16,-0x20(%rbp)
jne    1193 <parse_cos_mask_type+0x53>
lea    0xe80(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e54(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
cmpq   $0x1,-0x20(%rbp)
jbe    11ef <parse_cos_mask_type+0xaf>
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x63,%eax
je     11d0 <parse_cos_mask_type+0x90>
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x43,%eax
jne    11ef <parse_cos_mask_type+0xaf>
mov    -0x10(%rbp),%rax
movl   $0x2,(%rax)
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    $0x1,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    125a <parse_cos_mask_type+0x11a>
cmpq   $0x1,-0x20(%rbp)
jbe    124b <parse_cos_mask_type+0x10b>
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x64,%eax
je     122c <parse_cos_mask_type+0xec>
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x44,%eax
jne    124b <parse_cos_mask_type+0x10b>
mov    -0x10(%rbp),%rax
movl   $0x1,(%rax)
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    $0x1,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    1255 <parse_cos_mask_type+0x115>
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
jmp    125a <parse_cos_mask_type+0x11a>
mov    -0x8(%rbp),%rdi
call   1050 <strtouint64@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_cos_mask_type>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
mov    $0x16,%esi
call   1040 <strnlen@plt>
cmp    $0x16,%rax
je     11b2 <parse_cos_mask_type+0x72>
cmp    $0x2,%rax
jb     118c <parse_cos_mask_type+0x4c>
mov    -0x1(%rax,%rbx,1),%cl
add    $0xbd,%cl
cmp    $0x21,%cl
ja     118c <parse_cos_mask_type+0x4c>
movzbl %cl,%ecx
lea    0xe86(%rip),%rdx
movslq (%rdx,%rcx,4),%rcx
add    %rdx,%rcx
jmp    *%rcx
movl   $0x2,(%r15)
jmp    119c <parse_cos_mask_type+0x5c>
movl   $0x0,(%r15)
jmp    11a1 <parse_cos_mask_type+0x61>
movl   $0x1,(%r15)
movb   $0x0,-0x1(%rbx,%rax,1)
mov    %rbx,%rdi
call   1050 <strtouint64@plt>
mov    %eax,(%r14)
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xecf(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e1b(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [41 x i8] c"Error converting allocation COS string!\0A\00"
@EXIT_FAILURE = global i32 0
define void @parse_cos_mask_type(i8* %0, i32* %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i64
store i8* %0, i8** %4
store i32* %1, i32** %5
store i32* %2, i32** %6
store i64 0, i64* %7
%8 = load i8*, i8** %4
%9 = call i64 @strnlen(i8* %8, i64 22)
store i64 %9, i64* %7
%10 = load i64, i64* %7
%11 = icmp eq i64 %10, 22
br i1 %11, label %12, label %16
12: ; preds = %3
%13 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
%14 = load i32, i32* @EXIT_FAILURE
%15 = call i32 @exit(i32 %14)
unreachable
16: ; preds = %3
%17 = load i64, i64* %7
%18 = icmp ugt i64 %17, 1
br i1 %18, label %19, label %41
19: ; preds = %16
%20 = load i8*, i8** %4
%21 = load i64, i64* %7
%22 = sub i64 %21, 1
%23 = getelementptr inbounds i8, i8* %20, i64 %22
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %25, 99
br i1 %26, label %35, label %27
27: ; preds = %19
%28 = load i8*, i8** %4
%29 = load i64, i64* %7
%30 = sub i64 %29, 1
%31 = getelementptr inbounds i8, i8* %28, i64 %30
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp eq i32 %33, 67
br i1 %34, label %35, label %41
35: ; preds = %27, %19
%36 = load i32*, i32** %5
store i32 2, i32* %36
%37 = load i8*, i8** %4
%38 = load i64, i64* %7
%39 = sub i64 %38, 1
%40 = getelementptr inbounds i8, i8* %37, i64 %39
store i8 0, i8* %40
br label %69
41: ; preds = %27, %16
%42 = load i64, i64* %7
%43 = icmp ugt i64 %42, 1
br i1 %43, label %44, label %66
44: ; preds = %41
%45 = load i8*, i8** %4
%46 = load i64, i64* %7
%47 = sub i64 %46, 1
%48 = getelementptr inbounds i8, i8* %45, i64 %47
%49 = load i8, i8* %48
%50 = sext i8 %49 to i32
%51 = icmp eq i32 %50, 100
br i1 %51, label %60, label %52
52: ; preds = %44
%53 = load i8*, i8** %4
%54 = load i64, i64* %7
%55 = sub i64 %54, 1
%56 = getelementptr inbounds i8, i8* %53, i64 %55
%57 = load i8, i8* %56
%58 = sext i8 %57 to i32
%59 = icmp eq i32 %58, 68
br i1 %59, label %60, label %66
60: ; preds = %52, %44
%61 = load i32*, i32** %5
store i32 1, i32* %61
%62 = load i8*, i8** %4
%63 = load i64, i64* %7
%64 = sub i64 %63, 1
%65 = getelementptr inbounds i8, i8* %62, i64 %64
store i8 0, i8* %65
br label %68
66: ; preds = %52, %41
%67 = load i32*, i32** %5
store i32 0, i32* %67
br label %68
68: ; preds = %66, %60
br label %69
69: ; preds = %68, %35
%70 = load i8*, i8** %4
%71 = call i64 @strtouint64(i8* %70)
%72 = trunc i64 %71 to i32
%73 = load i32*, i32** %6
store i32 %72, i32* %73
ret void
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@str = [40 x i8] c"Error converting allocation COS string!\00"
define void @parse_cos_mask_type(i8* %0, i32* nocapture writeonly %1, i32* nocapture writeonly %2) {
%4 = tail call i64 @strnlen(i8* %0, i64 22)
%5 = icmp eq i64 %4, 22
br i1 %5, label %6, label %10
6: ; preds = %3
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str, i64 0, i64 0))
%8 = load i32, i32* @EXIT_FAILURE
%9 = tail call i32 @exit(i32 %8)
unreachable
10: ; preds = %3
%11 = icmp ugt i64 %4, 1
br i1 %11, label %12, label %18
12: ; preds = %10
%13 = add i64 %4, -1
%14 = getelementptr inbounds i8, i8* %0, i64 %13
%15 = load i8, i8* %14
switch i8 %15, label %18 [
i8 99, label %16
i8 67, label %16
i8 100, label %17
i8 68, label %17
]
16: ; preds = %12, %12
store i32 2, i32* %1
store i8 0, i8* %14
br label %19
17: ; preds = %12, %12
store i32 1, i32* %1
store i8 0, i8* %14
br label %19
18: ; preds = %12, %10
store i32 0, i32* %1
br label %19
19: ; preds = %17, %18, %16
%20 = tail call i64 @strtouint64(i8* %0)
%21 = trunc i64 %20 to i32
store i32 %21, i32* %2
ret void
}