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

/* Variables and functions */
int /*<<< orphan*/ sprintf(char *, char *, char const *);
int /*<<< orphan*/ strcat(char *, char *);
int strlen(char const *);
int /*<<< orphan*/ syslog(int, char *, char *);
int /*<<< orphan*/ vsnprintf(char *, int, char const *, int /*<<< orphan*/);
_log_tag(int log_level, const char *src, const char *format, va_list argptr) {
  const size_t n_prefix = strlen(src) + 1 + 1 + 1;
  char prefix[n_prefix];
  sprintf(prefix, "%s: ", src);
  char suffix[1024];
  vsnprintf(suffix, sizeof(suffix), format, argptr);
  const size_t n_suffix = strlen(suffix);
  char log_msg[n_prefix + n_suffix + 1];
  log_msg[0] = '\0';
  strcat(log_msg, prefix);
  strcat(log_msg, suffix);
  syslog(log_level, "%s", log_msg);
}


x86 assembly (clang, -O0):
<_log_tag>:
push   %rbp
mov    %rsp,%rbp
sub    $0x470,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x3,%eax
cltq
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x460(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdx
lea    0xe50(%rip),%rsi
call   1070 <sprintf@plt>
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
lea    -0x440(%rbp),%rdi
mov    %rdi,-0x468(%rbp)
mov    $0x400,%esi
call   1030 <vsnprintf@plt>
mov    -0x468(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x460(%rbp),%rsi
cltq
mov    %rax,-0x448(%rbp)
mov    -0x28(%rbp),%rcx
mov    -0x448(%rbp),%rdx
lea    0x1(%rcx,%rdx,1),%rax
lea    0x10(%rcx,%rdx,1),%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x458(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x450(%rbp)
movb   $0x0,(%rdi)
call   1060 <strcat@plt>
mov    -0x458(%rbp),%rdi
lea    -0x440(%rbp),%rsi
call   1060 <strcat@plt>
mov    -0x458(%rbp),%rdx
mov    -0x8(%rbp),%edi
lea    0xdb9(%rip),%rsi
call   1050 <syslog@plt>
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_log_tag>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x408,%rsp
mov    %ecx,%r12d
mov    %rdx,%r13
mov    %rsi,%r15
mov    %edi,-0x2c(%rbp)
mov    %rsi,%rdi
call   1040 <strlen@plt>
movslq %eax,%rbx
mov    %rsp,%r14
lea    0x12(%rbx),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
lea    0xe6d(%rip),%rsi
mov    %r14,%rdi
mov    %r15,%rdx
call   1070 <sprintf@plt>
lea    -0x430(%rbp),%r15
mov    %r15,%rdi
mov    $0x400,%esi
mov    %r13,%rdx
mov    %r12d,%ecx
call   1030 <vsnprintf@plt>
mov    %r15,%rdi
call   1040 <strlen@plt>
cltq
add    %rbx,%rax
add    $0x13,%rax
and    $0xfffffffffffffff0,%rax
mov    %rsp,%rcx
mov    %rcx,%rbx
sub    %rax,%rbx
neg    %rax
mov    %rbx,%rsp
movb   $0x0,(%rcx,%rax,1)
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <strcat@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1060 <strcat@plt>
lea    0xe08(%rip),%rsi
mov    -0x2c(%rbp),%edi
mov    %rbx,%rdx
call   1050 <syslog@plt>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%s: \00"
@.str.1 = [3 x i8] c"%s\00"
define i32 @_log_tag(i32 %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i64
%11 = alloca i8*
%12 = alloca i64
%13 = alloca [1024 x i8]
%14 = alloca i64
%15 = alloca i64
store i32 %0, i32* %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i32 %3, i32* %9
%16 = load i8*, i8** %7
%17 = call i32 @strlen(i8* %16)
%18 = add nsw i32 %17, 1
%19 = add nsw i32 %18, 1
%20 = add nsw i32 %19, 1
%21 = sext i32 %20 to i64
store i64 %21, i64* %10
%22 = load i64, i64* %10
%23 = call i8* @llvm.stacksave()
store i8* %23, i8** %11
%24 = alloca i8, i64 %22
store i64 %22, i64* %12
%25 = load i8*, i8** %7
%26 = call i32 @sprintf(i8* %24, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %25)
%27 = getelementptr inbounds [1024 x i8], [1024 x i8]* %13, i64 0, i64 0
%28 = load i8*, i8** %8
%29 = load i32, i32* %9
%30 = call i32 @vsnprintf(i8* %27, i32 1024, i8* %28, i32 %29)
%31 = getelementptr inbounds [1024 x i8], [1024 x i8]* %13, i64 0, i64 0
%32 = call i32 @strlen(i8* %31)
%33 = sext i32 %32 to i64
store i64 %33, i64* %14
%34 = load i64, i64* %10
%35 = load i64, i64* %14
%36 = add i64 %34, %35
%37 = add i64 %36, 1
%38 = alloca i8, i64 %37
store i64 %37, i64* %15
%39 = getelementptr inbounds i8, i8* %38, i64 0
store i8 0, i8* %39
%40 = call i32 @strcat(i8* %38, i8* %24)
%41 = getelementptr inbounds [1024 x i8], [1024 x i8]* %13, i64 0, i64 0
%42 = call i32 @strcat(i8* %38, i8* %41)
%43 = load i32, i32* %6
%44 = call i32 @syslog(i32 %43, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %38)
%45 = load i8*, i8** %11
%46 = load i32, i32* %5
ret i32 %46
}

LLVM IR (-O2):
@.str = [5 x i8] c"%s: \00"
@.str.1 = [3 x i8] c"%s\00"
define i32 @_log_tag(i32 %0, i8* %1, i8* nocapture %2, i32 %3) {
%5 = alloca [1024 x i8]
%6 = tail call i32 @strlen(i8* %1)
%7 = add nsw i32 %6, 3
%8 = sext i32 %7 to i64
%9 = alloca i8, i64 %8
%10 = call i32 @sprintf(i8* %9, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %1)
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%12 = call i32 @vsnprintf(i8* %11, i32 1024, i8* %2, i32 %3)
%13 = call i32 @strlen(i8* %11)
%14 = sext i32 %13 to i64
%15 = add nsw i64 %8, 1
%16 = add nsw i64 %15, %14
%17 = alloca i8, i64 %16
store i8 0, i8* %17
%18 = call i32 @strcat(i8* %17, i8* %9)
%19 = call i32 @strcat(i8* %17, i8* %11)
%20 = call i32 @syslog(i32 %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %17)
ret i32 undef
}