#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*/ fflush(int /*<<< orphan*/);
int fwrite(char *, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, char const *, char const *,
                           unsigned int);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strcat(char *, char *);
int strlen(char *);
int /*<<< orphan*/ vsprintf(char *, char const *, int /*<<< orphan*/);
void vdiagnostic(const char *prefix, const char *file, unsigned line,
                 const char *fmt, va_list ap) {
  static char buf[2048];
  int n, na, i = 0;
  sprintf(buf, "%s(%s:%d): ", prefix, file, line);
  vsprintf(buf + strlen(buf), fmt, ap);
  strcat(buf, "\n");
  n = strlen(buf);
  while (n && (na = fwrite(buf + i, 1, n, stdout)))
    n -= na, i += na;
  fflush(stdout);
}


x86 assembly (clang, -O0):
<vdiagnostic>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    -0x14(%rbp),%r8d
lea    0x2ecb(%rip),%rdi
lea    0xe64(%rip),%rsi
call   1070 <sprintf@plt>
lea    0x2eb8(%rip),%rdi
call   1030 <strlen@plt>
cltq
lea    0x2eaa(%rip),%rdi
add    %rax,%rdi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1050 <vsprintf@plt>
lea    0x2e94(%rip),%rdi
lea    0xe39(%rip),%rsi
call   1060 <strcat@plt>
lea    0x2e81(%rip),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x28(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x28(%rbp)
mov    %al,-0x31(%rbp)
je     1226 <vdiagnostic+0xc6>
movslq -0x30(%rbp),%rax
lea    0x2e5f(%rip),%rdi
add    %rax,%rdi
mov    -0x28(%rbp),%edx
mov    0x2dd2(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%esi
call   1080 <fwrite@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0x0,%eax
setne  %al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
test   $0x1,%al
jne    1236 <vdiagnostic+0xd6>
jmp    124f <vdiagnostic+0xef>
mov    -0x2c(%rbp),%ecx
mov    -0x28(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x28(%rbp)
mov    -0x2c(%rbp),%eax
add    -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
jmp    11e7 <vdiagnostic+0x87>
mov    0x2d8a(%rip),%rax
mov    (%rax),%edi
call   1040 <fflush@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vdiagnostic>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %r8d,%r14d
mov    %rcx,%rbp
mov    %edx,%r8d
mov    %rsi,%rcx
mov    %rdi,%rdx
lea    0x2ee3(%rip),%r15
lea    0xe7c(%rip),%rsi
mov    %r15,%rdi
call   1070 <sprintf@plt>
mov    %r15,%rdi
call   1030 <strlen@plt>
movslq %eax,%rdi
add    %r15,%rdi
mov    %rbp,%rsi
mov    %r14d,%edx
call   1050 <vsprintf@plt>
lea    0xe60(%rip),%rsi
mov    %r15,%rdi
call   1060 <strcat@plt>
mov    %r15,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
je     11ef <vdiagnostic+0x8f>
mov    %eax,%ebp
xor    %ebx,%ebx
mov    0x2e15(%rip),%r14
nopl   0x0(%rax,%rax,1)
movslq %ebx,%rdi
add    %r15,%rdi
mov    (%r14),%ecx
mov    $0x1,%esi
mov    %ebp,%edx
call   1080 <fwrite@plt>
test   %eax,%eax
je     11ef <vdiagnostic+0x8f>
add    %eax,%ebx
sub    %eax,%ebp
jne    11d0 <vdiagnostic+0x70>
mov    0x2dea(%rip),%rax
mov    (%rax),%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <fflush@plt>

LLVM IR (-O0):
@vdiagnostic.buf = internal global [2048 x i8] zeroinitializer
@.str = [12 x i8] c"%s(%s:%d): \00"
@.str.1 = [2 x i8] c"\0A\00"
@stdout = global i32 0
define void @vdiagnostic(i8* %0, i8* %1, i32 %2, i8* %3, i32 %4) {
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i8* %0, i8** %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i8* %3, i8** %9
store i32 %4, i32* %10
store i32 0, i32* %13
%14 = load i8*, i8** %6
%15 = load i8*, i8** %7
%16 = load i32, i32* %8
%17 = call i32 @sprintf(i8* getelementptr inbounds ([2048 x i8], [2048 x i8]* @vdiagnostic.buf, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %14, i8* %15, i32 %16)
%18 = call i32 @strlen(i8* getelementptr inbounds ([2048 x i8], [2048 x i8]* @vdiagnostic.buf, i64 0, i64 0))
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* getelementptr inbounds ([2048 x i8], [2048 x i8]* @vdiagnostic.buf, i64 0, i64 0), i64 %19
%21 = load i8*, i8** %9
%22 = load i32, i32* %10
%23 = call i32 @vsprintf(i8* %20, i8* %21, i32 %22)
%24 = call i32 @strcat(i8* getelementptr inbounds ([2048 x i8], [2048 x i8]* @vdiagnostic.buf, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%25 = call i32 @strlen(i8* getelementptr inbounds ([2048 x i8], [2048 x i8]* @vdiagnostic.buf, i64 0, i64 0))
store i32 %25, i32* %11
br label %26
26: ; preds = %39, %5
%27 = load i32, i32* %11
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %37
29: ; preds = %26
%30 = load i32, i32* %13
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* getelementptr inbounds ([2048 x i8], [2048 x i8]* @vdiagnostic.buf, i64 0, i64 0), i64 %31
%33 = load i32, i32* %11
%34 = load i32, i32* @stdout
%35 = call i32 @fwrite(i8* %32, i32 1, i32 %33, i32 %34)
store i32 %35, i32* %12
%36 = icmp ne i32 %35, 0
br label %37
37: ; preds = %29, %26
%38 = phi i1 [ false, %26 ], [ %36, %29 ]
br i1 %38, label %39, label %46
39: ; preds = %37
%40 = load i32, i32* %12
%41 = load i32, i32* %11
%42 = sub nsw i32 %41, %40
store i32 %42, i32* %11
%43 = load i32, i32* %12
%44 = load i32, i32* %13
%45 = add nsw i32 %44, %43
store i32 %45, i32* %13
br label %26
46: ; preds = %37
%47 = load i32, i32* @stdout
%48 = call i32 @fflush(i32 %47)
ret void
}

LLVM IR (-O2):
@vdiagnostic.buf = internal global [2048 x i8] zeroinitializer
@.str = [12 x i8] c"%s(%s:%d): \00"
@.str.1 = [2 x i8] c"\0A\00"
@stdout = global i32 0
define void @vdiagnostic(i8* %0, i8* %1, i32 %2, i8* nocapture %3, i32 %4) {
%6 = tail call i32 @sprintf(i8* dereferenceable(1) getelementptr inbounds ([2048 x i8], [2048 x i8]* @vdiagnostic.buf, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1, i32 %2)
%7 = tail call i32 @strlen(i8* getelementptr inbounds ([2048 x i8], [2048 x i8]* @vdiagnostic.buf, i64 0, i64 0))
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds [2048 x i8], [2048 x i8]* @vdiagnostic.buf, i64 0, i64 %8
%10 = tail call i32 @vsprintf(i8* %9, i8* %3, i32 %4)
%11 = tail call i32 @strcat(i8* getelementptr inbounds ([2048 x i8], [2048 x i8]* @vdiagnostic.buf, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%12 = tail call i32 @strlen(i8* getelementptr inbounds ([2048 x i8], [2048 x i8]* @vdiagnostic.buf, i64 0, i64 0))
%13 = icmp eq i32 %12, 0
br i1 %13, label %26, label %14
14: ; preds = %5, %22
%15 = phi i32 [ %24, %22 ], [ 0, %5 ]
%16 = phi i32 [ %23, %22 ], [ %12, %5 ]
%17 = sext i32 %15 to i64
%18 = getelementptr inbounds [2048 x i8], [2048 x i8]* @vdiagnostic.buf, i64 0, i64 %17
%19 = load i32, i32* @stdout
%20 = tail call i32 @fwrite(i8* %18, i32 1, i32 %16, i32 %19)
%21 = icmp eq i32 %20, 0
br i1 %21, label %26, label %22
22: ; preds = %14
%23 = sub nsw i32 %16, %20
%24 = add nsw i32 %20, %15
%25 = icmp eq i32 %23, 0
br i1 %25, label %26, label %14
26: ; preds = %14, %22, %5
%27 = load i32, i32* @stdout
%28 = tail call i32 @fflush(i32 %27)
ret void
}