#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 */
struct evbuffer {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ log_err(char *);
int /*<<< orphan*/ sl_forward(struct evbuffer *, unsigned short, char *,
                              char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
char *strchr(char *, char);
int strlen(char *);
void sl_forward_with_host(struct evbuffer *out, unsigned short pri, char *tag,
                          char *msg, char *host) {
  size_t len;
  char *tmp;
  tmp = strchr(tag, '[');
  if (tmp != NULL)
    *tmp = '\0';
  len = strlen(tag) + strlen(host) + 2;
  if (len > 1024) {
    log_err("[r] syslog message too long\n");
    return;
  }
  char tag_wth_host[len];
  sprintf(tag_wth_host, "%s@%s", tag, host);
  sl_forward(out, pri, tag_wth_host, msg);
}


x86 assembly (clang, -O0):
<sl_forward_with_host>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %si,%ax
mov    %rdi,-0x8(%rbp)
mov    %ax,-0xa(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x5b,%esi
call   1040 <strchr@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     1193 <sl_forward_with_host+0x43>
mov    -0x38(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x4c(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x4c(%rbp),%eax
add    %ecx,%eax
add    $0x2,%eax
cltq
mov    %rax,-0x30(%rbp)
cmpq   $0x400,-0x30(%rbp)
jbe    11d7 <sl_forward_with_host+0x87>
lea    0xe33(%rip),%rdi
call   1070 <log_err@plt>
jmp    1231 <sl_forward_with_host+0xe1>
mov    -0x30(%rbp),%rax
mov    %rsp,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x58(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x48(%rbp)
mov    -0x18(%rbp),%rdx
mov    -0x28(%rbp),%rcx
lea    0xe10(%rip),%rsi
call   1060 <sprintf@plt>
mov    -0x58(%rbp),%rdx
mov    -0x8(%rbp),%rdi
mov    -0xa(%rbp),%ax
mov    -0x20(%rbp),%rcx
movzwl %ax,%esi
call   1050 <sl_forward@plt>
mov    -0x40(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sl_forward_with_host>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8,%r13
mov    %rcx,%r12
mov    %rdx,%r15
mov    %esi,-0x2c(%rbp)
mov    %rdi,%rbx
mov    %rdx,%rdi
mov    $0x5b,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     1185 <sl_forward_with_host+0x35>
movb   $0x0,(%rax)
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    %eax,%r14d
mov    %r13,%rdi
call   1030 <strlen@plt>
add    %r14d,%eax
add    $0x2,%eax
cmp    $0x401,%eax
jb     11bf <sl_forward_with_host+0x6f>
lea    0xe54(%rip),%rdi
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <log_err@plt>
mov    %rsp,-0x38(%rbp)
mov    %eax,%eax
mov    %rbx,%r14
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    0xe3d(%rip),%rsi
mov    %rbx,%rdi
mov    %r15,%rdx
mov    %r13,%rcx
call   1060 <sprintf@plt>
movzwl -0x2c(%rbp),%esi
mov    %r14,%rdi
mov    %rbx,%rdx
mov    %r12,%rcx
call   1050 <sl_forward@plt>
mov    -0x38(%rbp),%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.evbuffer = type { i32 }
@.str = [29 x i8] c"[r] syslog message too long\0A\00"
@.str.1 = [6 x i8] c"%s@%s\00"
define void @sl_forward_with_host(%struct.evbuffer* %0, i16 zeroext %1, i8* %2, i8* %3, i8* %4) {
%6 = alloca %struct.evbuffer*
%7 = alloca i16
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i64
store %struct.evbuffer* %0, %struct.evbuffer** %6
store i16 %1, i16* %7
store i8* %2, i8** %8
store i8* %3, i8** %9
store i8* %4, i8** %10
%15 = load i8*, i8** %8
%16 = call i8* @strchr(i8* %15, i8 signext 91)
store i8* %16, i8** %12
%17 = load i8*, i8** %12
%18 = icmp ne i8* %17, null
br i1 %18, label %19, label %21
19: ; preds = %5
%20 = load i8*, i8** %12
store i8 0, i8* %20
br label %21
21: ; preds = %19, %5
%22 = load i8*, i8** %8
%23 = call i32 @strlen(i8* %22)
%24 = load i8*, i8** %10
%25 = call i32 @strlen(i8* %24)
%26 = add nsw i32 %23, %25
%27 = add nsw i32 %26, 2
%28 = sext i32 %27 to i64
store i64 %28, i64* %11
%29 = load i64, i64* %11
%30 = icmp ugt i64 %29, 1024
br i1 %30, label %31, label %33
31: ; preds = %21
%32 = call i32 @log_err(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
br label %45
33: ; preds = %21
%34 = load i64, i64* %11
%35 = call i8* @llvm.stacksave()
store i8* %35, i8** %13
%36 = alloca i8, i64 %34
store i64 %34, i64* %14
%37 = load i8*, i8** %8
%38 = load i8*, i8** %10
%39 = call i32 @sprintf(i8* %36, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %37, i8* %38)
%40 = load %struct.evbuffer*, %struct.evbuffer** %6
%41 = load i16, i16* %7
%42 = load i8*, i8** %9
%43 = call i32 @sl_forward(%struct.evbuffer* %40, i16 zeroext %41, i8* %36, i8* %42)
%44 = load i8*, i8** %13
br label %45
45: ; preds = %33, %31
ret void
}

LLVM IR (-O2):
%struct.evbuffer = type { i32 }
@.str = [29 x i8] c"[r] syslog message too long\0A\00"
@.str.1 = [6 x i8] c"%s@%s\00"
define void @sl_forward_with_host(%struct.evbuffer* %0, i16 zeroext %1, i8* %2, i8* %3, i8* %4) {
%6 = tail call i8* @strchr(i8* dereferenceable(1) %2, i8 signext 91)
%7 = icmp eq i8* %6, null
br i1 %7, label %9, label %8
8: ; preds = %5
store i8 0, i8* %6
br label %9
9: ; preds = %8, %5
%10 = tail call i32 @strlen(i8* %2)
%11 = tail call i32 @strlen(i8* %4)
%12 = add i32 %10, 2
%13 = add i32 %12, %11
%14 = icmp ugt i32 %13, 1024
br i1 %14, label %15, label %17
15: ; preds = %9
%16 = tail call i32 @log_err(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
br label %23
17: ; preds = %9
%18 = zext i32 %13 to i64
%19 = tail call i8* @llvm.stacksave()
%20 = alloca i8, i64 %18
%21 = call i32 @sprintf(i8* %20, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %2, i8* %4)
%22 = call i32 @sl_forward(%struct.evbuffer* %0, i16 zeroext %1, i8* %20, i8* %3)
br label %23
23: ; preds = %17, %15
ret void
}