#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;
struct tm {
  int dummy;
};
struct timespec {
  scalar_t__ tv_nsec;
  int /*<<< orphan*/ tv_sec;
};
typedef int /*<<< orphan*/ buf;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ CLOCK_REALTIME;
int /*<<< orphan*/ clock_gettime(int /*<<< orphan*/, struct timespec *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *, long, char *);
int /*<<< orphan*/ gmtime_r(int /*<<< orphan*/ *, struct tm *);
int /*<<< orphan*/ strftime(char *, int, char *, struct tm *);
int /*<<< orphan*/ vfprintf(int /*<<< orphan*/ *, char *, int /*<<< orphan*/);
void m_flog(FILE *fd, char *module, char *fmt, va_list ap) {
  struct timespec spec;
  struct tm tmn;
  char buf[256];
  if (fd != NULL) {
    clock_gettime(CLOCK_REALTIME, &spec);
    gmtime_r(&spec.tv_sec, &tmn);
    strftime(buf, sizeof(buf), "%b %d %H:%M:%S", &tmn);
    fprintf(fd, "%s.%03ld %s: ", buf, (long)spec.tv_nsec / 1000000, module);
    vfprintf(fd, fmt, ap);
    fflush(fd);
  }
}


x86 assembly (clang, -O0):
<m_flog>:
push   %rbp
mov    %rsp,%rbp
sub    $0x150,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1217 <m_flog+0xb7>
mov    0x2e54(%rip),%rax
mov    (%rax),%edi
lea    -0x30(%rbp),%rsi
call   1030 <clock_gettime@plt>
lea    -0x30(%rbp),%rdi
add    $0x8,%rdi
lea    -0x38(%rbp),%rsi
call   1040 <gmtime_r@plt>
lea    -0x140(%rbp),%rdi
mov    $0x100,%esi
lea    0xe45(%rip),%rdx
lea    -0x38(%rbp),%rcx
call   1070 <strftime@plt>
mov    -0x8(%rbp),%rdi
lea    -0x140(%rbp),%rax
mov    %rax,-0x148(%rbp)
mov    -0x30(%rbp),%rax
mov    $0xf4240,%ecx
cqto
idiv   %rcx
mov    -0x148(%rbp),%rdx
mov    %rax,%rcx
mov    -0x10(%rbp),%r8
lea    0xe16(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1080 <vfprintf@plt>
mov    -0x8(%rbp),%rdi
call   1060 <fflush@plt>
add    $0x150,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<m_flog>:
test   %rdi,%rdi
je     1220 <m_flog+0xc0>
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x128,%rsp
mov    %ecx,%r14d
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%rbx
mov    0x2e53(%rip),%rax
mov    (%rax),%edi
lea    0x10(%rsp),%rsi
call   1030 <clock_gettime@plt>
lea    0x18(%rsp),%rdi
lea    0x8(%rsp),%rbp
mov    %rbp,%rsi
call   1040 <gmtime_r@plt>
lea    0xe4e(%rip),%rdx
lea    0x20(%rsp),%r13
mov    %r13,%rdi
mov    $0x100,%esi
mov    %rbp,%rcx
call   1070 <strftime@plt>
movabs $0x431bde82d7b634db,%rax
de 1b 43
imulq  0x10(%rsp)
mov    %rdx,%rcx
shr    $0x3f,%rcx
sar    $0x12,%rdx
add    %rdx,%rcx
lea    0xe24(%rip),%rsi
mov    %rbx,%rdi
mov    %r13,%rdx
mov    %r12,%r8
call   1050 <fprintf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14d,%edx
call   1080 <vfprintf@plt>
mov    %rbx,%rdi
call   1060 <fflush@plt>
add    $0x128,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timespec = type { i64, i32 }
%struct.tm = type { i32 }
@CLOCK_REALTIME = global i32 0
@.str = [15 x i8] c"%b %d %H:%M:%S\00"
@.str.1 = [14 x i8] c"%s.%03ld %s: \00"
define void @m_flog(i32* %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca %struct.timespec
%10 = alloca %struct.tm
%11 = alloca [256 x i8]
store i32* %0, i32** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%12 = load i32*, i32** %5
%13 = icmp ne i32* %12, null
br i1 %13, label %14, label %34
14: ; preds = %4
%15 = load i32, i32* @CLOCK_REALTIME
%16 = call i32 @clock_gettime(i32 %15, %struct.timespec* %9)
%17 = getelementptr inbounds %struct.timespec, %struct.timespec* %9, i32 0, i32 1
%18 = call i32 @gmtime_r(i32* %17, %struct.tm* %10)
%19 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%20 = call i32 @strftime(i8* %19, i32 256, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), %struct.tm* %10)
%21 = load i32*, i32** %5
%22 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%23 = getelementptr inbounds %struct.timespec, %struct.timespec* %9, i32 0, i32 0
%24 = load i64, i64* %23
%25 = sdiv i64 %24, 1000000
%26 = load i8*, i8** %6
%27 = call i32 @fprintf(i32* %21, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %22, i64 %25, i8* %26)
%28 = load i32*, i32** %5
%29 = load i8*, i8** %7
%30 = load i32, i32* %8
%31 = call i32 @vfprintf(i32* %28, i8* %29, i32 %30)
%32 = load i32*, i32** %5
%33 = call i32 @fflush(i32* %32)
br label %34
34: ; preds = %14, %4
ret void
}

LLVM IR (-O2):
%struct.timespec = type { i64, i32 }
%struct.tm = type { i32 }
@CLOCK_REALTIME = global i32 0
@.str = [15 x i8] c"%b %d %H:%M:%S\00"
@.str.1 = [14 x i8] c"%s.%03ld %s: \00"
define void @m_flog(i32* %0, i8* %1, i8* nocapture %2, i32 %3) {
%5 = alloca %struct.timespec
%6 = alloca %struct.tm
%7 = alloca [256 x i8]
%8 = bitcast %struct.timespec* %5 to i8*
%9 = bitcast %struct.tm* %6 to i8*
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%11 = icmp eq i32* %0, null
br i1 %11, label %24, label %12
12: ; preds = %4
%13 = load i32, i32* @CLOCK_REALTIME
%14 = call i32 @clock_gettime(i32 %13, %struct.timespec* %5)
%15 = getelementptr inbounds %struct.timespec, %struct.timespec* %5, i64 0, i32 1
%16 = call i32 @gmtime_r(i32* %15, %struct.tm* %6)
%17 = call i32 @strftime(i8* %10, i32 256, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), %struct.tm* %6)
%18 = getelementptr inbounds %struct.timespec, %struct.timespec* %5, i64 0, i32 0
%19 = load i64, i64* %18
%20 = sdiv i64 %19, 1000000
%21 = call i32 @fprintf(i32* %0, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %10, i64 %20, i8* %1)
%22 = call i32 @vfprintf(i32* %0, i8* %2, i32 %3)
%23 = call i32 @fflush(i32* %0)
br label %24
24: ; preds = %12, %4
ret void
}