#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 */
char *get_formatted_date();
int /*<<< orphan*/ print_raw_line(int /*<<< orphan*/ *, char *,
                                  int /*<<< orphan*/);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, char const *,
                            char const *, ...);
int strlen(char *);
void print_detail_line(FILE *log_file, const char *log_level,
                       const char *func_name, const char *log_format,
                       va_list argptr) {
  char format_buffer[1024];
  int _strlen;
  if (func_name != NULL && func_name[0] != 0) {
    snprintf(format_buffer, 1024, "[%s][%s](%s) %s", get_formatted_date(),
             log_level, func_name, log_format);
  } else {
    snprintf(format_buffer, 1024, "[%s][%s] %s", get_formatted_date(),
             log_level, log_format);
  }
  _strlen = strlen(format_buffer);
  if (format_buffer[_strlen - 1] != '\n') {
    format_buffer[_strlen] = '\n';
    format_buffer[_strlen + 1] = 0;
  }
  print_raw_line(log_file, format_buffer, argptr);
}


x86 assembly (clang, -O0):
<print_detail_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x450,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11c1 <print_detail_line+0x81>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11c1 <print_detail_line+0x81>
lea    -0x430(%rbp),%rax
mov    %rax,-0x440(%rbp)
mov    $0x0,%al
call   1050 <get_formatted_date@plt>
mov    -0x440(%rbp),%rdi
mov    %rax,%rcx
mov    -0x10(%rbp),%r8
mov    -0x18(%rbp),%r9
mov    -0x20(%rbp),%rax
mov    $0x400,%esi
lea    0xe4f(%rip),%rdx
mov    %rax,(%rsp)
mov    $0x0,%al
call   1040 <snprintf@plt>
jmp    11fb <print_detail_line+0xbb>
lea    -0x430(%rbp),%rax
mov    %rax,-0x448(%rbp)
mov    $0x0,%al
call   1050 <get_formatted_date@plt>
mov    -0x448(%rbp),%rdi
mov    %rax,%rcx
mov    -0x10(%rbp),%r8
mov    -0x20(%rbp),%r9
mov    $0x400,%esi
lea    0xe1c(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
lea    -0x430(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x434(%rbp)
mov    -0x434(%rbp),%eax
sub    $0x1,%eax
cltq
movsbl -0x430(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
je     124b <print_detail_line+0x10b>
movslq -0x434(%rbp),%rax
movb   $0xa,-0x430(%rbp,%rax,1)
0a
mov    -0x434(%rbp),%eax
add    $0x1,%eax
cltq
movb   $0x0,-0x430(%rbp,%rax,1)
mov    -0x8(%rbp),%rdi
lea    -0x430(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1060 <print_raw_line@plt>
add    $0x450,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_detail_line>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x410,%rsp
mov    %r8d,%r14d
mov    %rcx,%rbx
mov    %rsi,%r12
mov    %rdi,%r15
test   %rdx,%rdx
je     118f <print_detail_line+0x4f>
mov    %rdx,%rbp
cmpb   $0x0,(%rdx)
je     118f <print_detail_line+0x4f>
xor    %eax,%eax
call   1050 <get_formatted_date@plt>
mov    %rbx,(%rsp)
lea    0xe86(%rip),%rdx
lea    0x10(%rsp),%rdi
mov    $0x400,%esi
mov    %rax,%rcx
mov    %r12,%r8
mov    %rbp,%r9
jmp    11b0 <print_detail_line+0x70>
xor    %eax,%eax
call   1050 <get_formatted_date@plt>
lea    0xe73(%rip),%rdx
lea    0x10(%rsp),%rdi
mov    $0x400,%esi
mov    %rax,%rcx
mov    %r12,%r8
mov    %rbx,%r9
xor    %eax,%eax
call   1040 <snprintf@plt>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
cmpb   $0xa,-0x1(%rax,%rbx,1)
je     11d4 <print_detail_line+0x94>
movw   $0xa,0x10(%rsp,%rax,1)
lea    0x10(%rsp),%rsi
mov    %r15,%rdi
mov    %r14d,%edx
call   1060 <print_raw_line@plt>
add    $0x410,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [16 x i8] c"[%s][%s](%s) %s\00"
@.str.1 = [12 x i8] c"[%s][%s] %s\00"
define void @print_detail_line(i32* %0, i8* %1, i8* %2, i8* %3, i32 %4) {
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca [1024 x i8]
%12 = alloca i32
store i32* %0, i32** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i8* %3, i8** %9
store i32 %4, i32* %10
%13 = load i8*, i8** %8
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %28
15: ; preds = %5
%16 = load i8*, i8** %8
%17 = getelementptr inbounds i8, i8* %16, i64 0
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %28
21: ; preds = %15
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%23 = call i8* (...) @get_formatted_date()
%24 = load i8*, i8** %7
%25 = load i8*, i8** %8
%26 = load i8*, i8** %9
%27 = call i32 (i8*, i32, i8*, i8*, i8*, i8*, ...) @snprintf(i8* %22, i32 1024, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %23, i8* %24, i8* %25, i8* %26)
br label %34
28: ; preds = %15, %5
%29 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%30 = call i8* (...) @get_formatted_date()
%31 = load i8*, i8** %7
%32 = load i8*, i8** %9
%33 = call i32 (i8*, i32, i8*, i8*, i8*, i8*, ...) @snprintf(i8* %29, i32 1024, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %30, i8* %31, i8* %32)
br label %34
34: ; preds = %28, %21
%35 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%36 = call i32 @strlen(i8* %35)
store i32 %36, i32* %12
%37 = load i32, i32* %12
%38 = sub nsw i32 %37, 1
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 %39
%41 = load i8, i8* %40
%42 = sext i8 %41 to i32
%43 = icmp ne i32 %42, 10
br i1 %43, label %44, label %52
44: ; preds = %34
%45 = load i32, i32* %12
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 %46
store i8 10, i8* %47
%48 = load i32, i32* %12
%49 = add nsw i32 %48, 1
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 %50
store i8 0, i8* %51
br label %52
52: ; preds = %44, %34
%53 = load i32*, i32** %6
%54 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%55 = load i32, i32* %10
%56 = call i32 @print_raw_line(i32* %53, i8* %54, i32 %55)
ret void
}

LLVM IR (-O2):
@.str = [16 x i8] c"[%s][%s](%s) %s\00"
@.str.1 = [12 x i8] c"[%s][%s] %s\00"
define void @print_detail_line(i32* %0, i8* %1, i8* %2, i8* %3, i32 %4) {
%6 = alloca [1024 x i8]
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%8 = icmp eq i8* %2, null
br i1 %8, label %15, label %9
9: ; preds = %5
%10 = load i8, i8* %2
%11 = icmp eq i8 %10, 0
br i1 %11, label %15, label %12
12: ; preds = %9
%13 = tail call i8* (...) @get_formatted_date()
%14 = call i32 (i8*, i32, i8*, i8*, i8*, i8*, ...) @snprintf(i8* %7, i32 1024, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %13, i8* %1, i8* %2, i8* %3)
br label %18
15: ; preds = %9, %5
%16 = tail call i8* (...) @get_formatted_date()
%17 = call i32 (i8*, i32, i8*, i8*, i8*, i8*, ...) @snprintf(i8* %7, i32 1024, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %16, i8* %1, i8* %3)
br label %18
18: ; preds = %15, %12
%19 = call i32 @strlen(i8* %7)
%20 = add nsw i32 %19, -1
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 %21
%23 = load i8, i8* %22
%24 = icmp eq i8 %23, 10
br i1 %24, label %31, label %25
25: ; preds = %18
%26 = sext i32 %19 to i64
%27 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 %26
store i8 10, i8* %27
%28 = add nsw i32 %19, 1
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 %29
store i8 0, i8* %30
br label %31
31: ; preds = %25, %18
%32 = call i32 @print_raw_line(i32* %0, i8* %7, i32 %4)
ret void
}