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

/* Variables and functions */
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
struct tm *localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ snprintf(char *, int, char *, long);
int /*<<< orphan*/ strftime(char *, int, char *, struct tm *);
int strlen(char *);
void logTime(FILE *logFile, int *nbWrittenBytesPtr, const int printToStdout) {
  struct timeval tv;
  struct tm *ptm;
  char timeStr[40];
  long milliseconds;
  gettimeofday(&tv, NULL);
  ptm = localtime(&tv.tv_sec);
  strftime(timeStr, sizeof(timeStr), "%Y-%m-%d %H:%M:%S", ptm);
  milliseconds = tv.tv_usec / 1000;
  int timeLength = strlen(timeStr);
  snprintf(timeStr + timeLength, sizeof(timeStr) - timeLength, ".%03ld ",
           milliseconds);
  fwrite(timeStr, sizeof(char), timeLength + 5, logFile);
  *nbWrittenBytesPtr = *nbWrittenBytesPtr + timeLength + 5;
  if (printToStdout == 1) {
    printf("%s", timeStr);
  }
}


x86 assembly (clang, -O0):
<logTime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
lea    -0x20(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1070 <gettimeofday@plt>
lea    -0x20(%rbp),%rdi
add    $0x4,%rdi
call   1030 <localtime@plt>
mov    %rax,-0x28(%rbp)
lea    -0x50(%rbp),%rdi
mov    -0x28(%rbp),%rcx
mov    $0x28,%esi
lea    0xe4b(%rip),%rdx
call   1080 <strftime@plt>
mov    -0x20(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
cltq
mov    %rax,-0x58(%rbp)
lea    -0x50(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x5c(%rbp)
lea    -0x50(%rbp),%rdi
movslq -0x5c(%rbp),%rax
add    %rax,%rdi
movslq -0x5c(%rbp),%rcx
mov    $0x28,%eax
sub    %rcx,%rax
mov    %eax,%esi
mov    -0x58(%rbp),%rcx
lea    0xe17(%rip),%rdx
call   1060 <snprintf@plt>
lea    -0x50(%rbp),%rdi
mov    -0x5c(%rbp),%edx
add    $0x5,%edx
mov    -0x8(%rbp),%rcx
mov    $0x1,%esi
call   1090 <fwrite@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
add    -0x5c(%rbp),%ecx
add    $0x5,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
cmpl   $0x1,-0x14(%rbp)
jne    1244 <logTime+0xd4>
lea    -0x50(%rbp),%rsi
lea    0xddb(%rip),%rdi
call   1050 <printf@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<logTime>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %edx,0x4(%rsp)
mov    %rsi,%r15
mov    %rdi,%r12
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1070 <gettimeofday@plt>
lea    0xc(%rsp),%rdi
call   1030 <localtime@plt>
lea    0xe5b(%rip),%rdx
lea    0x10(%rsp),%r13
mov    $0x28,%ebp
mov    %r13,%rdi
mov    $0x28,%esi
mov    %rax,%rcx
call   1080 <strftime@plt>
movslq 0x8(%rsp),%rax
imul   $0x10624dd3,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x26,%rax
add    %ecx,%eax
movslq %eax,%rbx
mov    %r13,%rdi
call   1040 <strlen@plt>
movslq %eax,%r14
lea    (%rsp,%r14,1),%rdi
add    $0x10,%rdi
sub    %r14d,%ebp
lea    0xe1a(%rip),%rdx
mov    %ebp,%esi
mov    %rbx,%rcx
call   1060 <snprintf@plt>
add    $0x5,%r14d
mov    %r13,%rdi
mov    $0x1,%esi
mov    %r14d,%edx
mov    %r12,%rcx
call   1090 <fwrite@plt>
add    %r14d,(%r15)
cmpl   $0x1,0x4(%rsp)
jne    1234 <logTime+0xc4>
lea    0xdf0(%rip),%rdi
lea    0x10(%rsp),%rsi
call   1050 <printf@plt>
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
%struct.tm = type { i32 }
@.str = [18 x i8] c"%Y-%m-%d %H:%M:%S\00"
@.str.1 = [8 x i8] c".%03ld \00"
@.str.2 = [3 x i8] c"%s\00"
define void @logTime(i32* %0, i32* %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca %struct.timeval
%8 = alloca %struct.tm*
%9 = alloca [40 x i8]
%10 = alloca i64
%11 = alloca i32
store i32* %0, i32** %4
store i32* %1, i32** %5
store i32 %2, i32* %6
%12 = call i32 @gettimeofday(%struct.timeval* %7, i32* null)
%13 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 1
%14 = call %struct.tm* @localtime(i32* %13)
store %struct.tm* %14, %struct.tm** %8
%15 = getelementptr inbounds [40 x i8], [40 x i8]* %9, i64 0, i64 0
%16 = load %struct.tm*, %struct.tm** %8
%17 = call i32 @strftime(i8* %15, i32 40, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), %struct.tm* %16)
%18 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 0
%19 = load i32, i32* %18
%20 = sdiv i32 %19, 1000
%21 = sext i32 %20 to i64
store i64 %21, i64* %10
%22 = getelementptr inbounds [40 x i8], [40 x i8]* %9, i64 0, i64 0
%23 = call i32 @strlen(i8* %22)
store i32 %23, i32* %11
%24 = getelementptr inbounds [40 x i8], [40 x i8]* %9, i64 0, i64 0
%25 = load i32, i32* %11
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %24, i64 %26
%28 = load i32, i32* %11
%29 = sext i32 %28 to i64
%30 = sub i64 40, %29
%31 = trunc i64 %30 to i32
%32 = load i64, i64* %10
%33 = call i32 @snprintf(i8* %27, i32 %31, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i64 %32)
%34 = getelementptr inbounds [40 x i8], [40 x i8]* %9, i64 0, i64 0
%35 = load i32, i32* %11
%36 = add nsw i32 %35, 5
%37 = load i32*, i32** %4
%38 = call i32 @fwrite(i8* %34, i32 1, i32 %36, i32* %37)
%39 = load i32*, i32** %5
%40 = load i32, i32* %39
%41 = load i32, i32* %11
%42 = add nsw i32 %40, %41
%43 = add nsw i32 %42, 5
%44 = load i32*, i32** %5
store i32 %43, i32* %44
%45 = load i32, i32* %6
%46 = icmp eq i32 %45, 1
br i1 %46, label %47, label %50
47: ; preds = %3
%48 = getelementptr inbounds [40 x i8], [40 x i8]* %9, i64 0, i64 0
%49 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %48)
br label %50
50: ; preds = %47, %3
ret void
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
%struct.tm = type { i32 }
@.str = [18 x i8] c"%Y-%m-%d %H:%M:%S\00"
@.str.1 = [8 x i8] c".%03ld \00"
@.str.2 = [3 x i8] c"%s\00"
define void @logTime(i32* nocapture %0, i32* nocapture %1, i32 %2) {
%4 = alloca %struct.timeval
%5 = alloca [40 x i8]
%6 = bitcast %struct.timeval* %4 to i8*
%7 = getelementptr inbounds [40 x i8], [40 x i8]* %5, i64 0, i64 0
%8 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 1
%10 = call %struct.tm* @localtime(i32* %9)
%11 = call i32 @strftime(i8* %7, i32 40, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), %struct.tm* %10)
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 0
%13 = load i32, i32* %12
%14 = sdiv i32 %13, 1000
%15 = sext i32 %14 to i64
%16 = call i32 @strlen(i8* %7)
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [40 x i8], [40 x i8]* %5, i64 0, i64 %17
%19 = sub i32 40, %16
%20 = call i32 @snprintf(i8* %18, i32 %19, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i64 %15)
%21 = add i32 %16, 5
%22 = call i32 @fwrite(i8* %7, i32 1, i32 %21, i32* %0)
%23 = load i32, i32* %1
%24 = add i32 %21, %23
store i32 %24, i32* %1
%25 = icmp eq i32 %2, 1
br i1 %25, label %26, label %28
26: ; preds = %3
%27 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %7)
br label %28
28: ; preds = %26, %3
ret void
}