#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 */
int /*<<< orphan*/ event_log(int, char *);
int /*<<< orphan*/ evutil_snprintf(char *, int, char *, int /*<<< orphan*/);
int /*<<< orphan*/ evutil_vsnprintf(char *, int, char const *,
                                    int /*<<< orphan*/);
int /*<<< orphan*/ strerror(int);
size_t strlen(char *);
void _warn_helper(int severity, int log_errno, const char *fmt, va_list ap) {
  char buf[1024];
  size_t len;
  if (fmt != NULL)
    evutil_vsnprintf(buf, sizeof(buf), fmt, ap);
  else
    buf[0] = '\0';
  if (log_errno >= 0) {
    len = strlen(buf);
    if (len < sizeof(buf) - 3) {
      evutil_snprintf(buf + len, sizeof(buf) - len, ": %s",
                      strerror(log_errno));
    }
  }
  event_log(severity, buf);
}


x86 assembly (clang, -O0):
<_warn_helper>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1190 <_warn_helper+0x40>
lea    -0x420(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x14(%rbp),%ecx
mov    $0x400,%esi
call   1050 <evutil_vsnprintf@plt>
jmp    1197 <_warn_helper+0x47>
movb   $0x0,-0x420(%rbp)
cmpl   $0x0,-0x8(%rbp)
jl     1214 <_warn_helper+0xc4>
lea    -0x420(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x428(%rbp)
cmpq   $0x3fd,-0x428(%rbp)
jae    120f <_warn_helper+0xbf>
lea    -0x420(%rbp),%rax
add    -0x428(%rbp),%rax
mov    %rax,-0x438(%rbp)
mov    $0x400,%eax
sub    -0x428(%rbp),%rax
mov    %eax,-0x42c(%rbp)
mov    -0x8(%rbp),%edi
call   1070 <strerror@plt>
mov    -0x438(%rbp),%rdi
mov    -0x42c(%rbp),%esi
mov    %eax,%ecx
lea    0xdf6(%rip),%rdx
call   1040 <evutil_snprintf@plt>
jmp    1214 <_warn_helper+0xc4>
mov    -0x4(%rbp),%edi
lea    -0x420(%rbp),%rsi
call   1060 <event_log@plt>
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_warn_helper>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x408,%rsp
mov    %esi,%ebp
mov    %edi,%r15d
test   %rdx,%rdx
je     117a <_warn_helper+0x2a>
mov    %rsp,%rdi
mov    $0x400,%esi
call   1050 <evutil_vsnprintf@plt>
test   %ebp,%ebp
jns    1182 <_warn_helper+0x32>
jmp    11b7 <_warn_helper+0x67>
movb   $0x0,(%rsp)
test   %ebp,%ebp
js     11b7 <_warn_helper+0x67>
mov    %rsp,%rdi
call   1030 <strlen@plt>
cmp    $0x3fc,%rax
ja     11b7 <_warn_helper+0x67>
lea    (%rsp,%rax,1),%r14
mov    $0x400,%ebx
sub    %eax,%ebx
mov    %ebp,%edi
call   1070 <strerror@plt>
lea    0xe55(%rip),%rdx
mov    %r14,%rdi
mov    %ebx,%esi
mov    %eax,%ecx
call   1040 <evutil_snprintf@plt>
mov    %rsp,%rsi
mov    %r15d,%edi
call   1060 <event_log@plt>
add    $0x408,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c": %s\00"
define void @_warn_helper(i32 %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca [1024 x i8]
%10 = alloca i64
store i32 %0, i32* %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%11 = load i8*, i8** %7
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %18
13: ; preds = %4
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%15 = load i8*, i8** %7
%16 = load i32, i32* %8
%17 = call i32 @evutil_vsnprintf(i8* %14, i32 1024, i8* %15, i32 %16)
br label %20
18: ; preds = %4
%19 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
store i8 0, i8* %19
br label %20
20: ; preds = %18, %13
%21 = load i32, i32* %6
%22 = icmp sge i32 %21, 0
br i1 %22, label %23, label %39
23: ; preds = %20
%24 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%25 = call i64 @strlen(i8* %24)
store i64 %25, i64* %10
%26 = load i64, i64* %10
%27 = icmp ult i64 %26, 1021
br i1 %27, label %28, label %38
28: ; preds = %23
%29 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%30 = load i64, i64* %10
%31 = getelementptr inbounds i8, i8* %29, i64 %30
%32 = load i64, i64* %10
%33 = sub i64 1024, %32
%34 = trunc i64 %33 to i32
%35 = load i32, i32* %6
%36 = call i32 @strerror(i32 %35)
%37 = call i32 @evutil_snprintf(i8* %31, i32 %34, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %36)
br label %38
38: ; preds = %28, %23
br label %39
39: ; preds = %38, %20
%40 = load i32, i32* %5
%41 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%42 = call i32 @event_log(i32 %40, i8* %41)
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c": %s\00"
define void @_warn_helper(i32 %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca [1024 x i8]
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%7 = icmp eq i8* %2, null
br i1 %7, label %10, label %8
8: ; preds = %4
%9 = call i32 @evutil_vsnprintf(i8* %6, i32 1024, i8* %2, i32 %3)
br label %11
10: ; preds = %4
store i8 0, i8* %6
br label %11
11: ; preds = %10, %8
%12 = icmp sgt i32 %1, -1
br i1 %12, label %13, label %22
13: ; preds = %11
%14 = call i64 @strlen(i8* %6)
%15 = icmp ult i64 %14, 1021
br i1 %15, label %16, label %22
16: ; preds = %13
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 %14
%18 = trunc i64 %14 to i32
%19 = sub nuw nsw i32 1024, %18
%20 = call i32 @strerror(i32 %1)
%21 = call i32 @evutil_snprintf(i8* %17, i32 %19, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %20)
br label %22
22: ; preds = %13, %16, %11
%23 = call i32 @event_log(i32 %0, i8* %6)
ret void
}