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

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
struct tm *localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strftime(char *, int, char *, struct tm *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
void stamptime(void) {
  static long startsecs = 0, startmsecs = 0;
  long secs, msecs;
  struct timeval tv;
  time_t t;
  struct tm *tmp;
  char timec[20];
  gettimeofday(&tv, NULL);
  msecs = tv.tv_usec / 1000;
  secs = tv.tv_sec;
  if (startsecs) {
    secs -= startsecs;
    msecs -= startmsecs;
    if (msecs < 0) {
      secs--;
      msecs += 1000;
    }
    fprintf(stderr, "%04lu.%03lu ", secs, msecs);
  } else {
    startsecs = secs;
    startmsecs = msecs;
    t = time(NULL);
    tmp = localtime(&t);
    strftime(timec, sizeof(timec), "%T", tmp);
    fprintf(stderr, "\n%s ", timec);
  }
}


x86 assembly (clang, -O0):
<stamptime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
lea    -0x20(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
mov    -0x20(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
cltq
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
cmpq   $0x0,0x2eca(%rip)
je     11f9 <stamptime+0xa9>
mov    0x2ebd(%rip),%rcx
mov    -0x8(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    0x2eb3(%rip),%rcx
mov    -0x10(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jge    11d5 <stamptime+0x85>
mov    -0x8(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
add    $0x3e8,%rax
mov    %rax,-0x10(%rbp)
mov    0x2e04(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xe13(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    125c <stamptime+0x10c>
mov    -0x8(%rbp),%rax
mov    %rax,0x2e4c(%rip)
mov    -0x10(%rbp),%rax
mov    %rax,0x2e49(%rip)
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
mov    %eax,-0x24(%rbp)
lea    -0x24(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x30(%rbp)
lea    -0x50(%rbp),%rdi
mov    -0x30(%rbp),%rcx
mov    $0x14,%esi
lea    0xdd1(%rip),%rdx
call   1070 <strftime@plt>
mov    0x2d98(%rip),%rax
mov    (%rax),%edi
lea    -0x50(%rbp),%rdx
lea    0xdbb(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stamptime>:
push   %rbx
sub    $0x40,%rsp
lea    0x10(%rsp),%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
movslq 0x10(%rsp),%rax
imul   $0x10624dd3,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x26,%rax
add    %ecx,%eax
movslq %eax,%rdx
mov    0x18(%rsp),%rax
mov    0x2ec7(%rip),%rcx
test   %rcx,%rcx
je     11c9 <stamptime+0x79>
sub    %rcx,%rax
sub    0x2ec0(%rip),%rdx
lea    0x3e8(%rdx),%rcx
test   %rdx,%rdx
cmovns %rdx,%rcx
sar    $0x3f,%rdx
add    %rax,%rdx
mov    0x2e2c(%rip),%rax
mov    (%rax),%edi
lea    0xe43(%rip),%rsi
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbx
jmp    1050 <fprintf@plt>
mov    %rax,0x2e80(%rip)
mov    %rdx,0x2e81(%rip)
xor    %edi,%edi
call   1060 <time@plt>
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rdi
call   1030 <localtime@plt>
lea    0xe1a(%rip),%rdx
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x14,%esi
mov    %rax,%rcx
call   1070 <strftime@plt>
mov    0x2dd1(%rip),%rax
mov    (%rax),%edi
lea    0xdf8(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
add    $0x40,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i64 }
%struct.tm = type { i32 }
@stamptime.startsecs = internal global i64 0
@stamptime.startmsecs = internal global i64 0
@stderr = global i32 0
@.str = [13 x i8] c"%04lu.%03lu \00"
@.str.1 = [3 x i8] c"%T\00"
@.str.2 = [5 x i8] c"\0A%s \00"
define void @stamptime() {
%1 = alloca i64
%2 = alloca i64
%3 = alloca %struct.timeval
%4 = alloca i32
%5 = alloca %struct.tm*
%6 = alloca [20 x i8]
%7 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
%9 = load i32, i32* %8
%10 = sdiv i32 %9, 1000
%11 = sext i32 %10 to i64
store i64 %11, i64* %2
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 1
%13 = load i64, i64* %12
store i64 %13, i64* %1
%14 = load i64, i64* @stamptime.startsecs
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %35
16: ; preds = %0
%17 = load i64, i64* @stamptime.startsecs
%18 = load i64, i64* %1
%19 = sub nsw i64 %18, %17
store i64 %19, i64* %1
%20 = load i64, i64* @stamptime.startmsecs
%21 = load i64, i64* %2
%22 = sub nsw i64 %21, %20
store i64 %22, i64* %2
%23 = load i64, i64* %2
%24 = icmp slt i64 %23, 0
br i1 %24, label %25, label %30
25: ; preds = %16
%26 = load i64, i64* %1
%27 = add nsw i64 %26, -1
store i64 %27, i64* %1
%28 = load i64, i64* %2
%29 = add nsw i64 %28, 1000
store i64 %29, i64* %2
br label %30
30: ; preds = %25, %16
%31 = load i32, i32* @stderr
%32 = load i64, i64* %1
%33 = load i64, i64* %2
%34 = call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i64 %32, i64 %33)
br label %46
35: ; preds = %0
%36 = load i64, i64* %1
store i64 %36, i64* @stamptime.startsecs
%37 = load i64, i64* %2
store i64 %37, i64* @stamptime.startmsecs
%38 = call i32 @time(i32* null)
store i32 %38, i32* %4
%39 = call %struct.tm* @localtime(i32* %4)
store %struct.tm* %39, %struct.tm** %5
%40 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%41 = load %struct.tm*, %struct.tm** %5
%42 = call i32 @strftime(i8* %40, i32 20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), %struct.tm* %41)
%43 = load i32, i32* @stderr
%44 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%45 = call i32 (i32, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %44)
br label %46
46: ; preds = %35, %30
ret void
}

LLVM IR (-O2):
%struct.timeval = type { i32, i64 }
%struct.tm = type { i32 }
@stamptime.startsecs = internal unnamed_addr global i64 0
@stamptime.startmsecs = internal unnamed_addr global i64 0
@stderr = global i32 0
@.str = [13 x i8] c"%04lu.%03lu \00"
@.str.1 = [3 x i8] c"%T\00"
@.str.2 = [5 x i8] c"\0A%s \00"
define void @stamptime() {
%1 = alloca %struct.timeval
%2 = alloca i32
%3 = alloca [20 x i8]
%4 = bitcast %struct.timeval* %1 to i8*
%5 = bitcast i32* %2 to i8*
%6 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%7 = call i32 @gettimeofday(%struct.timeval* %1, i32* null)
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%9 = load i32, i32* %8
%10 = sdiv i32 %9, 1000
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%13 = load i64, i64* %12
%14 = load i64, i64* @stamptime.startsecs
%15 = icmp eq i64 %14, 0
br i1 %15, label %27, label %16
16: ; preds = %0
%17 = sub i64 %13, %14
%18 = load i64, i64* @stamptime.startmsecs
%19 = sub nsw i64 %11, %18
%20 = icmp slt i64 %19, 0
%21 = add nsw i64 %19, 1000
%22 = select i1 %20, i64 %21, i64 %19
%23 = ashr i64 %19, 63
%24 = add nsw i64 %17, %23
%25 = load i32, i32* @stderr
%26 = tail call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i64 %24, i64 %22)
br label %33
27: ; preds = %0
store i64 %13, i64* @stamptime.startsecs
store i64 %11, i64* @stamptime.startmsecs
%28 = tail call i32 @time(i32* null)
store i32 %28, i32* %2
%29 = call %struct.tm* @localtime(i32* %2)
%30 = call i32 @strftime(i8* %6, i32 20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), %struct.tm* %29)
%31 = load i32, i32* @stderr
%32 = call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %6)
br label %33
33: ; preds = %27, %16
ret void
}