#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*/ msgbuf;
typedef int /*<<< orphan*/ fmtbuf;

/* Variables and functions */
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *, char const *);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ vsnprintf(char *, int, char *, int /*<<< orphan*/);
void do_log(const char *fmt, va_list args, const char *type) {
  char msgbuf[1024];
  char fmtbuf[1024];
  snprintf(fmtbuf, sizeof(fmtbuf), "[%s] %s\n", type, fmt);
  vsnprintf(msgbuf, sizeof(msgbuf), fmtbuf, args);
  fprintf(stdout, "%s", msgbuf);
  fflush(stdout);
}


x86 assembly (clang, -O0):
<do_log>:
push   %rbp
mov    %rsp,%rbp
sub    $0x820,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0x820(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    -0x8(%rbp),%r8
mov    $0x400,%esi
lea    0xe8f(%rip),%rdx
call   1040 <snprintf@plt>
lea    -0x420(%rbp),%rdi
lea    -0x820(%rbp),%rdx
mov    -0xc(%rbp),%ecx
mov    $0x400,%esi
call   1030 <vsnprintf@plt>
mov    0x2e48(%rip),%rax
mov    (%rax),%edi
lea    -0x420(%rbp),%rdx
lea    0xe61(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2e2c(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
add    $0x820,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_log>:
push   %r15
push   %r14
push   %rbx
sub    $0x800,%rsp
mov    %rdx,%rcx
mov    %esi,%ebx
mov    %rdi,%r8
lea    0xea5(%rip),%rdx
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x400,%esi
call   1040 <snprintf@plt>
lea    0x400(%rsp),%r15
mov    %r15,%rdi
mov    $0x400,%esi
mov    %r14,%rdx
mov    %ebx,%ecx
call   1030 <vsnprintf@plt>
mov    0x2e54(%rip),%rbx
mov    (%rbx),%edi
lea    0xe74(%rip),%rsi
mov    %r15,%rdx
call   1050 <fprintf@plt>
mov    (%rbx),%edi
call   1060 <fflush@plt>
add    $0x800,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [9 x i8] c"[%s] %s\0A\00"
@stdout = global i32 0
@.str.1 = [3 x i8] c"%s\00"
define void @do_log(i8* %0, i32 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca [1024 x i8]
%8 = alloca [1024 x i8]
store i8* %0, i8** %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%10 = load i8*, i8** %6
%11 = load i8*, i8** %4
%12 = call i32 @snprintf(i8* %9, i32 1024, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %10, i8* %11)
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%15 = load i32, i32* %5
%16 = call i32 @vsnprintf(i8* %13, i32 1024, i8* %14, i32 %15)
%17 = load i32, i32* @stdout
%18 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%19 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %18)
%20 = load i32, i32* @stdout
%21 = call i32 @fflush(i32 %20)
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c"[%s] %s\0A\00"
@stdout = global i32 0
@.str.1 = [3 x i8] c"%s\00"
define void @do_log(i8* %0, i32 %1, i8* %2) {
%4 = alloca [1024 x i8]
%5 = alloca [1024 x i8]
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%8 = call i32 @snprintf(i8* %7, i32 1024, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %2, i8* %0)
%9 = call i32 @vsnprintf(i8* %6, i32 1024, i8* %7, i32 %1)
%10 = load i32, i32* @stdout
%11 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %6)
%12 = load i32, i32* @stdout
%13 = call i32 @fflush(i32 %12)
ret void
}