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

/* Variables and functions */
int /*<<< orphan*/ snprintf(char *, int, char *, char const *, int,
                            char const *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ vfprintf(int /*<<< orphan*/, char *, int /*<<< orphan*/);
void log(const char *func, int line_num, const char *templ, va_list va) {
  char output[2048];
  snprintf(output, sizeof(output), "%s:%d %s\n", func, line_num, templ);
  output[sizeof(output) - 1] = 0;
  vfprintf(stderr, output, va);
}


x86 assembly (clang, -O0):
<log>:
push   %rbp
mov    %rsp,%rbp
sub    $0x820,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
lea    -0x820(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    -0xc(%rbp),%r8d
mov    -0x18(%rbp),%r9
mov    $0x800,%esi
lea    0xea8(%rip),%rdx
call   1030 <snprintf@plt>
movb   $0x0,-0x21(%rbp)
mov    0x2e78(%rip),%rax
mov    (%rax),%edi
lea    -0x820(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1040 <vfprintf@plt>
add    $0x820,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<log>:
push   %r14
push   %rbx
sub    $0x808,%rsp
mov    %ecx,%ebx
mov    %rdx,%r9
mov    %esi,%r8d
mov    %rdi,%rcx
lea    0xec4(%rip),%rdx
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x800,%esi
call   1030 <snprintf@plt>
movb   $0x0,0x7ff(%rsp)
mov    0x2e85(%rip),%rax
mov    (%rax),%edi
mov    %r14,%rsi
mov    %ebx,%edx
call   1040 <vfprintf@plt>
add    $0x808,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [10 x i8] c"%s:%d %s\0A\00"
@stderr = global i32 0
define void @log(i8* %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca [2048 x i8]
store i8* %0, i8** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%10 = getelementptr inbounds [2048 x i8], [2048 x i8]* %9, i64 0, i64 0
%11 = load i8*, i8** %5
%12 = load i32, i32* %6
%13 = load i8*, i8** %7
%14 = call i32 @snprintf(i8* %10, i32 2048, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %11, i32 %12, i8* %13)
%15 = getelementptr inbounds [2048 x i8], [2048 x i8]* %9, i64 0, i64 2047
store i8 0, i8* %15
%16 = load i32, i32* @stderr
%17 = getelementptr inbounds [2048 x i8], [2048 x i8]* %9, i64 0, i64 0
%18 = load i32, i32* %8
%19 = call i32 @vfprintf(i32 %16, i8* %17, i32 %18)
ret void
}

LLVM IR (-O2):
@.str = [10 x i8] c"%s:%d %s\0A\00"
@stderr = global i32 0
define void @log(i8* %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca [2048 x i8]
%6 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 0
%7 = call i32 @snprintf(i8* %6, i32 2048, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %1, i8* %2)
%8 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 2047
store i8 0, i8* %8
%9 = load i32, i32* @stderr
%10 = call i32 @vfprintf(i32 %9, i8* %6, i32 %3)
ret void
}