#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*/ va_list;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
#define LOG_CRIT 133
#define LOG_DEBUG 132
#define LOG_ERR 131
#define LOG_INFO 130
#define LOG_NOTICE 129
#define LOG_WARNING 128
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
int /*<<< orphan*/ syslog(int const, char *, char const *, char *);
scalar_t__ vasprintf(char **, char const *, int /*<<< orphan*/);
void log_syslog(void *data, int priority, const char *file, int line,
                const char *fn, const char *format, va_list args) {
  char *str, buf[32];
  const char *prioname;
  switch (priority) {
  case LOG_CRIT:
    prioname = "FATAL";
    break;
  case LOG_ERR:
    prioname = "ERROR";
    break;
  case LOG_WARNING:
    prioname = "WARNING";
    break;
  case LOG_NOTICE:
    prioname = "NOTICE";
    break;
  case LOG_INFO:
    prioname = "INFO";
    break;
  case LOG_DEBUG:
    prioname = "DEBUG";
    break;
  default:
    snprintf(buf, sizeof(buf), "LOG-%03d", priority);
    prioname = buf;
  }
  if (vasprintf(&str, format, args) < 0)
    return;
  syslog(LOG_NOTICE, "%s: %s", prioname, str);
  free(str);
  (void)data;
}


x86 assembly (clang, -O0):
<log_syslog>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    0x10(%rbp),%eax
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
mov    -0xc(%rbp),%eax
add    $0xffffff80,%eax
mov    %eax,%ecx
mov    %rcx,-0x70(%rbp)
sub    $0x5,%eax
ja     11ea <log_syslog+0xaa>
mov    -0x70(%rbp),%rax
lea    0xe7f(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xe87(%rip),%rax
mov    %rax,-0x68(%rbp)
jmp    120a <log_syslog+0xca>
lea    0xe7d(%rip),%rax
mov    %rax,-0x68(%rbp)
jmp    120a <log_syslog+0xca>
lea    0xe73(%rip),%rax
mov    %rax,-0x68(%rbp)
jmp    120a <log_syslog+0xca>
lea    0xe6b(%rip),%rax
mov    %rax,-0x68(%rbp)
jmp    120a <log_syslog+0xca>
lea    0xe62(%rip),%rax
mov    %rax,-0x68(%rbp)
jmp    120a <log_syslog+0xca>
lea    0xe57(%rip),%rax
mov    %rax,-0x68(%rbp)
jmp    120a <log_syslog+0xca>
lea    -0x60(%rbp),%rdi
mov    -0xc(%rbp),%ecx
mov    $0x20,%esi
lea    0xe41(%rip),%rdx
call   1050 <snprintf@plt>
lea    -0x60(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x30(%rbp),%rsi
mov    0x10(%rbp),%edx
lea    -0x38(%rbp),%rdi
call   1040 <vasprintf@plt>
cmp    $0x0,%rax
jge    1229 <log_syslog+0xe9>
jmp    124b <log_syslog+0x10b>
mov    -0x68(%rbp),%rdx
mov    -0x38(%rbp),%rcx
mov    $0x81,%edi
lea    0xe0a(%rip),%rsi
call   1060 <syslog@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<log_syslog>:
push   %rbp
push   %r14
push   %rbx
sub    $0x30,%rsp
mov    %r9,%r14
mov    %esi,%ecx
mov    0x50(%rsp),%ebp
lea    -0x80(%rcx),%eax
cmp    $0x6,%eax
jae    116b <log_syslog+0x2b>
cltq
lea    0xed6(%rip),%rcx
movslq (%rcx,%rax,4),%rbx
add    %rcx,%rbx
jmp    1184 <log_syslog+0x44>
lea    0x10(%rsp),%rbx
lea    0xeaf(%rip),%rdx
mov    %rbx,%rdi
mov    $0x20,%esi
call   1050 <snprintf@plt>
lea    0x8(%rsp),%rdi
mov    %r14,%rsi
mov    %ebp,%edx
call   1040 <vasprintf@plt>
test   %rax,%rax
js     11bb <log_syslog+0x7b>
mov    0x8(%rsp),%rcx
lea    0xe8b(%rip),%rsi
mov    $0x81,%edi
mov    %rbx,%rdx
call   1060 <syslog@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"FATAL\00"
@.str.1 = [6 x i8] c"ERROR\00"
@.str.2 = [8 x i8] c"WARNING\00"
@.str.3 = [7 x i8] c"NOTICE\00"
@.str.4 = [5 x i8] c"INFO\00"
@.str.5 = [6 x i8] c"DEBUG\00"
@.str.6 = [9 x i8] c"LOG-%03d\00"
@.str.7 = [7 x i8] c"%s: %s\00"
define void @log_syslog(i8* %0, i32 %1, i8* %2, i32 %3, i8* %4, i8* %5, i32 %6) {
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i32
%15 = alloca i8*
%16 = alloca [32 x i8]
%17 = alloca i8*
store i8* %0, i8** %8
store i32 %1, i32* %9
store i8* %2, i8** %10
store i32 %3, i32* %11
store i8* %4, i8** %12
store i8* %5, i8** %13
store i32 %6, i32* %14
%18 = load i32, i32* %9
switch i32 %18, label %25 [
i32 133, label %19
i32 131, label %20
i32 128, label %21
i32 129, label %22
i32 130, label %23
i32 132, label %24
]
19: ; preds = %7
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8** %17
br label %30
20: ; preds = %7
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8** %17
br label %30
21: ; preds = %7
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8** %17
br label %30
22: ; preds = %7
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8** %17
br label %30
23: ; preds = %7
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8** %17
br label %30
24: ; preds = %7
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8** %17
br label %30
25: ; preds = %7
%26 = getelementptr inbounds [32 x i8], [32 x i8]* %16, i64 0, i64 0
%27 = load i32, i32* %9
%28 = call i32 @snprintf(i8* %26, i32 32, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i32 %27)
%29 = getelementptr inbounds [32 x i8], [32 x i8]* %16, i64 0, i64 0
store i8* %29, i8** %17
br label %30
30: ; preds = %25, %24, %23, %22, %21, %20, %19
%31 = load i8*, i8** %13
%32 = load i32, i32* %14
%33 = call i64 @vasprintf(i8** %15, i8* %31, i32 %32)
%34 = icmp slt i64 %33, 0
br i1 %34, label %35, label %36
35: ; preds = %30
br label %43
36: ; preds = %30
%37 = load i8*, i8** %17
%38 = load i8*, i8** %15
%39 = call i32 @syslog(i32 129, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0), i8* %37, i8* %38)
%40 = load i8*, i8** %15
%41 = call i32 @free(i8* %40)
%42 = load i8*, i8** %8
br label %43
43: ; preds = %36, %35
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"FATAL\00"
@.str.1 = [6 x i8] c"ERROR\00"
@.str.2 = [8 x i8] c"WARNING\00"
@.str.3 = [7 x i8] c"NOTICE\00"
@.str.4 = [5 x i8] c"INFO\00"
@.str.5 = [6 x i8] c"DEBUG\00"
@.str.6 = [9 x i8] c"LOG-%03d\00"
@.str.7 = [7 x i8] c"%s: %s\00"
@reltable.log_syslog = [6 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str.2 to i64), i64 ptrtoint ([6 x i32]* @reltable.log_syslog to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([7 x i8]* @.str.3 to i64), i64 ptrtoint ([6 x i32]* @reltable.log_syslog to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str.4 to i64), i64 ptrtoint ([6 x i32]* @reltable.log_syslog to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str.1 to i64), i64 ptrtoint ([6 x i32]* @reltable.log_syslog to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str.5 to i64), i64 ptrtoint ([6 x i32]* @reltable.log_syslog to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str to i64), i64 ptrtoint ([6 x i32]* @reltable.log_syslog to i64)) to i32)]
define void @log_syslog(i8* nocapture readnone %0, i32 %1, i8* nocapture readnone %2, i32 %3, i8* nocapture readnone %4, i8* %5, i32 %6) {
%8 = alloca i8*
%9 = alloca [32 x i8]
%10 = bitcast i8** %8 to i8*
%11 = getelementptr inbounds [32 x i8], [32 x i8]* %9, i64 0, i64 0
%12 = add i32 %1, -128
%13 = icmp ult i32 %12, 6
br i1 %13, label %16, label %14
14: ; preds = %7
%15 = call i32 @snprintf(i8* %11, i32 32, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i32 %1)
br label %20
16: ; preds = %7
%17 = sext i32 %12 to i64
%18 = shl i64 %17, 2
%19 = call i8* @llvm.load.relative.i64(i8* bitcast ([6 x i32]* @reltable.log_syslog to i8*), i64 %18)
br label %20
20: ; preds = %16, %14
%21 = phi i8* [ %11, %14 ], [ %19, %16 ]
%22 = call i64 @vasprintf(i8** %8, i8* %5, i32 %6)
%23 = icmp slt i64 %22, 0
br i1 %23, label %29, label %24
24: ; preds = %20
%25 = load i8*, i8** %8
%26 = call i32 @syslog(i32 129, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0), i8* %21, i8* %25)
%27 = load i8*, i8** %8
%28 = call i32 @free(i8* %27)
br label %29
29: ; preds = %20, %24
ret void
}