#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*/ parse_facility(char *, unsigned int *, unsigned int *);
int /*<<< orphan*/ parse_priority(char *, unsigned int *, unsigned int *,
                                  unsigned int *);
int /*<<< orphan*/ select_facility(unsigned int, unsigned int, int,
                                   unsigned int);
char *strchr(char *, char);
int /*<<< orphan*/ usage(char *);
void parse_selector(char *str) {
  char *ptr;
  unsigned facility;
  unsigned priority;
  unsigned neg_pri;
  unsigned all_fac;
  unsigned eq_pri;
  unsigned i;
  ptr = strchr(str, '.');
  if (!ptr)
    usage("Invalid selector format");
  *ptr++ = 0;
  parse_facility(str, &facility, &all_fac);
  parse_priority(ptr, &priority, &neg_pri, &eq_pri);
  if (all_fac)
    for (i = 0; i < 24; i++)
      select_facility(i, priority, !neg_pri, eq_pri);
  else
    select_facility(facility, priority, !neg_pri, eq_pri);
}


x86 assembly (clang, -O0):
<parse_selector>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x2e,%esi
call   1050 <strchr@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1185 <parse_selector+0x35>
lea    0xe80(%rip),%rdi
call   1060 <usage@plt>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
lea    -0x14(%rbp),%rsi
lea    -0x20(%rbp),%rdx
call   1070 <parse_facility@plt>
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
lea    -0x1c(%rbp),%rdx
lea    -0x24(%rbp),%rcx
call   1040 <parse_priority@plt>
cmpl   $0x0,-0x20(%rbp)
je     1207 <parse_selector+0xb7>
movl   $0x0,-0x28(%rbp)
cmpl   $0x18,-0x28(%rbp)
jae    1202 <parse_selector+0xb2>
mov    -0x28(%rbp),%edi
mov    -0x18(%rbp),%esi
cmpl   $0x0,-0x1c(%rbp)
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%edx
mov    -0x24(%rbp),%ecx
call   1030 <select_facility@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11ce <parse_selector+0x7e>
jmp    1223 <parse_selector+0xd3>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
cmpl   $0x0,-0x1c(%rbp)
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%edx
mov    -0x24(%rbp),%ecx
call   1030 <select_facility@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_selector>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rdi,%r14
mov    $0x2e,%esi
call   1050 <strchr@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    117a <parse_selector+0x2a>
lea    0xe8b(%rip),%rdi
call   1060 <usage@plt>
mov    %rbx,%r15
add    $0x1,%r15
movb   $0x0,(%rbx)
lea    0x1c(%rsp),%rsi
lea    0x18(%rsp),%rdx
mov    %r14,%rdi
call   1070 <parse_facility@plt>
lea    0x14(%rsp),%rsi
lea    0x10(%rsp),%rdx
lea    0xc(%rsp),%rcx
mov    %r15,%rdi
call   1040 <parse_priority@plt>
cmpl   $0x0,0x18(%rsp)
je     11e3 <parse_selector+0x93>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
mov    0x14(%rsp),%esi
xor    %edx,%edx
cmpl   $0x0,0x10(%rsp)
sete   %dl
mov    0xc(%rsp),%ecx
mov    %ebx,%edi
call   1030 <select_facility@plt>
add    $0x1,%ebx
cmp    $0x18,%ebx
jne    11c0 <parse_selector+0x70>
jmp    11fe <parse_selector+0xae>
mov    0x1c(%rsp),%edi
mov    0x14(%rsp),%esi
xor    %edx,%edx
cmpl   $0x0,0x10(%rsp)
sete   %dl
mov    0xc(%rsp),%ecx
call   1030 <select_facility@plt>
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [24 x i8] c"Invalid selector format\00"
define void @parse_selector(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %2
%10 = load i8*, i8** %2
%11 = call i8* @strchr(i8* %10, i8 signext 46)
store i8* %11, i8** %3
%12 = load i8*, i8** %3
%13 = icmp ne i8* %12, null
br i1 %13, label %16, label %14
14: ; preds = %1
%15 = call i32 @usage(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %14, %1
%17 = load i8*, i8** %3
%18 = getelementptr inbounds i8, i8* %17, i32 1
store i8* %18, i8** %3
store i8 0, i8* %17
%19 = load i8*, i8** %2
%20 = call i32 @parse_facility(i8* %19, i32* %4, i32* %7)
%21 = load i8*, i8** %3
%22 = call i32 @parse_priority(i8* %21, i32* %5, i32* %6, i32* %8)
%23 = load i32, i32* %7
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %42
25: ; preds = %16
store i32 0, i32* %9
br label %26
26: ; preds = %38, %25
%27 = load i32, i32* %9
%28 = icmp ult i32 %27, 24
br i1 %28, label %29, label %41
29: ; preds = %26
%30 = load i32, i32* %9
%31 = load i32, i32* %5
%32 = load i32, i32* %6
%33 = icmp ne i32 %32, 0
%34 = xor i1 %33, true
%35 = zext i1 %34 to i32
%36 = load i32, i32* %8
%37 = call i32 @select_facility(i32 %30, i32 %31, i32 %35, i32 %36)
br label %38
38: ; preds = %29
%39 = load i32, i32* %9
%40 = add i32 %39, 1
store i32 %40, i32* %9
br label %26
41: ; preds = %26
br label %51
42: ; preds = %16
%43 = load i32, i32* %4
%44 = load i32, i32* %5
%45 = load i32, i32* %6
%46 = icmp ne i32 %45, 0
%47 = xor i1 %46, true
%48 = zext i1 %47 to i32
%49 = load i32, i32* %8
%50 = call i32 @select_facility(i32 %43, i32 %44, i32 %48, i32 %49)
br label %51
51: ; preds = %42, %41
ret void
}

LLVM IR (-O2):
@.str = [24 x i8] c"Invalid selector format\00"
define void @parse_selector(i8* %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = bitcast i32* %2 to i8*
%8 = bitcast i32* %3 to i8*
%9 = bitcast i32* %4 to i8*
%10 = bitcast i32* %5 to i8*
%11 = bitcast i32* %6 to i8*
%12 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 46)
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %16
14: ; preds = %1
%15 = tail call i32 @usage(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %14, %1
%17 = getelementptr inbounds i8, i8* %12, i64 1
store i8 0, i8* %12
%18 = call i32 @parse_facility(i8* %0, i32* %2, i32* %5)
%19 = call i32 @parse_priority(i8* %17, i32* %3, i32* %4, i32* %6)
%20 = load i32, i32* %5
%21 = icmp eq i32 %20, 0
br i1 %21, label %32, label %22
22: ; preds = %16, %22
%23 = phi i32 [ %30, %22 ], [ 0, %16 ]
%24 = load i32, i32* %3
%25 = load i32, i32* %4
%26 = icmp eq i32 %25, 0
%27 = zext i1 %26 to i32
%28 = load i32, i32* %6
%29 = call i32 @select_facility(i32 %23, i32 %24, i32 %27, i32 %28)
%30 = add nuw nsw i32 %23, 1
%31 = icmp eq i32 %30, 24
br i1 %31, label %40, label %22
32: ; preds = %16
%33 = load i32, i32* %2
%34 = load i32, i32* %3
%35 = load i32, i32* %4
%36 = icmp eq i32 %35, 0
%37 = zext i1 %36 to i32
%38 = load i32, i32* %6
%39 = call i32 @select_facility(i32 %33, i32 %34, i32 %37, i32 %38)
br label %40
40: ; preds = %22, %32
ret void
}