#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 tm_hour;
  int tm_min;
  int tm_sec;
};
struct timeval {
  int tv_usec;
  int /*<<< orphan*/ tv_sec;
};

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ localtime_r(int /*<<< orphan*/ *, struct tm *);
int /*<<< orphan*/ printf(char *, int, int, int, int);
void printtimestamp(void) {
  struct tm tm;
  int ms;
  struct timeval tv;
  gettimeofday(&tv, NULL);
  localtime_r((time_t *)&tv.tv_sec, &tm);
  ms = tv.tv_usec / 1000;
  printf("%2d:%02d:%02d.%03d  ", tm.tm_hour, tm.tm_min, tm.tm_sec, ms);
}


x86 assembly (clang, -O0):
<printtimestamp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    -0x20(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
lea    -0x20(%rbp),%rdi
add    $0x4,%rdi
lea    -0x10(%rbp),%rsi
call   1030 <localtime_r@plt>
mov    -0x20(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x8(%rbp),%ecx
mov    -0x14(%rbp),%r8d
lea    0xe88(%rip),%rdi
call   1040 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printtimestamp>:
sub    $0x18,%rsp
mov    %rsp,%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
lea    0x4(%rsp),%rdi
lea    0x8(%rsp),%rsi
call   1030 <localtime_r@plt>
movslq (%rsp),%rax
imul   $0x10624dd3,%rax,%r8
mov    %r8,%rax
shr    $0x3f,%rax
sar    $0x26,%r8
add    %eax,%r8d
mov    0x8(%rsp),%esi
mov    0xc(%rsp),%edx
mov    0x10(%rsp),%ecx
lea    0xe87(%rip),%rdi
call   1040 <printf@plt>
add    $0x18,%rsp
ret

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

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