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

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ gmtime_r(int /*<<< orphan*/ *, struct tm *);
int snprintf(char *, size_t, char *, int, int, int, int, int, double);
int ms_speech_get_timestamp(char *buffer, size_t len) {
  struct timeval tv;
  struct tm info;
  gettimeofday(&tv, NULL);
  gmtime_r(&tv.tv_sec, &info);
  double seconds = (double)info.tm_sec + tv.tv_usec / 1000000.0;
  return snprintf(buffer, len, "%04d-%02d-%02dT%02d:%02d:%0.7f",
                  info.tm_year + 1900, info.tm_mon + 1, info.tm_mday,
                  info.tm_hour, info.tm_min, seconds);
}


x86 assembly (clang, -O0):
<ms_speech_get_timestamp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x20(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
lea    -0x20(%rbp),%rdi
add    $0x8,%rdi
lea    -0x40(%rbp),%rsi
call   1040 <gmtime_r@plt>
cvtsi2sdq -0x28(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
movsd  0xe8f(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x40(%rbp),%ecx
add    $0x76c,%ecx
mov    -0x3c(%rbp),%r8d
add    $0x1,%r8d
mov    -0x38(%rbp),%r9d
mov    -0x34(%rbp),%r10d
mov    -0x30(%rbp),%eax
movsd  -0x48(%rbp),%xmm0
lea    0xe5a(%rip),%rdx
mov    %r10d,(%rsp)
mov    %eax,0x8(%rsp)
call   1030 <snprintf@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ms_speech_get_timestamp>:
push   %r15
push   %r14
push   %rbx
sub    $0x30,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
lea    0x20(%rsp),%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
lea    0x28(%rsp),%rdi
mov    %rsp,%rsi
call   1040 <gmtime_r@plt>
cvtsi2sdq 0x18(%rsp),%xmm1
movsd  0x20(%rsp),%xmm0
divsd  0xe93(%rip),%xmm0
addsd  %xmm1,%xmm0
mov    $0x76c,%ecx
add    (%rsp),%ecx
mov    0x4(%rsp),%r8d
mov    0x8(%rsp),%r9d
add    $0x1,%r8d
mov    0xc(%rsp),%eax
mov    0x10(%rsp),%ebx
lea    0xe72(%rip),%rdx
mov    %r15,%rdi
mov    %r14,%rsi
push   %rbx
push   %rax
call   1030 <snprintf@plt>
add    $0x40,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.timeval = type { double, i32 }
%struct.tm = type { i32, i32, i32, i32, i32, i64 }
@.str = [31 x i8] c"%04d-%02d-%02dT%02d:%02d:%0.7f\00"
define i32 @ms_speech_get_timestamp(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca %struct.timeval
%6 = alloca %struct.tm
%7 = alloca double
store i8* %0, i8** %3
store i64 %1, i64* %4
%8 = call i32 @gettimeofday(%struct.timeval* %5, i32* null)
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 1
%10 = call i32 @gmtime_r(i32* %9, %struct.tm* %6)
%11 = getelementptr inbounds %struct.tm, %struct.tm* %6, i32 0, i32 5
%12 = load i64, i64* %11
%13 = sitofp i64 %12 to double
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 0
%15 = load double, double* %14
%16 = fdiv double %15, 1.000000e+06
%17 = fadd double %13, %16
store double %17, double* %7
%18 = load i8*, i8** %3
%19 = load i64, i64* %4
%20 = getelementptr inbounds %struct.tm, %struct.tm* %6, i32 0, i32 0
%21 = load i32, i32* %20
%22 = add nsw i32 %21, 1900
%23 = getelementptr inbounds %struct.tm, %struct.tm* %6, i32 0, i32 1
%24 = load i32, i32* %23
%25 = add nsw i32 %24, 1
%26 = getelementptr inbounds %struct.tm, %struct.tm* %6, i32 0, i32 2
%27 = load i32, i32* %26
%28 = getelementptr inbounds %struct.tm, %struct.tm* %6, i32 0, i32 3
%29 = load i32, i32* %28
%30 = getelementptr inbounds %struct.tm, %struct.tm* %6, i32 0, i32 4
%31 = load i32, i32* %30
%32 = load double, double* %7
%33 = call i32 @snprintf(i8* %18, i64 %19, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %22, i32 %25, i32 %27, i32 %29, i32 %31, double %32)
ret i32 %33
}

LLVM IR (-O2):
%struct.timeval = type { double, i32 }
%struct.tm = type { i32, i32, i32, i32, i32, i64 }
@.str = [31 x i8] c"%04d-%02d-%02dT%02d:%02d:%0.7f\00"
define i32 @ms_speech_get_timestamp(i8* %0, i64 %1) {
%3 = alloca %struct.timeval
%4 = alloca %struct.tm
%5 = bitcast %struct.timeval* %3 to i8*
%6 = bitcast %struct.tm* %4 to i8*
%7 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
%9 = call i32 @gmtime_r(i32* %8, %struct.tm* %4)
%10 = getelementptr inbounds %struct.tm, %struct.tm* %4, i64 0, i32 5
%11 = load i64, i64* %10
%12 = sitofp i64 %11 to double
%13 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
%14 = load double, double* %13
%15 = fdiv double %14, 1.000000e+06
%16 = fadd double %15, %12
%17 = getelementptr inbounds %struct.tm, %struct.tm* %4, i64 0, i32 0
%18 = load i32, i32* %17
%19 = add nsw i32 %18, 1900
%20 = getelementptr inbounds %struct.tm, %struct.tm* %4, i64 0, i32 1
%21 = load i32, i32* %20
%22 = add nsw i32 %21, 1
%23 = getelementptr inbounds %struct.tm, %struct.tm* %4, i64 0, i32 2
%24 = load i32, i32* %23
%25 = getelementptr inbounds %struct.tm, %struct.tm* %4, i64 0, i32 3
%26 = load i32, i32* %25
%27 = getelementptr inbounds %struct.tm, %struct.tm* %4, i64 0, i32 4
%28 = load i32, i32* %27
%29 = call i32 @snprintf(i8* %0, i64 %1, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %19, i32 %22, i32 %24, i32 %26, i32 %28, double %16)
ret i32 %29
}