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

/* Variables and functions */
int /*<<< orphan*/ SetSystemLog(unsigned char, unsigned char, unsigned char,
                                char *);
int /*<<< orphan*/ vsnprintf(char *, int, char const *, int /*<<< orphan*/);
void v_format_syslog(unsigned char log_type, unsigned char log_level,
                     unsigned char log_facility, const char *fmt, va_list ap) {
  register char *p;
  char *last_chr, *head_end, *end, *stdp;
  char tbuf[1024];
  head_end = stdp = p = tbuf;
  end = tbuf + sizeof(tbuf) - 1;
  p += vsnprintf(p, end - p, fmt, ap);
  if (p >= end) {
    p = end - 1;
  }
  last_chr = p;
  *last_chr = 0;
  SetSystemLog(log_type, log_level, log_facility, tbuf);
}


x86 assembly (clang, -O0):
<v_format_syslog>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
mov    %dl,%al
mov    %sil,%dl
mov    %dil,%sil
mov    %sil,-0x1(%rbp)
mov    %dl,-0x2(%rbp)
mov    %al,-0x3(%rbp)
mov    %rcx,-0x10(%rbp)
mov    %r8d,-0x14(%rbp)
lea    -0x440(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    %rax,-0x40(%rbp)
mov    %rax,-0x30(%rbp)
lea    -0x440(%rbp),%rax
add    $0x400,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x38(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%esi
mov    -0x10(%rbp),%rdx
mov    -0x14(%rbp),%ecx
call   1030 <vsnprintf@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x38(%rbp),%rax
jb     11b4 <v_format_syslog+0x94>
mov    -0x38(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x1(%rbp),%sil
mov    -0x2(%rbp),%dl
mov    -0x3(%rbp),%al
lea    -0x440(%rbp),%rcx
movzbl %sil,%edi
movzbl %dl,%esi
movzbl %al,%edx
call   1040 <SetSystemLog@plt>
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<v_format_syslog>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x408,%rsp
mov    %edx,%r14d
mov    %esi,%ebp
mov    %edi,%ebx
mov    %rsp,%r15
mov    %r15,%rdi
mov    $0x3ff,%esi
mov    %rcx,%rdx
mov    %r8d,%ecx
call   1030 <vsnprintf@plt>
cltq
cmp    $0x3ff,%eax
mov    $0x3fe,%ecx
cmovl  %rax,%rcx
movb   $0x0,(%rsp,%rcx,1)
mov    %ebx,%edi
mov    %ebp,%esi
mov    %r14d,%edx
mov    %r15,%rcx
call   1040 <SetSystemLog@plt>
add    $0x408,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @v_format_syslog(i8 zeroext %0, i8 zeroext %1, i8 zeroext %2, i8* %3, i32 %4) {
%6 = alloca i8
%7 = alloca i8
%8 = alloca i8
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i8*
%15 = alloca i8*
%16 = alloca [1024 x i8]
store i8 %0, i8* %6
store i8 %1, i8* %7
store i8 %2, i8* %8
store i8* %3, i8** %9
store i32 %4, i32* %10
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %16, i64 0, i64 0
store i8* %17, i8** %11
store i8* %17, i8** %15
store i8* %17, i8** %13
%18 = getelementptr inbounds [1024 x i8], [1024 x i8]* %16, i64 0, i64 0
%19 = getelementptr inbounds i8, i8* %18, i64 1024
%20 = getelementptr inbounds i8, i8* %19, i64 -1
store i8* %20, i8** %14
%21 = load i8*, i8** %11
%22 = load i8*, i8** %14
%23 = load i8*, i8** %11
%24 = ptrtoint i8* %22 to i64
%25 = ptrtoint i8* %23 to i64
%26 = sub i64 %24, %25
%27 = trunc i64 %26 to i32
%28 = load i8*, i8** %9
%29 = load i32, i32* %10
%30 = call i32 @vsnprintf(i8* %21, i32 %27, i8* %28, i32 %29)
%31 = load i8*, i8** %11
%32 = sext i32 %30 to i64
%33 = getelementptr inbounds i8, i8* %31, i64 %32
store i8* %33, i8** %11
%34 = load i8*, i8** %11
%35 = load i8*, i8** %14
%36 = icmp uge i8* %34, %35
br i1 %36, label %37, label %40
37: ; preds = %5
%38 = load i8*, i8** %14
%39 = getelementptr inbounds i8, i8* %38, i64 -1
store i8* %39, i8** %11
br label %40
40: ; preds = %37, %5
%41 = load i8*, i8** %11
store i8* %41, i8** %12
%42 = load i8*, i8** %12
store i8 0, i8* %42
%43 = load i8, i8* %6
%44 = load i8, i8* %7
%45 = load i8, i8* %8
%46 = getelementptr inbounds [1024 x i8], [1024 x i8]* %16, i64 0, i64 0
%47 = call i32 @SetSystemLog(i8 zeroext %43, i8 zeroext %44, i8 zeroext %45, i8* %46)
ret void
}

LLVM IR (-O2):
define void @v_format_syslog(i8 zeroext %0, i8 zeroext %1, i8 zeroext %2, i8* nocapture %3, i32 %4) {
%6 = alloca [1024 x i8]
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%8 = call i32 @vsnprintf(i8* %7, i32 1023, i8* %3, i32 %4)
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 %9
%11 = icmp slt i32 %8, 1023
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 1022
%13 = select i1 %11, i8* %10, i8* %12
store i8 0, i8* %13
%14 = call i32 @SetSystemLog(i8 zeroext %0, i8 zeroext %1, i8 zeroext %2, i8* %7)
ret void
}