#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*/ time_t;
struct tm {
  int dummy;
};
struct timeval {
  scalar_t__ tv_usec;
  int /*<<< orphan*/ tv_sec;
};
typedef int /*<<< orphan*/ str;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *, unsigned long,
                           int, char const *);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ localtime_r(int /*<<< orphan*/ *, struct tm *);
int /*<<< orphan*/ *stderr;
int /*<<< orphan*/ strftime(char *, int, char *, struct tm *);
void eblob_log_raw_formatted(void *priv, int level, const char *msg) {
  char str[64];
  struct tm tm;
  struct timeval tv;
  FILE *stream = priv;
  if (!stream)
    stream = stderr;
  gettimeofday(&tv, NULL);
  localtime_r((time_t *)&tv.tv_sec, &tm);
  strftime(str, sizeof(str), "%F %R:%S", &tm);
  fprintf(stream, "%s.%06lu %1x: %s", str, (unsigned long)tv.tv_usec, level,
          msg);
  fflush(stream);
}


x86 assembly (clang, -O0):
<eblob_log_raw_formatted>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x80(%rbp)
cmpq   $0x0,-0x80(%rbp)
jne    1187 <eblob_log_raw_formatted+0x37>
mov    0x2e60(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x80(%rbp)
lea    -0x78(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
lea    -0x78(%rbp),%rdi
add    $0x8,%rdi
lea    -0x68(%rbp),%rsi
call   1030 <localtime_r@plt>
lea    -0x60(%rbp),%rdi
mov    $0x40,%esi
lea    0xe4b(%rip),%rdx
lea    -0x68(%rbp),%rcx
call   1070 <strftime@plt>
mov    -0x80(%rbp),%rdi
lea    -0x60(%rbp),%rdx
mov    -0x78(%rbp),%rcx
mov    -0xc(%rbp),%r8d
mov    -0x18(%rbp),%r9
lea    0xe30(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x80(%rbp),%rdi
call   1060 <fflush@plt>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<eblob_log_raw_formatted>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x60,%rsp
mov    %rdx,%r14
mov    %esi,%r15d
mov    %rdi,%rbx
test   %rdi,%rdi
jne    1174 <eblob_log_raw_formatted+0x24>
mov    0x2e6f(%rip),%rax
mov    (%rax),%rbx
lea    0x10(%rsp),%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
lea    0x18(%rsp),%rdi
lea    0x8(%rsp),%rbp
mov    %rbp,%rsi
call   1030 <localtime_r@plt>
lea    0xe67(%rip),%rdx
lea    0x20(%rsp),%r12
mov    %r12,%rdi
mov    $0x40,%esi
mov    %rbp,%rcx
call   1070 <strftime@plt>
mov    0x10(%rsp),%rcx
lea    0xe4f(%rip),%rsi
mov    %rbx,%rdi
mov    %r12,%rdx
mov    %r15d,%r8d
mov    %r14,%r9
call   1050 <fprintf@plt>
mov    %rbx,%rdi
call   1060 <fflush@plt>
add    $0x60,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
%struct.timeval = type { i64, i32 }
@stderr = global i32* null
@.str = [9 x i8] c"%F %R:%S\00"
@.str.1 = [17 x i8] c"%s.%06lu %1x: %s\00"
define void @eblob_log_raw_formatted(i8* %0, i32 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca [64 x i8]
%8 = alloca %struct.tm
%9 = alloca %struct.timeval
%10 = alloca i32*
store i8* %0, i8** %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%11 = load i8*, i8** %4
%12 = bitcast i8* %11 to i32*
store i32* %12, i32** %10
%13 = load i32*, i32** %10
%14 = icmp ne i32* %13, null
br i1 %14, label %17, label %15
15: ; preds = %3
%16 = load i32*, i32** @stderr
store i32* %16, i32** %10
br label %17
17: ; preds = %15, %3
%18 = call i32 @gettimeofday(%struct.timeval* %9, i32* null)
%19 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 1
%20 = call i32 @localtime_r(i32* %19, %struct.tm* %8)
%21 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%22 = call i32 @strftime(i8* %21, i32 64, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), %struct.tm* %8)
%23 = load i32*, i32** %10
%24 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%25 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 0
%26 = load i64, i64* %25
%27 = load i32, i32* %5
%28 = load i8*, i8** %6
%29 = call i32 @fprintf(i32* %23, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %24, i64 %26, i32 %27, i8* %28)
%30 = load i32*, i32** %10
%31 = call i32 @fflush(i32* %30)
ret void
}

LLVM IR (-O2):
%struct.tm = type { i32 }
%struct.timeval = type { i64, i32 }
@stderr = global i32* null
@.str = [9 x i8] c"%F %R:%S\00"
@.str.1 = [17 x i8] c"%s.%06lu %1x: %s\00"
define void @eblob_log_raw_formatted(i8* %0, i32 %1, i8* %2) {
%4 = alloca [64 x i8]
%5 = alloca %struct.tm
%6 = alloca %struct.timeval
%7 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%8 = bitcast %struct.tm* %5 to i8*
%9 = bitcast %struct.timeval* %6 to i8*
%10 = bitcast i8* %0 to i32*
%11 = icmp eq i8* %0, null
%12 = load i32*, i32** @stderr
%13 = select i1 %11, i32* %12, i32* %10
%14 = call i32 @gettimeofday(%struct.timeval* %6, i32* null)
%15 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i64 0, i32 1
%16 = call i32 @localtime_r(i32* %15, %struct.tm* %5)
%17 = call i32 @strftime(i8* %7, i32 64, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), %struct.tm* %5)
%18 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i64 0, i32 0
%19 = load i64, i64* %18
%20 = call i32 @fprintf(i32* %13, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %7, i64 %19, i32 %1, i8* %2)
%21 = call i32 @fflush(i32* %13)
ret void
}