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

/* Variables and functions */
#define LOG_ALERT 135
#define LOG_CRIT 134
#define LOG_DEBUG 133
#define LOG_EMERG 132
#define LOG_ERR 131
#define LOG_INFO 130
#define LOG_NOTICE 129
#define LOG_WARNING 128
int /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ strlcpy(char *, char const *, int);
scalar_t__ strncmp(char *, char *, int);
int /*<<< orphan*/ xsyslog(int /*<<< orphan*/ *, int, char *);
int slg_write(BIO *b, const char *in, int inl) {
  int ret = inl;
  char *buf;
  char *pp;
  int priority, i;
  static const struct {
    int strl;
    char str[10];
    int log_level;
  } mapping[] = {{6, "PANIC ", LOG_EMERG},   {6, "EMERG ", LOG_EMERG},
                 {4, "EMR ", LOG_EMERG},     {6, "ALERT ", LOG_ALERT},
                 {4, "ALR ", LOG_ALERT},     {5, "CRIT ", LOG_CRIT},
                 {4, "CRI ", LOG_CRIT},      {6, "ERROR ", LOG_ERR},
                 {4, "ERR ", LOG_ERR},       {8, "WARNING ", LOG_WARNING},
                 {5, "WARN ", LOG_WARNING},  {4, "WAR ", LOG_WARNING},
                 {7, "NOTICE ", LOG_NOTICE}, {5, "NOTE ", LOG_NOTICE},
                 {4, "NOT ", LOG_NOTICE},    {5, "INFO ", LOG_INFO},
                 {4, "INF ", LOG_INFO},      {6, "DEBUG ", LOG_DEBUG},
                 {4, "DBG ", LOG_DEBUG},     {0, "", LOG_ERR}};
  if ((buf = malloc(inl + 1)) == NULL) {
    return (0);
  }
  strlcpy(buf, in, inl + 1);
  i = 0;
  while (strncmp(buf, mapping[i].str, mapping[i].strl) != 0)
    i++;
  priority = mapping[i].log_level;
  pp = buf + mapping[i].strl;
  xsyslog(b, priority, pp);
  free(buf);
  return (ret);
}


x86 assembly (clang, -O0):
<slg_write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%edi
add    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    118e <slg_write+0x3e>
movl   $0x0,-0x4(%rbp)
jmp    124a <slg_write+0xfa>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
add    $0x1,%edx
call   1070 <strlcpy@plt>
movl   $0x0,-0x38(%rbp)
mov    -0x28(%rbp),%rdi
movslq -0x38(%rbp),%rax
lea    0xe49(%rip),%rsi
imul   $0x14,%rax,%rax
add    %rax,%rsi
add    $0x4,%rsi
movslq -0x38(%rbp),%rcx
lea    0xe33(%rip),%rax
imul   $0x14,%rcx,%rcx
add    %rcx,%rax
mov    (%rax),%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
je     11f3 <slg_write+0xa3>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    11a8 <slg_write+0x58>
movslq -0x38(%rbp),%rcx
lea    0xe02(%rip),%rax
imul   $0x14,%rcx,%rcx
add    %rcx,%rax
mov    0x10(%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x28(%rbp),%rax
movslq -0x38(%rbp),%rdx
lea    0xde6(%rip),%rcx
imul   $0x14,%rdx,%rdx
add    %rdx,%rcx
movslq (%rcx),%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x34(%rbp),%esi
mov    -0x30(%rbp),%rdx
call   1050 <xsyslog@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<slg_write>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r15d
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0x1(%r15),%ebp
mov    %ebp,%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     11eb <slg_write+0x9b>
mov    %rax,%r12
mov    %rax,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1070 <strlcpy@plt>
mov    $0xffffffffffffffff,%rbp
lea    0xe72(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    -0x4(%rbx),%r13d
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %r13d,%edx
call   1040 <strncmp@plt>
add    $0x1,%rbp
add    $0x14,%rbx
test   %rax,%rax
jne    11a0 <slg_write+0x50>
movslq %r13d,%rax
mov    %ebp,%ecx
lea    (%rcx,%rcx,4),%rcx
lea    0xe31(%rip),%rdx
mov    0x10(%rdx,%rcx,4),%esi
mov    %r12,%rdx
add    %rax,%rdx
mov    %r14,%rdi
call   1050 <xsyslog@plt>
mov    %r12,%rdi
call   1030 <free@plt>
jmp    11ee <slg_write+0x9e>
xor    %r15d,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.anon = type { i32, [10 x i8], i32 }
@slg_write.mapping = internal constant [20 x %struct.anon] [%struct.anon { i32 6, [10 x i8] c"PANIC \00\00\00\00", i32 132 }, %struct.anon { i32 6, [10 x i8] c"EMERG \00\00\00\00", i32 132 }, %struct.anon { i32 4, [10 x i8] c"EMR \00\00\00\00\00\00", i32 132 }, %struct.anon { i32 6, [10 x i8] c"ALERT \00\00\00\00", i32 135 }, %struct.anon { i32 4, [10 x i8] c"ALR \00\00\00\00\00\00", i32 135 }, %struct.anon { i32 5, [10 x i8] c"CRIT \00\00\00\00\00", i32 134 }, %struct.anon { i32 4, [10 x i8] c"CRI \00\00\00\00\00\00", i32 134 }, %struct.anon { i32 6, [10 x i8] c"ERROR \00\00\00\00", i32 131 }, %struct.anon { i32 4, [10 x i8] c"ERR \00\00\00\00\00\00", i32 131 }, %struct.anon { i32 8, [10 x i8] c"WARNING \00\00", i32 128 }, %struct.anon { i32 5, [10 x i8] c"WARN \00\00\00\00\00", i32 128 }, %struct.anon { i32 4, [10 x i8] c"WAR \00\00\00\00\00\00", i32 128 }, %struct.anon { i32 7, [10 x i8] c"NOTICE \00\00\00", i32 129 }, %struct.anon { i32 5, [10 x i8] c"NOTE \00\00\00\00\00", i32 129 }, %struct.anon { i32 4, [10 x i8] c"NOT \00\00\00\00\00\00", i32 129 }, %struct.anon { i32 5, [10 x i8] c"INFO \00\00\00\00\00", i32 130 }, %struct.anon { i32 4, [10 x i8] c"INF \00\00\00\00\00\00", i32 130 }, %struct.anon { i32 6, [10 x i8] c"DEBUG \00\00\00\00", i32 133 }, %struct.anon { i32 4, [10 x i8] c"DBG \00\00\00\00\00\00", i32 133 }, %struct.anon { i32 0, [10 x i8] zeroinitializer, i32 131 }]
define i32 @slg_write(i32* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
store i32* %0, i32** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%13 = load i32, i32* %7
store i32 %13, i32* %8
%14 = load i32, i32* %7
%15 = add nsw i32 %14, 1
%16 = call i8* @malloc(i32 %15)
store i8* %16, i8** %9
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %19
18: ; preds = %3
store i32 0, i32* %4
br label %63
19: ; preds = %3
%20 = load i8*, i8** %9
%21 = load i8*, i8** %6
%22 = load i32, i32* %7
%23 = add nsw i32 %22, 1
%24 = call i32 @strlcpy(i8* %20, i8* %21, i32 %23)
store i32 0, i32* %12
br label %25
25: ; preds = %39, %19
%26 = load i8*, i8** %9
%27 = load i32, i32* %12
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [20 x %struct.anon], [20 x %struct.anon]* @slg_write.mapping, i64 0, i64 %28
%30 = getelementptr inbounds %struct.anon, %struct.anon* %29, i32 0, i32 1
%31 = getelementptr inbounds [10 x i8], [10 x i8]* %30, i64 0, i64 0
%32 = load i32, i32* %12
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [20 x %struct.anon], [20 x %struct.anon]* @slg_write.mapping, i64 0, i64 %33
%35 = getelementptr inbounds %struct.anon, %struct.anon* %34, i32 0, i32 0
%36 = load i32, i32* %35
%37 = call i64 @strncmp(i8* %26, i8* %31, i32 %36)
%38 = icmp ne i64 %37, 0
br i1 %38, label %39, label %42
39: ; preds = %25
%40 = load i32, i32* %12
%41 = add nsw i32 %40, 1
store i32 %41, i32* %12
br label %25
42: ; preds = %25
%43 = load i32, i32* %12
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [20 x %struct.anon], [20 x %struct.anon]* @slg_write.mapping, i64 0, i64 %44
%46 = getelementptr inbounds %struct.anon, %struct.anon* %45, i32 0, i32 2
%47 = load i32, i32* %46
store i32 %47, i32* %11
%48 = load i8*, i8** %9
%49 = load i32, i32* %12
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds [20 x %struct.anon], [20 x %struct.anon]* @slg_write.mapping, i64 0, i64 %50
%52 = getelementptr inbounds %struct.anon, %struct.anon* %51, i32 0, i32 0
%53 = load i32, i32* %52
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i8, i8* %48, i64 %54
store i8* %55, i8** %10
%56 = load i32*, i32** %5
%57 = load i32, i32* %11
%58 = load i8*, i8** %10
%59 = call i32 @xsyslog(i32* %56, i32 %57, i8* %58)
%60 = load i8*, i8** %9
%61 = call i32 @free(i8* %60)
%62 = load i32, i32* %8
store i32 %62, i32* %4
br label %63
63: ; preds = %42, %18
%64 = load i32, i32* %4
ret i32 %64
}

LLVM IR (-O2):
%struct.anon = type { i32, [10 x i8], i32 }
@slg_write.mapping = internal constant [20 x %struct.anon] [%struct.anon { i32 6, [10 x i8] c"PANIC \00\00\00\00", i32 132 }, %struct.anon { i32 6, [10 x i8] c"EMERG \00\00\00\00", i32 132 }, %struct.anon { i32 4, [10 x i8] c"EMR \00\00\00\00\00\00", i32 132 }, %struct.anon { i32 6, [10 x i8] c"ALERT \00\00\00\00", i32 135 }, %struct.anon { i32 4, [10 x i8] c"ALR \00\00\00\00\00\00", i32 135 }, %struct.anon { i32 5, [10 x i8] c"CRIT \00\00\00\00\00", i32 134 }, %struct.anon { i32 4, [10 x i8] c"CRI \00\00\00\00\00\00", i32 134 }, %struct.anon { i32 6, [10 x i8] c"ERROR \00\00\00\00", i32 131 }, %struct.anon { i32 4, [10 x i8] c"ERR \00\00\00\00\00\00", i32 131 }, %struct.anon { i32 8, [10 x i8] c"WARNING \00\00", i32 128 }, %struct.anon { i32 5, [10 x i8] c"WARN \00\00\00\00\00", i32 128 }, %struct.anon { i32 4, [10 x i8] c"WAR \00\00\00\00\00\00", i32 128 }, %struct.anon { i32 7, [10 x i8] c"NOTICE \00\00\00", i32 129 }, %struct.anon { i32 5, [10 x i8] c"NOTE \00\00\00\00\00", i32 129 }, %struct.anon { i32 4, [10 x i8] c"NOT \00\00\00\00\00\00", i32 129 }, %struct.anon { i32 5, [10 x i8] c"INFO \00\00\00\00\00", i32 130 }, %struct.anon { i32 4, [10 x i8] c"INF \00\00\00\00\00\00", i32 130 }, %struct.anon { i32 6, [10 x i8] c"DEBUG \00\00\00\00", i32 133 }, %struct.anon { i32 4, [10 x i8] c"DBG \00\00\00\00\00\00", i32 133 }, %struct.anon { i32 0, [10 x i8] zeroinitializer, i32 131 }]
define i32 @slg_write(i32* %0, i8* %1, i32 %2) {
%4 = add nsw i32 %2, 1
%5 = tail call i8* @malloc(i32 %4)
%6 = icmp eq i8* %5, null
br i1 %6, label %25, label %7
7: ; preds = %3
%8 = tail call i32 @strlcpy(i8* %5, i8* %1, i32 %4)
br label %9
9: ; preds = %9, %7
%10 = phi i64 [ %16, %9 ], [ 0, %7 ]
%11 = getelementptr inbounds [20 x %struct.anon], [20 x %struct.anon]* @slg_write.mapping, i64 0, i64 %10, i32 1, i64 0
%12 = getelementptr inbounds [20 x %struct.anon], [20 x %struct.anon]* @slg_write.mapping, i64 0, i64 %10, i32 0
%13 = load i32, i32* %12
%14 = tail call i64 @strncmp(i8* %5, i8* %11, i32 %13)
%15 = icmp eq i64 %14, 0
%16 = add nuw i64 %10, 1
br i1 %15, label %17, label %9
17: ; preds = %9
%18 = and i64 %10, 4294967295
%19 = getelementptr inbounds [20 x %struct.anon], [20 x %struct.anon]* @slg_write.mapping, i64 0, i64 %18, i32 2
%20 = load i32, i32* %19
%21 = sext i32 %13 to i64
%22 = getelementptr inbounds i8, i8* %5, i64 %21
%23 = tail call i32 @xsyslog(i32* %0, i32 %20, i8* %22)
%24 = tail call i32 @free(i8* %5)
br label %25
25: ; preds = %3, %17
%26 = phi i32 [ %2, %17 ], [ 0, %3 ]
ret i32 %26
}