#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 */
typedef int uint8_t;

/* Variables and functions */
int /*<<< orphan*/ strcmp(char *, char *);
char *strtok(char *, char *);
uint8_t ace_flag_value(char *flagstr) {
  uint8_t flagval = 0x0;
  char *iflag;
  iflag = strtok(flagstr, "|");
  while (iflag) {
    if (!strcmp(iflag, "OI"))
      flagval += 0x1;
    else if (!strcmp(iflag, "CI"))
      flagval += 0x2;
    else if (!strcmp(iflag, "NP"))
      flagval += 0x4;
    else if (!strcmp(iflag, "IO"))
      flagval += 0x8;
    else if (!strcmp(iflag, "I"))
      flagval += 0x10;
    else
      return 0x0;
    iflag = strtok(NULL, "|");
  }
  return flagval;
}


x86 assembly (clang, -O0):
<ace_flag_value>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xec2(%rip),%rsi
call   1040 <strtok@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     124e <ace_flag_value+0x12e>
mov    -0x20(%rbp),%rdi
lea    0xea5(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%eax
jne    1179 <ace_flag_value+0x59>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1235 <ace_flag_value+0x115>
mov    -0x20(%rbp),%rdi
lea    0xe81(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%eax
jne    11a0 <ace_flag_value+0x80>
mov    -0x14(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x14(%rbp)
jmp    1230 <ace_flag_value+0x110>
mov    -0x20(%rbp),%rdi
lea    0xe5d(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%eax
jne    11c7 <ace_flag_value+0xa7>
mov    -0x14(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x14(%rbp)
jmp    122b <ace_flag_value+0x10b>
mov    -0x20(%rbp),%rdi
lea    0xe39(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%eax
jne    11ee <ace_flag_value+0xce>
mov    -0x14(%rbp),%eax
add    $0x8,%eax
mov    %eax,-0x14(%rbp)
jmp    1226 <ace_flag_value+0x106>
mov    -0x20(%rbp),%rdi
lea    0xe0d(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%eax
jne    1215 <ace_flag_value+0xf5>
mov    -0x14(%rbp),%eax
add    $0x10,%eax
mov    %eax,-0x14(%rbp)
jmp    1221 <ace_flag_value+0x101>
movl   $0x0,-0x4(%rbp)
jmp    1254 <ace_flag_value+0x134>
jmp    1226 <ace_flag_value+0x106>
jmp    122b <ace_flag_value+0x10b>
jmp    1230 <ace_flag_value+0x110>
jmp    1235 <ace_flag_value+0x115>
xor    %eax,%eax
mov    %eax,%edi
lea    0xdc0(%rip),%rsi
call   1040 <strtok@plt>
mov    %rax,-0x20(%rbp)
jmp    1147 <ace_flag_value+0x27>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ace_flag_value>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xece(%rip),%rsi
call   1040 <strtok@plt>
test   %rax,%rax
je     120e <ace_flag_value+0xee>
mov    %rax,%rbp
xor    %ebx,%ebx
lea    0xeb6(%rip),%r14
lea    0xead(%rip),%r15
lea    0xeab(%rip),%r12
lea    0xea7(%rip),%r13
jmp    118d <ace_flag_value+0x6d>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    $0x1,%ecx
add    %ecx,%ebx
xor    %edi,%edi
mov    %r15,%rsi
call   1040 <strtok@plt>
mov    %rax,%rbp
test   %rax,%rax
je     1210 <ace_flag_value+0xf0>
mov    %rbp,%rdi
mov    %r14,%rsi
call   1030 <strcmp@plt>
test   %eax,%eax
je     1170 <ace_flag_value+0x50>
mov    %rbp,%rdi
mov    %r12,%rsi
call   1030 <strcmp@plt>
test   %eax,%eax
je     11f0 <ace_flag_value+0xd0>
mov    %rbp,%rdi
mov    %r13,%rsi
call   1030 <strcmp@plt>
test   %eax,%eax
je     11fa <ace_flag_value+0xda>
mov    %rbp,%rdi
lea    0xe47(%rip),%rsi
call   1030 <strcmp@plt>
test   %eax,%eax
je     1204 <ace_flag_value+0xe4>
mov    %rbp,%rdi
lea    0xe2f(%rip),%rsi
call   1030 <strcmp@plt>
mov    $0x10,%ecx
test   %eax,%eax
je     1175 <ace_flag_value+0x55>
jmp    120e <ace_flag_value+0xee>
nopw   0x0(%rax,%rax,1)
mov    $0x2,%ecx
jmp    1175 <ace_flag_value+0x55>
mov    $0x4,%ecx
jmp    1175 <ace_flag_value+0x55>
mov    $0x8,%ecx
jmp    1175 <ace_flag_value+0x55>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"|\00"
@.str.1 = [3 x i8] c"OI\00"
@.str.2 = [3 x i8] c"CI\00"
@.str.3 = [3 x i8] c"NP\00"
@.str.4 = [3 x i8] c"IO\00"
@.str.5 = [2 x i8] c"I\00"
define i32 @ace_flag_value(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
store i8* %0, i8** %3
store i32 0, i32* %4
%6 = load i8*, i8** %3
%7 = call i8* @strtok(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %7, i8** %5
br label %8
8: ; preds = %51, %1
%9 = load i8*, i8** %5
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %53
11: ; preds = %8
%12 = load i8*, i8** %5
%13 = call i32 @strcmp(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp ne i32 %13, 0
br i1 %14, label %18, label %15
15: ; preds = %11
%16 = load i32, i32* %4
%17 = add nsw i32 %16, 1
store i32 %17, i32* %4
br label %51
18: ; preds = %11
%19 = load i8*, i8** %5
%20 = call i32 @strcmp(i8* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%21 = icmp ne i32 %20, 0
br i1 %21, label %25, label %22
22: ; preds = %18
%23 = load i32, i32* %4
%24 = add nsw i32 %23, 2
store i32 %24, i32* %4
br label %50
25: ; preds = %18
%26 = load i8*, i8** %5
%27 = call i32 @strcmp(i8* %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%28 = icmp ne i32 %27, 0
br i1 %28, label %32, label %29
29: ; preds = %25
%30 = load i32, i32* %4
%31 = add nsw i32 %30, 4
store i32 %31, i32* %4
br label %49
32: ; preds = %25
%33 = load i8*, i8** %5
%34 = call i32 @strcmp(i8* %33, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%35 = icmp ne i32 %34, 0
br i1 %35, label %39, label %36
36: ; preds = %32
%37 = load i32, i32* %4
%38 = add nsw i32 %37, 8
store i32 %38, i32* %4
br label %48
39: ; preds = %32
%40 = load i8*, i8** %5
%41 = call i32 @strcmp(i8* %40, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%42 = icmp ne i32 %41, 0
br i1 %42, label %46, label %43
43: ; preds = %39
%44 = load i32, i32* %4
%45 = add nsw i32 %44, 16
store i32 %45, i32* %4
br label %47
46: ; preds = %39
store i32 0, i32* %2
br label %55
47: ; preds = %43
br label %48
48: ; preds = %47, %36
br label %49
49: ; preds = %48, %29
br label %50
50: ; preds = %49, %22
br label %51
51: ; preds = %50, %15
%52 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %52, i8** %5
br label %8
53: ; preds = %8
%54 = load i32, i32* %4
store i32 %54, i32* %2
br label %55
55: ; preds = %53, %46
%56 = load i32, i32* %2
ret i32 %56
}

LLVM IR (-O2):
@.str = [2 x i8] c"|\00"
@.str.1 = [3 x i8] c"OI\00"
@.str.2 = [3 x i8] c"CI\00"
@.str.3 = [3 x i8] c"NP\00"
@.str.4 = [3 x i8] c"IO\00"
@.str.5 = [2 x i8] c"I\00"
define i32 @ace_flag_value(i8* %0) {
%2 = tail call i8* @strtok(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i8* %2, null
br i1 %3, label %26, label %4
4: ; preds = %1, %21
%5 = phi i8* [ %24, %21 ], [ %2, %1 ]
%6 = phi i32 [ %23, %21 ], [ 0, %1 ]
%7 = tail call i32 @strcmp(i8* %5, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i32 %7, 0
br i1 %8, label %21, label %9
9: ; preds = %4
%10 = tail call i32 @strcmp(i8* %5, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%11 = icmp eq i32 %10, 0
br i1 %11, label %21, label %12
12: ; preds = %9
%13 = tail call i32 @strcmp(i8* %5, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%14 = icmp eq i32 %13, 0
br i1 %14, label %21, label %15
15: ; preds = %12
%16 = tail call i32 @strcmp(i8* %5, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%17 = icmp eq i32 %16, 0
br i1 %17, label %21, label %18
18: ; preds = %15
%19 = tail call i32 @strcmp(i8* %5, i8* dereferenceable(2) getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %26
21: ; preds = %18, %15, %12, %9, %4
%22 = phi i32 [ 1, %4 ], [ 2, %9 ], [ 4, %12 ], [ 8, %15 ], [ 16, %18 ]
%23 = add nuw nsw i32 %6, %22
%24 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%25 = icmp eq i8* %24, null
br i1 %25, label %26, label %4
26: ; preds = %18, %21, %1
%27 = phi i32 [ 0, %1 ], [ %23, %21 ], [ 0, %18 ]
ret i32 %27
}