#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 /*<<< orphan*/ snprintf(char *, int, char *, char const *, char const *,
                            int, ...);
int /*<<< orphan*/ vsnprintf(char *, int, char const *, int /*<<< orphan*/);
void pcbc_log_formatter(char *buf, int buf_size, const char *severity,
                        const char *subsystem, int srcline, int instance_id,
                        void *instance_ptr, int is_lcb, const char *fmt,
                        va_list ap) {
  char msg[1024] = {0};
  int i;
  vsnprintf(msg, 1024, fmt, ap);
  msg[1024 - 1] = '\0';
  for (i = 0; i < 1024; i++) {
    if (msg[i] == '\n' || msg[i] == '\r') {
      msg[i] = ' ';
    }
  }
  if (is_lcb) {
    snprintf(buf, buf_size, "[cb,%s] (%s L:%d I:%u) %s", severity, subsystem,
             srcline, (unsigned int)instance_id, msg);
  } else if (instance_ptr) {
    snprintf(buf, buf_size, "[cb,%s] (%s L:%d) %s. I=%p", severity, subsystem,
             srcline, msg, instance_ptr);
  } else {
    snprintf(buf, buf_size, "[cb,%s] (%s L:%d) %s", severity, subsystem,
             srcline, msg);
  }
}


x86 assembly (clang, -O0):
<pcbc_log_formatter>:
push   %rbp
mov    %rsp,%rbp
sub    $0x450,%rsp
mov    0x28(%rbp),%eax
mov    0x20(%rbp),%rax
mov    0x18(%rbp),%eax
mov    0x10(%rbp),%rax
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    %r9d,-0x28(%rbp)
lea    -0x430(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1050 <memset@plt>
lea    -0x430(%rbp),%rdi
mov    0x20(%rbp),%rdx
mov    0x28(%rbp),%ecx
mov    $0x400,%esi
call   1030 <vsnprintf@plt>
movb   $0x0,-0x31(%rbp)
movl   $0x0,-0x434(%rbp)
cmpl   $0x400,-0x434(%rbp)
jge    1201 <pcbc_log_formatter+0xd1>
movslq -0x434(%rbp),%rax
movsbl -0x430(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
je     11d9 <pcbc_log_formatter+0xa9>
movslq -0x434(%rbp),%rax
movsbl -0x430(%rbp,%rax,1),%eax
ff
cmp    $0xd,%eax
jne    11e8 <pcbc_log_formatter+0xb8>
movslq -0x434(%rbp),%rax
movb   $0x20,-0x430(%rbp,%rax,1)
20
jmp    11ed <pcbc_log_formatter+0xbd>
mov    -0x434(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x434(%rbp)
jmp    1199 <pcbc_log_formatter+0x69>
cmpl   $0x0,0x18(%rbp)
je     1245 <pcbc_log_formatter+0x115>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%r8
mov    -0x24(%rbp),%r9d
mov    -0x28(%rbp),%r10d
lea    -0x430(%rbp),%rax
lea    0xdd0(%rip),%rdx
mov    %r10d,(%rsp)
mov    %rax,0x8(%rsp)
mov    $0x0,%al
call   1040 <snprintf@plt>
jmp    12bb <pcbc_log_formatter+0x18b>
cmpq   $0x0,0x10(%rbp)
je     128a <pcbc_log_formatter+0x15a>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%r8
mov    -0x24(%rbp),%r9d
lea    -0x430(%rbp),%r10
mov    0x10(%rbp),%rax
lea    0xda5(%rip),%rdx
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
mov    $0x0,%al
call   1040 <snprintf@plt>
jmp    12b6 <pcbc_log_formatter+0x186>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%r8
mov    -0x24(%rbp),%r9d
lea    -0x430(%rbp),%rax
lea    0xd8a(%rip),%rdx
mov    %rax,(%rsp)
mov    $0x0,%al
call   1040 <snprintf@plt>
jmp    12bb <pcbc_log_formatter+0x18b>
add    $0x450,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pcbc_log_formatter>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x428,%rsp
mov    %r9,0x18(%rsp)
mov    %r8d,0x4(%rsp)
mov    %rcx,0x10(%rsp)
mov    %rdx,0x8(%rsp)
mov    %esi,%ebp
mov    %rdi,%r13
mov    0x470(%rsp),%r14
mov    0x478(%rsp),%r15d
lea    0x20(%rsp),%rbx
xor    %r12d,%r12d
mov    $0x400,%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1050 <memset@plt>
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %r14,%rdx
mov    %r15d,%ecx
call   1030 <vsnprintf@plt>
movb   $0x0,0x41f(%rsp)
jmp    11b3 <pcbc_log_formatter+0x83>
xchg   %ax,%ax
movb   $0x20,0x23(%rsp,%r12,1)
add    $0x4,%r12
cmp    $0x400,%r12
je     11ff <pcbc_log_formatter+0xcf>
movzbl 0x20(%rsp,%r12,1),%eax
cmp    $0xd,%al
je     11c1 <pcbc_log_formatter+0x91>
cmp    $0xa,%al
jne    11c7 <pcbc_log_formatter+0x97>
movb   $0x20,0x20(%rsp,%r12,1)
movzbl 0x21(%rsp,%r12,1),%eax
cmp    $0xd,%al
je     11d5 <pcbc_log_formatter+0xa5>
cmp    $0xa,%al
jne    11db <pcbc_log_formatter+0xab>
movb   $0x20,0x21(%rsp,%r12,1)
movzbl 0x22(%rsp,%r12,1),%eax
cmp    $0xd,%al
je     11e9 <pcbc_log_formatter+0xb9>
cmp    $0xa,%al
jne    11ef <pcbc_log_formatter+0xbf>
movb   $0x20,0x22(%rsp,%r12,1)
movzbl 0x23(%rsp,%r12,1),%eax
cmp    $0xd,%al
je     11a0 <pcbc_log_formatter+0x70>
cmp    $0xa,%al
je     11a0 <pcbc_log_formatter+0x70>
jmp    11a6 <pcbc_log_formatter+0x76>
cmpl   $0x0,0x468(%rsp)
je     1232 <pcbc_log_formatter+0x102>
lea    0xdf0(%rip),%rdx
mov    %r13,%rdi
mov    %ebp,%esi
mov    0x8(%rsp),%rcx
mov    0x10(%rsp),%r8
mov    0x4(%rsp),%r9d
xor    %eax,%eax
lea    0x20(%rsp),%rbp
push   %rbp
push   0x20(%rsp)
jmp    1286 <pcbc_log_formatter+0x156>
mov    0x460(%rsp),%rbx
test   %rbx,%rbx
je     125f <pcbc_log_formatter+0x12f>
lea    0xdd4(%rip),%rdx
mov    %r13,%rdi
mov    %ebp,%esi
mov    0x8(%rsp),%rcx
mov    0x10(%rsp),%r8
mov    0x4(%rsp),%r9d
xor    %eax,%eax
push   %rbx
jmp    1280 <pcbc_log_formatter+0x150>
sub    $0x8,%rsp
lea    0xdcb(%rip),%rdx
mov    %r13,%rdi
mov    %ebp,%esi
mov    0x10(%rsp),%rcx
mov    0x18(%rsp),%r8
mov    0xc(%rsp),%r9d
xor    %eax,%eax
lea    0x28(%rsp),%rbp
push   %rbp
call   1040 <snprintf@plt>
add    $0x10,%rsp
add    $0x428,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [26 x i8] c"[cb,%s] (%s L:%d I:%u) %s\00"
@.str.1 = [27 x i8] c"[cb,%s] (%s L:%d) %s. I=%p\00"
@.str.2 = [21 x i8] c"[cb,%s] (%s L:%d) %s\00"
define void @pcbc_log_formatter(i8* %0, i32 %1, i8* %2, i8* %3, i32 %4, i32 %5, i8* %6, i32 %7, i8* %8, i32 %9) {
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i8*
%14 = alloca i8*
%15 = alloca i32
%16 = alloca i32
%17 = alloca i8*
%18 = alloca i32
%19 = alloca i8*
%20 = alloca i32
%21 = alloca [1024 x i8]
%22 = alloca i32
store i8* %0, i8** %11
store i32 %1, i32* %12
store i8* %2, i8** %13
store i8* %3, i8** %14
store i32 %4, i32* %15
store i32 %5, i32* %16
store i8* %6, i8** %17
store i32 %7, i32* %18
store i8* %8, i8** %19
store i32 %9, i32* %20
%23 = bitcast [1024 x i8]* %21 to i8*
%24 = getelementptr inbounds [1024 x i8], [1024 x i8]* %21, i64 0, i64 0
%25 = load i8*, i8** %19
%26 = load i32, i32* %20
%27 = call i32 @vsnprintf(i8* %24, i32 1024, i8* %25, i32 %26)
%28 = getelementptr inbounds [1024 x i8], [1024 x i8]* %21, i64 0, i64 1023
store i8 0, i8* %28
store i32 0, i32* %22
br label %29
29: ; preds = %51, %10
%30 = load i32, i32* %22
%31 = icmp slt i32 %30, 1024
br i1 %31, label %32, label %54
32: ; preds = %29
%33 = load i32, i32* %22
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [1024 x i8], [1024 x i8]* %21, i64 0, i64 %34
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = icmp eq i32 %37, 10
br i1 %38, label %46, label %39
39: ; preds = %32
%40 = load i32, i32* %22
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds [1024 x i8], [1024 x i8]* %21, i64 0, i64 %41
%43 = load i8, i8* %42
%44 = sext i8 %43 to i32
%45 = icmp eq i32 %44, 13
br i1 %45, label %46, label %50
46: ; preds = %39, %32
%47 = load i32, i32* %22
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds [1024 x i8], [1024 x i8]* %21, i64 0, i64 %48
store i8 32, i8* %49
br label %50
50: ; preds = %46, %39
br label %51
51: ; preds = %50
%52 = load i32, i32* %22
%53 = add nsw i32 %52, 1
store i32 %53, i32* %22
br label %29
54: ; preds = %29
%55 = load i32, i32* %18
%56 = icmp ne i32 %55, 0
br i1 %56, label %57, label %66
57: ; preds = %54
%58 = load i8*, i8** %11
%59 = load i32, i32* %12
%60 = load i8*, i8** %13
%61 = load i8*, i8** %14
%62 = load i32, i32* %15
%63 = load i32, i32* %16
%64 = getelementptr inbounds [1024 x i8], [1024 x i8]* %21, i64 0, i64 0
%65 = call i32 (i8*, i32, i8*, i8*, i8*, i32, ...) @snprintf(i8* %58, i32 %59, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %60, i8* %61, i32 %62, i32 %63, i8* %64)
br label %87
66: ; preds = %54
%67 = load i8*, i8** %17
%68 = icmp ne i8* %67, null
br i1 %68, label %69, label %78
69: ; preds = %66
%70 = load i8*, i8** %11
%71 = load i32, i32* %12
%72 = load i8*, i8** %13
%73 = load i8*, i8** %14
%74 = load i32, i32* %15
%75 = getelementptr inbounds [1024 x i8], [1024 x i8]* %21, i64 0, i64 0
%76 = load i8*, i8** %17
%77 = call i32 (i8*, i32, i8*, i8*, i8*, i32, ...) @snprintf(i8* %70, i32 %71, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %72, i8* %73, i32 %74, i8* %75, i8* %76)
br label %86
78: ; preds = %66
%79 = load i8*, i8** %11
%80 = load i32, i32* %12
%81 = load i8*, i8** %13
%82 = load i8*, i8** %14
%83 = load i32, i32* %15
%84 = getelementptr inbounds [1024 x i8], [1024 x i8]* %21, i64 0, i64 0
%85 = call i32 (i8*, i32, i8*, i8*, i8*, i32, ...) @snprintf(i8* %79, i32 %80, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %81, i8* %82, i32 %83, i8* %84)
br label %86
86: ; preds = %78, %69
br label %87
87: ; preds = %86, %57
ret void
}

LLVM IR (-O2):
@.str = [26 x i8] c"[cb,%s] (%s L:%d I:%u) %s\00"
@.str.1 = [27 x i8] c"[cb,%s] (%s L:%d) %s. I=%p\00"
@.str.2 = [21 x i8] c"[cb,%s] (%s L:%d) %s\00"
define void @pcbc_log_formatter(i8* %0, i32 %1, i8* %2, i8* %3, i32 %4, i32 %5, i8* %6, i32 %7, i8* nocapture %8, i32 %9) {
%11 = alloca [1024 x i8]
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%13 = call i32 @vsnprintf(i8* %12, i32 1024, i8* %8, i32 %9)
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 1023
store i8 0, i8* %14
br label %15
15: ; preds = %35, %10
%16 = phi i64 [ 0, %10 ], [ %36, %35 ]
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 %16
%18 = load i8, i8* %17
switch i8 %18, label %20 [
i8 10, label %19
i8 13, label %19
]
19: ; preds = %15, %15
store i8 32, i8* %17
br label %20
20: ; preds = %15, %19
%21 = or i64 %16, 1
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 %21
%23 = load i8, i8* %22
switch i8 %23, label %25 [
i8 10, label %24
i8 13, label %24
]
24: ; preds = %20, %20
store i8 32, i8* %22
br label %25
25: ; preds = %24, %20
%26 = or i64 %16, 2
%27 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 %26
%28 = load i8, i8* %27
switch i8 %28, label %30 [
i8 10, label %29
i8 13, label %29
]
29: ; preds = %25, %25
store i8 32, i8* %27
br label %30
30: ; preds = %29, %25
%31 = or i64 %16, 3
%32 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 %31
%33 = load i8, i8* %32
switch i8 %33, label %35 [
i8 10, label %34
i8 13, label %34
]
34: ; preds = %30, %30
store i8 32, i8* %32
br label %35
35: ; preds = %34, %30
%36 = add nuw nsw i64 %16, 4
%37 = icmp eq i64 %36, 1024
br i1 %37, label %38, label %15
38: ; preds = %35
%39 = icmp eq i32 %7, 0
br i1 %39, label %42, label %40
40: ; preds = %38
%41 = call i32 (i8*, i32, i8*, i8*, i8*, i32, ...) @snprintf(i8* %0, i32 %1, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %2, i8* %3, i32 %4, i32 %5, i8* %12)
br label %48
42: ; preds = %38
%43 = icmp eq i8* %6, null
br i1 %43, label %46, label %44
44: ; preds = %42
%45 = call i32 (i8*, i32, i8*, i8*, i8*, i32, ...) @snprintf(i8* %0, i32 %1, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %2, i8* %3, i32 %4, i8* %12, i8* %6)
br label %48
46: ; preds = %42
%47 = call i32 (i8*, i32, i8*, i8*, i8*, i32, ...) @snprintf(i8* %0, i32 %1, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %2, i8* %3, i32 %4, i8* %12)
br label %48
48: ; preds = %44, %46, %40
ret void
}