#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*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ vfprintf(int /*<<< orphan*/ *, char const *,
                            int /*<<< orphan*/);
__attribute__((format(printf, 3, 0))) void
log_once(FILE *where, int level, const char *format, va_list args) {
  switch (level) {
  case 2:
  case 4:
  case 3:
    break;
  default:
    fprintf(where, "error: ");
    break;
  }
  vfprintf(where, format, args);
  fflush(where);
}


x86 assembly (clang, -O0):
<log_once>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0xc(%rbp),%eax
add    $0xfffffffe,%eax
sub    $0x2,%eax
ja     115f <log_once+0x2f>
jmp    115a <log_once+0x2a>
jmp    116f <log_once+0x3f>
mov    -0x8(%rbp),%rdi
lea    0xe96(%rip),%rsi
call   1030 <fprintf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1050 <vfprintf@plt>
mov    -0x8(%rbp),%rdi
call   1040 <fflush@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<log_once>:
push   %rbp
push   %r14
push   %rbx
mov    %ecx,%r14d
mov    %rdx,%rbp
mov    %rdi,%rbx
add    $0xfffffffe,%esi
cmp    $0x3,%esi
jb     115e <log_once+0x2e>
lea    0xeb4(%rip),%rdi
mov    $0x7,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1050 <fwrite@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %r14d,%edx
call   1040 <vfprintf@plt>
mov    %rbx,%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <fflush@plt>

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

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