#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 */
scalar_t__ fprintf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ *get_log_file();
char *log_to_char(int);
scalar_t__ vfprintf(int /*<<< orphan*/ *, char const *, int /*<<< orphan*/);
int debug_vfprintf(FILE *stream, int log_level, const char *format,
                   va_list arg) {
  int wrote = 0;
  if (stream == NULL) {
    stream = get_log_file();
  }
  if (2 >= log_level) {
    wrote += fprintf(stream, "%s", log_to_char(log_level));
    wrote += vfprintf(stream, format, arg);
  }
  return wrote;
}


x86 assembly (clang, -O0):
<debug_vfprintf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1173 <debug_vfprintf+0x33>
mov    $0x0,%al
call   1050 <get_log_file@plt>
mov    %rax,-0x8(%rbp)
mov    $0x2,%eax
cmp    -0xc(%rbp),%eax
jl     11ce <debug_vfprintf+0x8e>
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0xc(%rbp),%edi
call   1030 <log_to_char@plt>
mov    -0x28(%rbp),%rdi
mov    %rax,%rdx
lea    0xe61(%rip),%rsi
call   1040 <fprintf@plt>
mov    %rax,%rcx
movslq -0x20(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1060 <vfprintf@plt>
mov    %rax,%rcx
movslq -0x20(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<debug_vfprintf>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %ecx,%r14d
mov    %rdx,%r15
mov    %esi,%ebx
mov    %rdi,%rbp
test   %rdi,%rdi
jne    1161 <debug_vfprintf+0x21>
xor    %eax,%eax
call   1050 <get_log_file@plt>
mov    %rax,%rbp
xor    %eax,%eax
cmp    $0x2,%ebx
jg     1194 <debug_vfprintf+0x54>
mov    %ebx,%edi
call   1030 <log_to_char@plt>
lea    0xe8a(%rip),%rsi
mov    %rbp,%rdi
mov    %rax,%rdx
call   1040 <fprintf@plt>
mov    %rax,%rbx
mov    %rbp,%rdi
mov    %r15,%rsi
mov    %r14d,%edx
call   1060 <vfprintf@plt>
add    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
define i32 @debug_vfprintf(i32* %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
store i32* %0, i32** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i32 %3, i32* %8
store i32 0, i32* %9
%10 = load i32*, i32** %5
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %14
12: ; preds = %4
%13 = call i32* (...) @get_log_file()
store i32* %13, i32** %5
br label %14
14: ; preds = %12, %4
%15 = load i32, i32* %6
%16 = icmp sge i32 2, %15
br i1 %16, label %17, label %34
17: ; preds = %14
%18 = load i32*, i32** %5
%19 = load i32, i32* %6
%20 = call i8* @log_to_char(i32 %19)
%21 = call i64 @fprintf(i32* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %20)
%22 = load i32, i32* %9
%23 = sext i32 %22 to i64
%24 = add nsw i64 %23, %21
%25 = trunc i64 %24 to i32
store i32 %25, i32* %9
%26 = load i32*, i32** %5
%27 = load i8*, i8** %7
%28 = load i32, i32* %8
%29 = call i64 @vfprintf(i32* %26, i8* %27, i32 %28)
%30 = load i32, i32* %9
%31 = sext i32 %30 to i64
%32 = add nsw i64 %31, %29
%33 = trunc i64 %32 to i32
store i32 %33, i32* %9
br label %34
34: ; preds = %17, %14
%35 = load i32, i32* %9
ret i32 %35
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
define i32 @debug_vfprintf(i32* %0, i32 %1, i8* nocapture %2, i32 %3) {
%5 = icmp eq i32* %0, null
br i1 %5, label %6, label %8
6: ; preds = %4
%7 = tail call i32* (...) @get_log_file()
br label %8
8: ; preds = %6, %4
%9 = phi i32* [ %7, %6 ], [ %0, %4 ]
%10 = icmp slt i32 %1, 3
br i1 %10, label %11, label %17
11: ; preds = %8
%12 = tail call i8* @log_to_char(i32 %1)
%13 = tail call i64 @fprintf(i32* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %12)
%14 = tail call i64 @vfprintf(i32* %9, i8* %2, i32 %3)
%15 = add i64 %14, %13
%16 = trunc i64 %15 to i32
br label %17
17: ; preds = %11, %8
%18 = phi i32 [ %16, %11 ], [ 0, %8 ]
ret i32 %18
}