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

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/);
struct tm *gmtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ snprintf(char *, int, char *, int, int, int, int);
char *timestamp(void) {
  struct timeval tv;
  static char time[50];
  struct tm *tmp;
  gettimeofday(&tv, 0);
  tmp = gmtime(&tv.tv_sec);
  snprintf(time, sizeof(time), "%02d:%02d:%02d.%02d", tmp->tm_hour, tmp->tm_min,
           tmp->tm_sec, (int)tv.tv_usec / 10000);
  return time;
}


x86 assembly (clang, -O0):
<timestamp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    -0x10(%rbp),%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
lea    -0x10(%rbp),%rdi
add    $0x8,%rdi
call   1050 <gmtime@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
mov    -0x18(%rbp),%rax
mov    0x4(%rax),%r8d
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%r9d
mov    -0x10(%rbp),%rax
mov    $0x2710,%esi
cltd
idiv   %esi
lea    0x2ed3(%rip),%rdi
mov    $0x32,%esi
lea    0xe77(%rip),%rdx
mov    %eax,(%rsp)
call   1030 <snprintf@plt>
lea    0x2eb8(%rip),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<timestamp>:
push   %rbx
sub    $0x20,%rsp
lea    0x10(%rsp),%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
lea    0x18(%rsp),%rdi
call   1050 <gmtime@plt>
mov    (%rax),%ecx
mov    0x4(%rax),%r8d
mov    0x8(%rax),%r9d
movslq 0x10(%rsp),%rax
imul   $0x68db8bad,%rax,%rax
mov    %rax,%rdx
shr    $0x3f,%rdx
sar    $0x2c,%rax
add    %edx,%eax
mov    %eax,(%rsp)
lea    0x2ed8(%rip),%rbx
lea    0xe81(%rip),%rdx
mov    %rbx,%rdi
mov    $0x32,%esi
call   1030 <snprintf@plt>
mov    %rbx,%rax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.timeval = type { i64, i32 }
%struct.tm = type { i32, i32, i32 }
@timestamp.time = internal global [50 x i8] zeroinitializer
@.str = [20 x i8] c"%02d:%02d:%02d.%02d\00"
define i8* @timestamp() {
%1 = alloca %struct.timeval
%2 = alloca %struct.tm*
%3 = call i32 @gettimeofday(%struct.timeval* %1, i32 0)
%4 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i32 0, i32 1
%5 = call %struct.tm* @gmtime(i32* %4)
store %struct.tm* %5, %struct.tm** %2
%6 = load %struct.tm*, %struct.tm** %2
%7 = getelementptr inbounds %struct.tm, %struct.tm* %6, i32 0, i32 0
%8 = load i32, i32* %7
%9 = load %struct.tm*, %struct.tm** %2
%10 = getelementptr inbounds %struct.tm, %struct.tm* %9, i32 0, i32 1
%11 = load i32, i32* %10
%12 = load %struct.tm*, %struct.tm** %2
%13 = getelementptr inbounds %struct.tm, %struct.tm* %12, i32 0, i32 2
%14 = load i32, i32* %13
%15 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i32 0, i32 0
%16 = load i64, i64* %15
%17 = trunc i64 %16 to i32
%18 = sdiv i32 %17, 10000
%19 = call i32 @snprintf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @timestamp.time, i64 0, i64 0), i32 50, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %8, i32 %11, i32 %14, i32 %18)
ret i8* getelementptr inbounds ([50 x i8], [50 x i8]* @timestamp.time, i64 0, i64 0)
}

LLVM IR (-O2):
%struct.timeval = type { i64, i32 }
%struct.tm = type { i32, i32, i32 }
@timestamp.time = internal global [50 x i8] zeroinitializer
@.str = [20 x i8] c"%02d:%02d:%02d.%02d\00"
define i8* @timestamp() {
%1 = alloca %struct.timeval
%2 = bitcast %struct.timeval* %1 to i8*
%3 = call i32 @gettimeofday(%struct.timeval* %1, i32 0)
%4 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%5 = call %struct.tm* @gmtime(i32* %4)
%6 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 0, i32 0
%7 = load i32, i32* %6
%8 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 0, i32 1
%9 = load i32, i32* %8
%10 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 0, i32 2
%11 = load i32, i32* %10
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%13 = load i64, i64* %12
%14 = trunc i64 %13 to i32
%15 = sdiv i32 %14, 10000
%16 = call i32 @snprintf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @timestamp.time, i64 0, i64 0), i32 50, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %7, i32 %9, i32 %11, i32 %15)
ret i8* getelementptr inbounds ([50 x i8], [50 x i8]* @timestamp.time, i64 0, i64 0)
}