#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;

/* Variables and functions */
int LOG_INFO;
int LOG_PID;
int LOG_USER;
int O_APPEND;
int O_CREAT;
int O_WRONLY;
scalar_t__ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int /*<<< orphan*/ syslog(int, char *, ...);
int true_open(char const *, int, int);
int vsnprintf(char *, int, char const *, int /*<<< orphan*/);
int write(int, char *, int);
int vlambda_log(const char *logname, const char *format, va_list ap) {
  char buffer[1024];
  int count;
  int logfd;
  int rcod = 0;
  count = vsnprintf(buffer, 1024, format, ap);
  if (count == -1) {
    strcpy(&(buffer[1024 - 5]), "...\n");
    count = 1024 - 1;
  }
  if (logname != NULL) {
    logfd = true_open(logname, O_WRONLY | O_CREAT | O_APPEND, 0666);
    if (logfd >= 0) {
      if (write(logfd, buffer, count) != count)
        syslog((LOG_USER | LOG_INFO | LOG_PID),
               "Count not write `%s' in `%s': %s\n", buffer, logname,
               strerror(errno));
      if (close(logfd) < 0)
        syslog((LOG_USER | LOG_INFO | LOG_PID), "Could not close `%s': %s\n",
               logname, strerror(errno));
    } else {
      syslog((LOG_USER | LOG_INFO | LOG_PID),
             "Could not open `%s' to write `%s': %s\n", logname, buffer,
             strerror(errno));
    }
  } else {
    syslog((LOG_USER | LOG_INFO | LOG_PID), buffer);
  }
  return rcod;
}


x86 assembly (clang, -O0):
<vlambda_log>:
push   %rbp
mov    %rsp,%rbp
sub    $0x470,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x42c(%rbp)
lea    -0x420(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x14(%rbp),%ecx
mov    $0x400,%esi
call   1050 <vsnprintf@plt>
mov    %eax,-0x424(%rbp)
cmpl   $0xffffffff,-0x424(%rbp)
jne    11df <vlambda_log+0x6f>
lea    -0x420(%rbp),%rdi
add    $0x3fb,%rdi
lea    0xe30(%rip),%rsi
call   1040 <strcpy@plt>
movl   $0x3ff,-0x424(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     139a <vlambda_log+0x22a>
mov    -0x8(%rbp),%rdi
mov    0x2dbb(%rip),%rax
mov    (%rax),%esi
mov    0x2dfa(%rip),%rax
or     (%rax),%esi
mov    0x2da1(%rip),%rax
or     (%rax),%esi
mov    $0x1b6,%edx
call   1030 <true_open@plt>
mov    %eax,-0x428(%rbp)
cmpl   $0x0,-0x428(%rbp)
jl     1328 <vlambda_log+0x1b8>
mov    -0x428(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    -0x424(%rbp),%edx
call   1060 <write@plt>
cmp    -0x424(%rbp),%eax
je     12b7 <vlambda_log+0x147>
mov    0x2d8f(%rip),%rax
mov    (%rax),%eax
mov    0x2d66(%rip),%rcx
or     (%rcx),%eax
mov    0x2d6d(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x444(%rbp)
lea    -0x420(%rbp),%rax
mov    %rax,-0x440(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x438(%rbp)
mov    0x2d3d(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x444(%rbp),%edi
mov    -0x440(%rbp),%rdx
mov    -0x438(%rbp),%rcx
mov    %eax,%r8d
lea    0xd55(%rip),%rsi
mov    $0x0,%al
call   1080 <syslog@plt>
mov    -0x428(%rbp),%edi
call   1070 <close@plt>
cmp    $0x0,%rax
jge    1323 <vlambda_log+0x1b3>
mov    0x2d0d(%rip),%rax
mov    (%rax),%eax
mov    0x2ce4(%rip),%rcx
or     (%rcx),%eax
mov    0x2ceb(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x454(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x450(%rbp)
mov    0x2cc9(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x454(%rbp),%edi
mov    -0x450(%rbp),%rdx
mov    %eax,%ecx
lea    0xd0b(%rip),%rsi
mov    $0x0,%al
call   1080 <syslog@plt>
jmp    1395 <vlambda_log+0x225>
mov    0x2cb1(%rip),%rax
mov    (%rax),%eax
mov    0x2c88(%rip),%rcx
or     (%rcx),%eax
mov    0x2c8f(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x46c(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x468(%rbp)
lea    -0x420(%rbp),%rax
mov    %rax,-0x460(%rbp)
mov    0x2c5f(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x46c(%rbp),%edi
mov    -0x468(%rbp),%rdx
mov    -0x460(%rbp),%rcx
mov    %eax,%r8d
lea    0xcb3(%rip),%rsi
mov    $0x0,%al
call   1080 <syslog@plt>
jmp    13c3 <vlambda_log+0x253>
mov    0x2c3f(%rip),%rax
mov    (%rax),%edi
mov    0x2c16(%rip),%rax
or     (%rax),%edi
mov    0x2c1d(%rip),%rax
or     (%rax),%edi
lea    -0x420(%rbp),%rsi
mov    $0x0,%al
call   1080 <syslog@plt>
mov    -0x42c(%rbp),%eax
add    $0x470,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vlambda_log>:
push   %rbp
push   %r14
push   %rbx
sub    $0x400,%rsp
mov    %edx,%ecx
mov    %rsi,%rdx
mov    %rdi,%r14
mov    %rsp,%rdi
mov    $0x400,%esi
call   1050 <vsnprintf@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
je     127b <vlambda_log+0x10b>
test   %r14,%r14
je     129d <vlambda_log+0x12d>
mov    0x2e05(%rip),%rax
mov    0x2e46(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2deb(%rip),%rax
or     (%rax),%esi
mov    %r14,%rdi
mov    $0x1b6,%edx
call   1030 <true_open@plt>
test   %eax,%eax
js     12c4 <vlambda_log+0x154>
mov    %eax,%ebp
mov    %rsp,%rsi
mov    %eax,%edi
mov    %ebx,%edx
call   1060 <write@plt>
cmp    %ebx,%eax
je     1228 <vlambda_log+0xb8>
mov    0x2df3(%rip),%rax
mov    0x2dcc(%rip),%rcx
mov    (%rcx),%ebx
or     (%rax),%ebx
mov    0x2dd1(%rip),%rax
or     (%rax),%ebx
mov    0x2dc0(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xdef(%rip),%rsi
mov    %rsp,%rdx
mov    %ebx,%edi
mov    %r14,%rcx
mov    %eax,%r8d
xor    %eax,%eax
call   1080 <syslog@plt>
mov    %ebp,%edi
call   1070 <close@plt>
test   %rax,%rax
jns    1306 <vlambda_log+0x196>
mov    0x2da1(%rip),%rax
mov    0x2d7a(%rip),%rcx
mov    (%rcx),%ebx
or     (%rax),%ebx
mov    0x2d7f(%rip),%rax
or     (%rax),%ebx
mov    0x2d6e(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xdbf(%rip),%rsi
mov    %ebx,%edi
mov    %r14,%rdx
mov    %eax,%ecx
xor    %eax,%eax
call   1080 <syslog@plt>
jmp    1306 <vlambda_log+0x196>
lea    0x3fb(%rsp),%rdi
lea    0xd76(%rip),%rsi
call   1040 <strcpy@plt>
mov    $0x3ff,%ebx
test   %r14,%r14
jne    11a4 <vlambda_log+0x34>
mov    0x2d3c(%rip),%rax
mov    0x2d15(%rip),%rcx
mov    (%rcx),%edi
or     (%rax),%edi
mov    0x2d1a(%rip),%rax
or     (%rax),%edi
mov    %rsp,%rsi
xor    %eax,%eax
call   1080 <syslog@plt>
jmp    1306 <vlambda_log+0x196>
mov    0x2d15(%rip),%rax
mov    0x2cee(%rip),%rcx
mov    (%rcx),%ebx
or     (%rax),%ebx
mov    0x2cf3(%rip),%rax
or     (%rax),%ebx
mov    0x2ce2(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xd4d(%rip),%rsi
mov    %rsp,%rcx
mov    %ebx,%edi
mov    %r14,%rdx
mov    %eax,%r8d
xor    %eax,%eax
call   1080 <syslog@plt>
xor    %eax,%eax
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"...\0A\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_APPEND = global i32 0
@LOG_USER = global i32 0
@LOG_INFO = global i32 0
@LOG_PID = global i32 0
@.str.1 = [34 x i8] c"Count not write `%s' in `%s': %s\0A\00"
@errno = global i32 0
@.str.2 = [26 x i8] c"Could not close `%s': %s\0A\00"
@.str.3 = [39 x i8] c"Could not open `%s' to write `%s': %s\0A\00"
define i32 @vlambda_log(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca [1024 x i8]
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
store i32 0, i32* %10
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%12 = load i8*, i8** %5
%13 = load i32, i32* %6
%14 = call i32 @vsnprintf(i8* %11, i32 1024, i8* %12, i32 %13)
store i32 %14, i32* %8
%15 = load i32, i32* %8
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %20
17: ; preds = %3
%18 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 1019
%19 = call i32 @strcpy(i8* %18, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i32 1023, i32* %8
br label %20
20: ; preds = %17, %3
%21 = load i8*, i8** %4
%22 = icmp ne i8* %21, null
br i1 %22, label %23, label %78
23: ; preds = %20
%24 = load i8*, i8** %4
%25 = load i32, i32* @O_WRONLY
%26 = load i32, i32* @O_CREAT
%27 = or i32 %25, %26
%28 = load i32, i32* @O_APPEND
%29 = or i32 %27, %28
%30 = call i32 @true_open(i8* %24, i32 %29, i32 438)
store i32 %30, i32* %9
%31 = load i32, i32* %9
%32 = icmp sge i32 %31, 0
br i1 %32, label %33, label %66
33: ; preds = %23
%34 = load i32, i32* %9
%35 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%36 = load i32, i32* %8
%37 = call i32 @write(i32 %34, i8* %35, i32 %36)
%38 = load i32, i32* %8
%39 = icmp ne i32 %37, %38
br i1 %39, label %40, label %51
40: ; preds = %33
%41 = load i32, i32* @LOG_USER
%42 = load i32, i32* @LOG_INFO
%43 = or i32 %41, %42
%44 = load i32, i32* @LOG_PID
%45 = or i32 %43, %44
%46 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%47 = load i8*, i8** %4
%48 = load i32, i32* @errno
%49 = call i32 @strerror(i32 %48)
%50 = call i32 (i32, i8*, ...) @syslog(i32 %45, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8* %46, i8* %47, i32 %49)
br label %51
51: ; preds = %40, %33
%52 = load i32, i32* %9
%53 = call i64 @close(i32 %52)
%54 = icmp slt i64 %53, 0
br i1 %54, label %55, label %65
55: ; preds = %51
%56 = load i32, i32* @LOG_USER
%57 = load i32, i32* @LOG_INFO
%58 = or i32 %56, %57
%59 = load i32, i32* @LOG_PID
%60 = or i32 %58, %59
%61 = load i8*, i8** %4
%62 = load i32, i32* @errno
%63 = call i32 @strerror(i32 %62)
%64 = call i32 (i32, i8*, ...) @syslog(i32 %60, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %61, i32 %63)
br label %65
65: ; preds = %55, %51
br label %77
66: ; preds = %23
%67 = load i32, i32* @LOG_USER
%68 = load i32, i32* @LOG_INFO
%69 = or i32 %67, %68
%70 = load i32, i32* @LOG_PID
%71 = or i32 %69, %70
%72 = load i8*, i8** %4
%73 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%74 = load i32, i32* @errno
%75 = call i32 @strerror(i32 %74)
%76 = call i32 (i32, i8*, ...) @syslog(i32 %71, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0), i8* %72, i8* %73, i32 %75)
br label %77
77: ; preds = %66, %65
br label %86
78: ; preds = %20
%79 = load i32, i32* @LOG_USER
%80 = load i32, i32* @LOG_INFO
%81 = or i32 %79, %80
%82 = load i32, i32* @LOG_PID
%83 = or i32 %81, %82
%84 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%85 = call i32 (i32, i8*, ...) @syslog(i32 %83, i8* %84)
br label %86
86: ; preds = %78, %77
%87 = load i32, i32* %10
ret i32 %87
}

LLVM IR (-O2):
@.str = [5 x i8] c"...\0A\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_APPEND = global i32 0
@LOG_USER = global i32 0
@LOG_INFO = global i32 0
@LOG_PID = global i32 0
@.str.1 = [34 x i8] c"Count not write `%s' in `%s': %s\0A\00"
@errno = global i32 0
@.str.2 = [26 x i8] c"Could not close `%s': %s\0A\00"
@.str.3 = [39 x i8] c"Could not open `%s' to write `%s': %s\0A\00"
define i32 @vlambda_log(i8* %0, i8* nocapture %1, i32 %2) {
%4 = alloca [1024 x i8]
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%6 = call i32 @vsnprintf(i8* %5, i32 1024, i8* %1, i32 %2)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %11
8: ; preds = %3
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 1019
%10 = call i32 @strcpy(i8* %9, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %8, %3
%12 = phi i32 [ 1023, %8 ], [ %6, %3 ]
%13 = icmp eq i8* %0, null
br i1 %13, label %55, label %14
14: ; preds = %11
%15 = load i32, i32* @O_WRONLY
%16 = load i32, i32* @O_CREAT
%17 = or i32 %16, %15
%18 = load i32, i32* @O_APPEND
%19 = or i32 %17, %18
%20 = call i32 @true_open(i8* %0, i32 %19, i32 438)
%21 = icmp sgt i32 %20, -1
br i1 %21, label %22, label %46
22: ; preds = %14
%23 = call i32 @write(i32 %20, i8* %5, i32 %12)
%24 = icmp eq i32 %23, %12
br i1 %24, label %34, label %25
25: ; preds = %22
%26 = load i32, i32* @LOG_USER
%27 = load i32, i32* @LOG_INFO
%28 = or i32 %27, %26
%29 = load i32, i32* @LOG_PID
%30 = or i32 %28, %29
%31 = load i32, i32* @errno
%32 = call i32 @strerror(i32 %31)
%33 = call i32 (i32, i8*, ...) @syslog(i32 %30, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8* %5, i8* %0, i32 %32)
br label %34
34: ; preds = %25, %22
%35 = call i64 @close(i32 %20)
%36 = icmp slt i64 %35, 0
br i1 %36, label %37, label %62
37: ; preds = %34
%38 = load i32, i32* @LOG_USER
%39 = load i32, i32* @LOG_INFO
%40 = or i32 %39, %38
%41 = load i32, i32* @LOG_PID
%42 = or i32 %40, %41
%43 = load i32, i32* @errno
%44 = call i32 @strerror(i32 %43)
%45 = call i32 (i32, i8*, ...) @syslog(i32 %42, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %0, i32 %44)
br label %62
46: ; preds = %14
%47 = load i32, i32* @LOG_USER
%48 = load i32, i32* @LOG_INFO
%49 = or i32 %48, %47
%50 = load i32, i32* @LOG_PID
%51 = or i32 %49, %50
%52 = load i32, i32* @errno
%53 = call i32 @strerror(i32 %52)
%54 = call i32 (i32, i8*, ...) @syslog(i32 %51, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0), i8* %0, i8* %5, i32 %53)
br label %62
55: ; preds = %11
%56 = load i32, i32* @LOG_USER
%57 = load i32, i32* @LOG_INFO
%58 = or i32 %57, %56
%59 = load i32, i32* @LOG_PID
%60 = or i32 %58, %59
%61 = call i32 (i32, i8*, ...) @syslog(i32 %60, i8* %5)
br label %62
62: ; preds = %46, %37, %34, %55
ret i32 0
}