#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 /*<<< orphan*/ facilities;

/* Variables and functions */
#define LOG_AUTH 143
#define LOG_CRON 142
#define LOG_DAEMON 141
#define LOG_FTP 140
#define LOG_LOCAL0 139
#define LOG_LOCAL1 138
#define LOG_LOCAL2 137
#define LOG_LOCAL3 136
#define LOG_LOCAL4 135
#define LOG_LOCAL5 134
#define LOG_LOCAL6 133
#define LOG_LOCAL7 132
#define LOG_MAIL 131
#define LOG_NEWS 130
#define LOG_USER 129
#define LOG_UUCP 128
int /*<<< orphan*/ strlen(char const *);
scalar_t__ strncasecmp(char const *, char const *, int /*<<< orphan*/);
int lookup_syslog_facility(const char *facility) {
  static const struct {
    const char *name;
    int number;
  } facilities[] = {
      {"auth", LOG_AUTH},     {"cron", LOG_CRON},     {"daemon", LOG_DAEMON},
      {"ftp", LOG_FTP},       {"local0", LOG_LOCAL0}, {"local1", LOG_LOCAL1},
      {"local2", LOG_LOCAL2}, {"local3", LOG_LOCAL3}, {"local4", LOG_LOCAL4},
      {"local5", LOG_LOCAL5}, {"local6", LOG_LOCAL6}, {"local7", LOG_LOCAL7},
      {"mail", LOG_MAIL},     {"news", LOG_NEWS},     {"user", LOG_USER},
      {"uucp", LOG_UUCP},
  };
  for (size_t i = 0; i < sizeof(facilities) / sizeof(facilities[0]); i++)
    if (strncasecmp(facilities[i].name, facility, strlen(facility)) == 0)
      return facilities[i].number;
  return LOG_USER;
}


x86 assembly (clang, -O0):
<lookup_syslog_facility>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
cmpq   $0x10,-0x18(%rbp)
jae    11b5 <lookup_syslog_facility+0x95>
mov    -0x18(%rbp),%rcx
lea    0x2bd6(%rip),%rax
shl    $0x4,%rcx
add    %rcx,%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    %eax,%edx
call   1040 <strncasecmp@plt>
cmp    $0x0,%rax
jne    119f <lookup_syslog_facility+0x7f>
mov    -0x18(%rbp),%rcx
lea    0x2b93(%rip),%rax
shl    $0x4,%rcx
add    %rcx,%rax
mov    0x8(%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11bc <lookup_syslog_facility+0x9c>
jmp    11a4 <lookup_syslog_facility+0x84>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1134 <lookup_syslog_facility+0x14>
movl   $0x81,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lookup_syslog_facility>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %ebx,%ebx
lea    0x2bec(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    (%rbx,%r12,1),%r15
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1040 <strncasecmp@plt>
test   %rax,%rax
je     1172 <lookup_syslog_facility+0x52>
add    $0x10,%rbx
cmp    $0x100,%rbx
jne    1140 <lookup_syslog_facility+0x20>
mov    $0x81,%eax
jmp    1177 <lookup_syslog_facility+0x57>
mov    0x8(%rbx,%r12,1),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.anon = type { i8*, i32 }
@lookup_syslog_facility.facilities = internal constant [16 x %struct.anon] [%struct.anon { i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i32 0, i32 0), i32 143 }, %struct.anon { i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i32 0, i32 0), i32 142 }, %struct.anon { i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i32 0, i32 0), i32 141 }, %struct.anon { i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i32 0, i32 0), i32 140 }, %struct.anon { i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i32 0, i32 0), i32 139 }, %struct.anon { i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i32 0, i32 0), i32 138 }, %struct.anon { i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i32 0, i32 0), i32 137 }, %struct.anon { i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i32 0, i32 0), i32 136 }, %struct.anon { i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i32 0, i32 0), i32 135 }, %struct.anon { i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i32 0, i32 0), i32 134 }, %struct.anon { i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.10, i32 0, i32 0), i32 133 }, %struct.anon { i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.11, i32 0, i32 0), i32 132 }, %struct.anon { i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.12, i32 0, i32 0), i32 131 }, %struct.anon { i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.13, i32 0, i32 0), i32 130 }, %struct.anon { i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.14, i32 0, i32 0), i32 129 }, %struct.anon { i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.15, i32 0, i32 0), i32 128 }]
@.str = [5 x i8] c"auth\00"
@.str.1 = [5 x i8] c"cron\00"
@.str.2 = [7 x i8] c"daemon\00"
@.str.3 = [4 x i8] c"ftp\00"
@.str.4 = [7 x i8] c"local0\00"
@.str.5 = [7 x i8] c"local1\00"
@.str.6 = [7 x i8] c"local2\00"
@.str.7 = [7 x i8] c"local3\00"
@.str.8 = [7 x i8] c"local4\00"
@.str.9 = [7 x i8] c"local5\00"
@.str.10 = [7 x i8] c"local6\00"
@.str.11 = [7 x i8] c"local7\00"
@.str.12 = [5 x i8] c"mail\00"
@.str.13 = [5 x i8] c"news\00"
@.str.14 = [5 x i8] c"user\00"
@.str.15 = [5 x i8] c"uucp\00"
define i32 @lookup_syslog_facility(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i64
store i8* %0, i8** %3
store i64 0, i64* %4
br label %5
5: ; preds = %24, %1
%6 = load i64, i64* %4
%7 = icmp ult i64 %6, 16
br i1 %7, label %8, label %27
8: ; preds = %5
%9 = load i64, i64* %4
%10 = getelementptr inbounds [16 x %struct.anon], [16 x %struct.anon]* @lookup_syslog_facility.facilities, i64 0, i64 %9
%11 = getelementptr inbounds %struct.anon, %struct.anon* %10, i32 0, i32 0
%12 = load i8*, i8** %11
%13 = load i8*, i8** %3
%14 = load i8*, i8** %3
%15 = call i32 @strlen(i8* %14)
%16 = call i64 @strncasecmp(i8* %12, i8* %13, i32 %15)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %23
18: ; preds = %8
%19 = load i64, i64* %4
%20 = getelementptr inbounds [16 x %struct.anon], [16 x %struct.anon]* @lookup_syslog_facility.facilities, i64 0, i64 %19
%21 = getelementptr inbounds %struct.anon, %struct.anon* %20, i32 0, i32 1
%22 = load i32, i32* %21
store i32 %22, i32* %2
br label %28
23: ; preds = %8
br label %24
24: ; preds = %23
%25 = load i64, i64* %4
%26 = add i64 %25, 1
store i64 %26, i64* %4
br label %5
27: ; preds = %5
store i32 129, i32* %2
br label %28
28: ; preds = %27, %18
%29 = load i32, i32* %2
ret i32 %29
}

LLVM IR (-O2):
%struct.anon = type { i8*, i32 }
@lookup_syslog_facility.facilities = internal unnamed_addr constant [16 x %struct.anon] [%struct.anon { i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i32 0, i32 0), i32 143 }, %struct.anon { i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i32 0, i32 0), i32 142 }, %struct.anon { i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i32 0, i32 0), i32 141 }, %struct.anon { i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i32 0, i32 0), i32 140 }, %struct.anon { i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i32 0, i32 0), i32 139 }, %struct.anon { i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i32 0, i32 0), i32 138 }, %struct.anon { i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i32 0, i32 0), i32 137 }, %struct.anon { i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i32 0, i32 0), i32 136 }, %struct.anon { i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i32 0, i32 0), i32 135 }, %struct.anon { i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i32 0, i32 0), i32 134 }, %struct.anon { i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.10, i32 0, i32 0), i32 133 }, %struct.anon { i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.11, i32 0, i32 0), i32 132 }, %struct.anon { i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.12, i32 0, i32 0), i32 131 }, %struct.anon { i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.13, i32 0, i32 0), i32 130 }, %struct.anon { i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.14, i32 0, i32 0), i32 129 }, %struct.anon { i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.15, i32 0, i32 0), i32 128 }]
@.str = [5 x i8] c"auth\00"
@.str.1 = [5 x i8] c"cron\00"
@.str.2 = [7 x i8] c"daemon\00"
@.str.3 = [4 x i8] c"ftp\00"
@.str.4 = [7 x i8] c"local0\00"
@.str.5 = [7 x i8] c"local1\00"
@.str.6 = [7 x i8] c"local2\00"
@.str.7 = [7 x i8] c"local3\00"
@.str.8 = [7 x i8] c"local4\00"
@.str.9 = [7 x i8] c"local5\00"
@.str.10 = [7 x i8] c"local6\00"
@.str.11 = [7 x i8] c"local7\00"
@.str.12 = [5 x i8] c"mail\00"
@.str.13 = [5 x i8] c"news\00"
@.str.14 = [5 x i8] c"user\00"
@.str.15 = [5 x i8] c"uucp\00"
define i32 @lookup_syslog_facility(i8* %0) {
br label %2
2: ; preds = %1, %12
%3 = phi i64 [ 0, %1 ], [ %13, %12 ]
%4 = getelementptr inbounds [16 x %struct.anon], [16 x %struct.anon]* @lookup_syslog_facility.facilities, i64 0, i64 %3, i32 0
%5 = load i8*, i8** %4
%6 = tail call i32 @strlen(i8* %0)
%7 = tail call i64 @strncasecmp(i8* %5, i8* %0, i32 %6)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = getelementptr inbounds [16 x %struct.anon], [16 x %struct.anon]* @lookup_syslog_facility.facilities, i64 0, i64 %3, i32 1
%11 = load i32, i32* %10
br label %15
12: ; preds = %2
%13 = add nuw nsw i64 %3, 1
%14 = icmp eq i64 %13, 16
br i1 %14, label %15, label %2
15: ; preds = %12, %9
%16 = phi i32 [ %11, %9 ], [ 129, %12 ]
ret i32 %16
}