#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*/ assert(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ vasprintf(char **, char const *, int /*<<< orphan*/);
void log_stderr(char type, const char *format, va_list ap) {
  char *message = NULL;
  vasprintf(&message, format, ap);
  assert(message != NULL);
  switch (type) {
  case 'D':
    type = 'D';
    break;
  case 'I':
    type = '+';
    break;
  case 'W':
    type = '!';
    break;
  case 'E':
    type = '-';
    break;
  }
  fprintf(stderr, "[%c] %s\n", type, message);
  free(message);
}


x86 assembly (clang, -O0):
<log_stderr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
lea    -0x20(%rbp),%rdi
call   1040 <vasprintf@plt>
mov    -0x20(%rbp),%rax
test   %rax,%rax
setne  %al
movzbl %al,%edi
call   1050 <assert@plt>
movsbl -0x1(%rbp),%eax
add    $0xffffffbc,%eax
mov    %eax,%ecx
mov    %rcx,-0x28(%rbp)
sub    $0x13,%eax
ja     11c8 <log_stderr+0x88>
mov    -0x28(%rbp),%rax
lea    0xe60(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movb   $0x44,-0x1(%rbp)
jmp    11c8 <log_stderr+0x88>
movb   $0x2b,-0x1(%rbp)
jmp    11c8 <log_stderr+0x88>
movb   $0x21,-0x1(%rbp)
jmp    11c8 <log_stderr+0x88>
movb   $0x2d,-0x1(%rbp)
mov    0x2e11(%rip),%rax
mov    (%rax),%edi
mov    -0x1(%rbp),%al
mov    -0x20(%rbp),%rcx
lea    0xe71(%rip),%rsi
movsbl %al,%edx
call   1060 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<log_stderr>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
movq   $0x0,0x8(%rsp)
lea    0x8(%rsp),%rdi
call   1040 <vasprintf@plt>
xor    %edi,%edi
cmpq   $0x0,0x8(%rsp)
setne  %dil
call   1050 <assert@plt>
mov    %ebx,%eax
add    $0xffffffbc,%eax
cmp    $0x13,%eax
ja     1193 <log_stderr+0x53>
lea    0xe84(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    $0x44,%bl
jmp    1193 <log_stderr+0x53>
mov    $0x2d,%bl
jmp    1193 <log_stderr+0x53>
mov    $0x2b,%bl
jmp    1193 <log_stderr+0x53>
mov    $0x21,%bl
mov    0x2e46(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rsp),%rcx
movsbl %bl,%edx
lea    0xea5(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [9 x i8] c"[%c] %s\0A\00"
define void @log_stderr(i8 signext %0, i8* %1, i32 %2) {
%4 = alloca i8
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
store i8 %0, i8* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
store i8* null, i8** %7
%8 = load i8*, i8** %5
%9 = load i32, i32* %6
%10 = call i32 @vasprintf(i8** %7, i8* %8, i32 %9)
%11 = load i8*, i8** %7
%12 = icmp ne i8* %11, null
%13 = zext i1 %12 to i32
%14 = call i32 @assert(i32 %13)
%15 = load i8, i8* %4
%16 = sext i8 %15 to i32
switch i32 %16, label %21 [
i32 68, label %17
i32 73, label %18
i32 87, label %19
i32 69, label %20
]
17: ; preds = %3
store i8 68, i8* %4
br label %21
18: ; preds = %3
store i8 43, i8* %4
br label %21
19: ; preds = %3
store i8 33, i8* %4
br label %21
20: ; preds = %3
store i8 45, i8* %4
br label %21
21: ; preds = %3, %20, %19, %18, %17
%22 = load i32, i32* @stderr
%23 = load i8, i8* %4
%24 = load i8*, i8** %7
%25 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8 signext %23, i8* %24)
%26 = load i8*, i8** %7
%27 = call i32 @free(i8* %26)
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [9 x i8] c"[%c] %s\0A\00"
define void @log_stderr(i8 signext %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = bitcast i8** %4 to i8*
store i8* null, i8** %4
%6 = call i32 @vasprintf(i8** %4, i8* %1, i32 %2)
%7 = load i8*, i8** %4
%8 = icmp ne i8* %7, null
%9 = zext i1 %8 to i32
%10 = call i32 @assert(i32 %9)
%11 = sext i8 %0 to i32
switch i32 %11, label %16 [
i32 68, label %12
i32 73, label %13
i32 87, label %14
i32 69, label %15
]
12: ; preds = %3
br label %16
13: ; preds = %3
br label %16
14: ; preds = %3
br label %16
15: ; preds = %3
br label %16
16: ; preds = %3, %15, %14, %13, %12
%17 = phi i8 [ %0, %3 ], [ 45, %15 ], [ 33, %14 ], [ 43, %13 ], [ 68, %12 ]
%18 = load i32, i32* @stderr
%19 = load i8*, i8** %4
%20 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8 signext %17, i8* %19)
%21 = load i8*, i8** %4
%22 = call i32 @free(i8* %21)
ret void
}