#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 {
  int tv_usec;
  int /*<<< orphan*/ tv_sec;
};
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
struct tm *localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char *, unsigned int);
int /*<<< orphan*/ strftime(char *, int, char *, struct tm *);
void bb_print_timestamp(void) {
  struct timeval tv;
  gettimeofday(&tv, NULL);
  time_t timer = (time_t)tv.tv_sec;
  struct tm *tm_info = localtime(&timer);
  char buf[64];
  strftime(buf, sizeof(buf), "%T", tm_info);
  printf("%s.%03u", buf, (unsigned)(tv.tv_usec / 1000));
}


x86 assembly (clang, -O0):
<bb_print_timestamp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
lea    -0x8(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0xc(%rbp)
lea    -0xc(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x18(%rbp)
lea    -0x60(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x40,%esi
lea    0xe84(%rip),%rdx
call   1060 <strftime@plt>
lea    -0x60(%rbp),%rsi
mov    -0x8(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,%edx
lea    0xe6a(%rip),%rdi
call   1040 <printf@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bb_print_timestamp>:
push   %rbx
sub    $0x50,%rsp
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
mov    0xc(%rsp),%eax
mov    %eax,0x4(%rsp)
lea    0x4(%rsp),%rdi
call   1030 <localtime@plt>
lea    0xe96(%rip),%rdx
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x40,%esi
mov    %rax,%rcx
call   1060 <strftime@plt>
movslq 0x8(%rsp),%rax
imul   $0x10624dd3,%rax,%rdx
mov    %rdx,%rax
shr    $0x3f,%rax
sar    $0x26,%rdx
add    %eax,%edx
lea    0xe64(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
add    $0x50,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
%struct.tm = type { i32 }
@.str = [3 x i8] c"%T\00"
@.str.1 = [8 x i8] c"%s.%03u\00"
define void @bb_print_timestamp() {
%1 = alloca %struct.timeval
%2 = alloca i32
%3 = alloca %struct.tm*
%4 = alloca [64 x i8]
%5 = call i32 @gettimeofday(%struct.timeval* %1, i32* null)
%6 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i32 0, i32 1
%7 = load i32, i32* %6
store i32 %7, i32* %2
%8 = call %struct.tm* @localtime(i32* %2)
store %struct.tm* %8, %struct.tm** %3
%9 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%10 = load %struct.tm*, %struct.tm** %3
%11 = call i32 @strftime(i8* %9, i32 64, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), %struct.tm* %10)
%12 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%13 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i32 0, i32 0
%14 = load i32, i32* %13
%15 = sdiv i32 %14, 1000
%16 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %12, i32 %15)
ret void
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
%struct.tm = type { i32 }
@.str = [3 x i8] c"%T\00"
@.str.1 = [8 x i8] c"%s.%03u\00"
define void @bb_print_timestamp() {
%1 = alloca %struct.timeval
%2 = alloca i32
%3 = alloca [64 x i8]
%4 = bitcast %struct.timeval* %1 to i8*
%5 = call i32 @gettimeofday(%struct.timeval* %1, i32* null)
%6 = bitcast i32* %2 to i8*
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%8 = load i32, i32* %7
store i32 %8, i32* %2
%9 = call %struct.tm* @localtime(i32* %2)
%10 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%11 = call i32 @strftime(i8* %10, i32 64, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), %struct.tm* %9)
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%13 = load i32, i32* %12
%14 = sdiv i32 %13, 1000
%15 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %10, i32 %14)
ret void
}