#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*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ stderr;
unsigned int encode_pax_flags(const char *conf) {
  unsigned int ret = 0;
  const char *p = conf;
  while (*p) {
    switch (*p) {
    case 'P':
      ret |= 0x00000001;
      break;
    case 'p':
      ret |= 0x00010000;
      break;
    case 'E':
      ret |= 0x00000010;
      break;
    case 'e':
      ret |= 0x00100000;
      break;
    case 'M':
      ret |= 0x00000004;
      break;
    case 'm':
      ret |= 0x00040000;
      break;
    case 'R':
      ret |= 0x00000008;
      break;
    case 'r':
      ret |= 0x00080000;
      break;
    case 'S':
      ret |= 0x00000002;
      break;
    case 's':
      ret |= 0x00020000;
      break;
    default:
      fprintf(stderr,
              "Unknown character: \"%c\" in PaX configuration string: \"%s\".  "
              "Permitted characters are: \"PpEeMmRrSs\".\n",
              *p, conf);
      exit(EXIT_FAILURE);
    }
    p++;
  };
  if ((ret >> 16) & (ret & 0xFFFF)) {
    fprintf(stderr,
            "PaX config string: \"%s\" tries to both enable and disable a PaX "
            "feature.  Please review configuration file.\n",
            conf);
    exit(EXIT_FAILURE);
  }
  return ret;
}


x86 assembly (clang, -O0):
<encode_pax_flags>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
je     124c <encode_pax_flags+0x12c>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
add    $0xffffffbb,%eax
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0x2e,%eax
ja     120b <encode_pax_flags+0xeb>
mov    -0x20(%rbp),%rax
lea    0xe94(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0xc(%rbp),%eax
or     $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    123b <encode_pax_flags+0x11b>
mov    -0xc(%rbp),%eax
or     $0x10000,%eax
mov    %eax,-0xc(%rbp)
jmp    123b <encode_pax_flags+0x11b>
mov    -0xc(%rbp),%eax
or     $0x10,%eax
mov    %eax,-0xc(%rbp)
jmp    123b <encode_pax_flags+0x11b>
mov    -0xc(%rbp),%eax
or     $0x100000,%eax
mov    %eax,-0xc(%rbp)
jmp    123b <encode_pax_flags+0x11b>
mov    -0xc(%rbp),%eax
or     $0x4,%eax
mov    %eax,-0xc(%rbp)
jmp    123b <encode_pax_flags+0x11b>
mov    -0xc(%rbp),%eax
or     $0x40000,%eax
mov    %eax,-0xc(%rbp)
jmp    123b <encode_pax_flags+0x11b>
mov    -0xc(%rbp),%eax
or     $0x8,%eax
mov    %eax,-0xc(%rbp)
jmp    123b <encode_pax_flags+0x11b>
mov    -0xc(%rbp),%eax
or     $0x80000,%eax
mov    %eax,-0xc(%rbp)
jmp    123b <encode_pax_flags+0x11b>
mov    -0xc(%rbp),%eax
or     $0x2,%eax
mov    %eax,-0xc(%rbp)
jmp    123b <encode_pax_flags+0x11b>
mov    -0xc(%rbp),%eax
or     $0x20000,%eax
mov    %eax,-0xc(%rbp)
jmp    123b <encode_pax_flags+0x11b>
mov    0x2dce(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rax
movsbl (%rax),%edx
mov    -0x8(%rbp),%rcx
lea    0xe96(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    0x2da4(%rip),%rax
mov    (%rax),%edi
call   1040 <exit@plt>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    113b <encode_pax_flags+0x1b>
mov    -0xc(%rbp),%eax
shr    $0x10,%eax
mov    -0xc(%rbp),%ecx
and    $0xffff,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     128f <encode_pax_flags+0x16f>
mov    0x2d73(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xea7(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    0x2d50(%rip),%rax
mov    (%rax),%edi
call   1040 <exit@plt>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<encode_pax_flags>:
push   %rax
mov    %rdi,%r8
mov    (%rdi),%cl
test   %cl,%cl
je     119e <encode_pax_flags+0x7e>
lea    0x1(%r8),%rsi
xor    %eax,%eax
lea    0xec9(%rip),%r9
jmp    114d <encode_pax_flags+0x2d>
mov    $0x10000,%ecx
xchg   %ax,%ax
or     %ecx,%eax
movzbl (%rsi),%ecx
add    $0x1,%rsi
test   %cl,%cl
je     11a0 <encode_pax_flags+0x80>
movsbl %cl,%edx
lea    -0x45(%rdx),%edi
cmp    $0x2e,%edi
ja     11ab <encode_pax_flags+0x8b>
mov    $0x1,%ecx
movslq (%r9,%rdi,4),%rdi
add    %r9,%rdi
jmp    *%rdi
mov    $0x10,%ecx
jmp    1140 <encode_pax_flags+0x20>
mov    $0x4,%ecx
jmp    1140 <encode_pax_flags+0x20>
mov    $0x8,%ecx
jmp    1140 <encode_pax_flags+0x20>
mov    $0x2,%ecx
jmp    1140 <encode_pax_flags+0x20>
mov    $0x100000,%ecx
jmp    1140 <encode_pax_flags+0x20>
mov    $0x40000,%ecx
jmp    1140 <encode_pax_flags+0x20>
mov    $0x80000,%ecx
jmp    1140 <encode_pax_flags+0x20>
mov    $0x20000,%ecx
jmp    1140 <encode_pax_flags+0x20>
xor    %eax,%eax
mov    %eax,%ecx
shr    $0x10,%ecx
test   %eax,%ecx
jne    11c7 <encode_pax_flags+0xa7>
pop    %rcx
ret
mov    0x2e2e(%rip),%rax
mov    (%rax),%edi
lea    0xf01(%rip),%rsi
mov    %r8,%rcx
xor    %eax,%eax
call   1030 <fprintf@plt>
jmp    11e1 <encode_pax_flags+0xc1>
mov    0x2e12(%rip),%rax
mov    (%rax),%edi
lea    0xf4a(%rip),%rsi
mov    %r8,%rdx
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    0x2df0(%rip),%rax
mov    (%rax),%edi
call   1040 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [101 x i8] c"Unknown character: \22%c\22 in PaX configuration string: \22%s\22. Permitted characters are: \22PpEeMmRrSs\22.\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [108 x i8] c"PaX config string: \22%s\22 tries to both enable and disable a PaX feature. Please review configuration file.\0A\00"
define i32 @encode_pax_flags(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
store i8* %0, i8** %2
store i32 0, i32* %3
%5 = load i8*, i8** %2
store i8* %5, i8** %4
br label %6
6: ; preds = %53, %1
%7 = load i8*, i8** %4
%8 = load i8, i8* %7
%9 = icmp ne i8 %8, 0
br i1 %9, label %10, label %56
10: ; preds = %6
%11 = load i8*, i8** %4
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
switch i32 %13, label %44 [
i32 80, label %14
i32 112, label %17
i32 69, label %20
i32 101, label %23
i32 77, label %26
i32 109, label %29
i32 82, label %32
i32 114, label %35
i32 83, label %38
i32 115, label %41
]
14: ; preds = %10
%15 = load i32, i32* %3
%16 = or i32 %15, 1
store i32 %16, i32* %3
br label %53
17: ; preds = %10
%18 = load i32, i32* %3
%19 = or i32 %18, 65536
store i32 %19, i32* %3
br label %53
20: ; preds = %10
%21 = load i32, i32* %3
%22 = or i32 %21, 16
store i32 %22, i32* %3
br label %53
23: ; preds = %10
%24 = load i32, i32* %3
%25 = or i32 %24, 1048576
store i32 %25, i32* %3
br label %53
26: ; preds = %10
%27 = load i32, i32* %3
%28 = or i32 %27, 4
store i32 %28, i32* %3
br label %53
29: ; preds = %10
%30 = load i32, i32* %3
%31 = or i32 %30, 262144
store i32 %31, i32* %3
br label %53
32: ; preds = %10
%33 = load i32, i32* %3
%34 = or i32 %33, 8
store i32 %34, i32* %3
br label %53
35: ; preds = %10
%36 = load i32, i32* %3
%37 = or i32 %36, 524288
store i32 %37, i32* %3
br label %53
38: ; preds = %10
%39 = load i32, i32* %3
%40 = or i32 %39, 2
store i32 %40, i32* %3
br label %53
41: ; preds = %10
%42 = load i32, i32* %3
%43 = or i32 %42, 131072
store i32 %43, i32* %3
br label %53
44: ; preds = %10
%45 = load i32, i32* @stderr
%46 = load i8*, i8** %4
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
%49 = load i8*, i8** %2
%50 = call i32 (i32, i8*, ...) @fprintf(i32 %45, i8* getelementptr inbounds ([101 x i8], [101 x i8]* @.str, i64 0, i64 0), i32 %48, i8* %49)
%51 = load i32, i32* @EXIT_FAILURE
%52 = call i32 @exit(i32 %51)
unreachable
53: ; preds = %41, %38, %35, %32, %29, %26, %23, %20, %17, %14
%54 = load i8*, i8** %4
%55 = getelementptr inbounds i8, i8* %54, i32 1
store i8* %55, i8** %4
br label %6
56: ; preds = %6
%57 = load i32, i32* %3
%58 = lshr i32 %57, 16
%59 = load i32, i32* %3
%60 = and i32 %59, 65535
%61 = and i32 %58, %60
%62 = icmp ne i32 %61, 0
br i1 %62, label %63, label %69
63: ; preds = %56
%64 = load i32, i32* @stderr
%65 = load i8*, i8** %2
%66 = call i32 (i32, i8*, ...) @fprintf(i32 %64, i8* getelementptr inbounds ([108 x i8], [108 x i8]* @.str.1, i64 0, i64 0), i8* %65)
%67 = load i32, i32* @EXIT_FAILURE
%68 = call i32 @exit(i32 %67)
unreachable
69: ; preds = %56
%70 = load i32, i32* %3
ret i32 %70
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [101 x i8] c"Unknown character: \22%c\22 in PaX configuration string: \22%s\22. Permitted characters are: \22PpEeMmRrSs\22.\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [108 x i8] c"PaX config string: \22%s\22 tries to both enable and disable a PaX feature. Please review configuration file.\0A\00"
define i32 @encode_pax_flags(i8* %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 0
br i1 %3, label %29, label %4
4: ; preds = %1, %23
%5 = phi i8 [ %27, %23 ], [ %2, %1 ]
%6 = phi i8* [ %26, %23 ], [ %0, %1 ]
%7 = phi i32 [ %25, %23 ], [ 0, %1 ]
%8 = sext i8 %5 to i32
switch i32 %8, label %18 [
i32 80, label %23
i32 112, label %9
i32 69, label %10
i32 101, label %11
i32 77, label %12
i32 109, label %13
i32 82, label %14
i32 114, label %15
i32 83, label %16
i32 115, label %17
]
9: ; preds = %4
br label %23
10: ; preds = %4
br label %23
11: ; preds = %4
br label %23
12: ; preds = %4
br label %23
13: ; preds = %4
br label %23
14: ; preds = %4
br label %23
15: ; preds = %4
br label %23
16: ; preds = %4
br label %23
17: ; preds = %4
br label %23
18: ; preds = %4
%19 = load i32, i32* @stderr
%20 = tail call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([101 x i8], [101 x i8]* @.str, i64 0, i64 0), i32 %8, i8* %0)
%21 = load i32, i32* @EXIT_FAILURE
%22 = tail call i32 @exit(i32 %21)
unreachable
23: ; preds = %4, %17, %16, %15, %14, %13, %12, %11, %10, %9
%24 = phi i32 [ 131072, %17 ], [ 2, %16 ], [ 524288, %15 ], [ 8, %14 ], [ 262144, %13 ], [ 4, %12 ], [ 1048576, %11 ], [ 16, %10 ], [ 65536, %9 ], [ 1, %4 ]
%25 = or i32 %7, %24
%26 = getelementptr inbounds i8, i8* %6, i64 1
%27 = load i8, i8* %26
%28 = icmp eq i8 %27, 0
br i1 %28, label %29, label %4
29: ; preds = %23, %1
%30 = phi i32 [ 0, %1 ], [ %25, %23 ]
%31 = lshr i32 %30, 16
%32 = and i32 %31, %30
%33 = icmp eq i32 %32, 0
br i1 %33, label %39, label %34
34: ; preds = %29
%35 = load i32, i32* @stderr
%36 = tail call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([108 x i8], [108 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%37 = load i32, i32* @EXIT_FAILURE
%38 = tail call i32 @exit(i32 %37)
unreachable
39: ; preds = %29
ret i32 %30
}