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

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ vfprintf(int /*<<< orphan*/ *, char const *,
                            int /*<<< orphan*/);
void mcx_write_f(FILE *fp, const char *caller, const char *fmt, va_list *args,
                 ...) {
  if (caller)
    fprintf(fp, "[%s] ", caller);
  vfprintf(fp, fmt, *args);
  fprintf(fp, "\n");
  return;
}


x86 assembly (clang, -O0):
<mcx_write_f>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1159 <mcx_write_f+0x39>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xeae(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rax
mov    (%rax),%edx
call   1040 <vfprintf@plt>
mov    -0x8(%rbp),%rdi
lea    0xe8f(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mcx_write_f>:
push   %r15
push   %r14
push   %rbx
mov    %rcx,%r15
mov    %rdx,%r14
mov    %rdi,%rbx
test   %rsi,%rsi
je     1157 <mcx_write_f+0x27>
mov    %rsi,%rdx
lea    0xeb3(%rip),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    (%r15),%edx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <vfprintf@plt>
mov    $0xa,%edi
mov    %rbx,%rsi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <fputc@plt>

LLVM IR (-O0):
@.str = [6 x i8] c"[%s] \00"
@.str.1 = [2 x i8] c"\0A\00"
define void @mcx_write_f(i32* %0, i8* %1, i8* %2, i32* %3, ...) {
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32*
store i32* %0, i32** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i32* %3, i32** %8
%9 = load i8*, i8** %6
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %15
11: ; preds = %4
%12 = load i32*, i32** %5
%13 = load i8*, i8** %6
%14 = call i32 (i32*, i8*, ...) @fprintf(i32* %12, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %13)
br label %15
15: ; preds = %11, %4
%16 = load i32*, i32** %5
%17 = load i8*, i8** %7
%18 = load i32*, i32** %8
%19 = load i32, i32* %18
%20 = call i32 @vfprintf(i32* %16, i8* %17, i32 %19)
%21 = load i32*, i32** %5
%22 = call i32 (i32*, i8*, ...) @fprintf(i32* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"[%s] \00"
define void @mcx_write_f(i32* nocapture %0, i8* %1, i8* nocapture %2, i32* nocapture %3, ...) {
%5 = icmp eq i8* %1, null
br i1 %5, label %8, label %6
6: ; preds = %4
%7 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %1)
br label %8
8: ; preds = %6, %4
%9 = load i32, i32* %3
%10 = tail call i32 @vfprintf(i32* %0, i8* %2, i32 %9)
%11 = tail call i32 @fputc(i32 10, i32* %0)
ret void
}