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

/* Variables and functions */
double fmod(double, int);
int /*<<< orphan*/ localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ sprintf(char *, char *, double);
int /*<<< orphan*/ strftime(char *, int, char *, int /*<<< orphan*/);
int strlen(char *);
char *timetostr(double dt) {
  static char buf[128];
  char *str;
  time_t t = (time_t)dt;
  strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", localtime(&t));
  str = buf + strlen(buf) - 1;
  sprintf(str, "%.6f", fmod(dt, 10));
  return buf;
}


x86 assembly (clang, -O0):
<timetostr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x8(%rbp)
cvttsd2si -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
lea    -0x14(%rbp),%rdi
call   1030 <localtime@plt>
mov    %eax,%ecx
lea    0x2ee9(%rip),%rdi
mov    $0x80,%esi
lea    0xe7d(%rip),%rdx
call   1060 <strftime@plt>
lea    0x2ed1(%rip),%rdi
call   1040 <strlen@plt>
movslq %eax,%rcx
lea    0x2ec2(%rip),%rax
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
movsd  -0x8(%rbp),%xmm0
mov    $0xa,%edi
call   1050 <fmod@plt>
mov    -0x20(%rbp),%rdi
lea    0xe47(%rip),%rsi
call   1070 <sprintf@plt>
lea    0x2e89(%rip),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<timetostr>:
push   %r14
push   %rbx
sub    $0x18,%rsp
movsd  %xmm0,0x10(%rsp)
cvttsd2si %xmm0,%eax
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rdi
call   1030 <localtime@plt>
lea    0x2eea(%rip),%r14
lea    0xe83(%rip),%rdx
mov    %r14,%rdi
mov    $0x80,%esi
mov    %eax,%ecx
call   1060 <strftime@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
cltq
lea    (%rax,%r14,1),%rbx
add    $0xffffffffffffffff,%rbx
movsd  0x10(%rsp),%xmm0
mov    $0xa,%edi
call   1050 <fmod@plt>
lea    0xe5d(%rip),%rsi
mov    %rbx,%rdi
call   1070 <sprintf@plt>
mov    %r14,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@timetostr.buf = internal global [128 x i8] zeroinitializer
@.str = [18 x i8] c"%Y-%m-%d %H:%M:%S\00"
@.str.1 = [5 x i8] c"%.6f\00"
define i8* @timetostr(double %0) {
%2 = alloca double
%3 = alloca i8*
%4 = alloca i32
store double %0, double* %2
%5 = load double, double* %2
%6 = fptosi double %5 to i32
store i32 %6, i32* %4
%7 = call i32 @localtime(i32* %4)
%8 = call i32 @strftime(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @timetostr.buf, i64 0, i64 0), i32 128, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = call i32 @strlen(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @timetostr.buf, i64 0, i64 0))
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i8, i8* getelementptr inbounds ([128 x i8], [128 x i8]* @timetostr.buf, i64 0, i64 0), i64 %10
%12 = getelementptr inbounds i8, i8* %11, i64 -1
store i8* %12, i8** %3
%13 = load i8*, i8** %3
%14 = load double, double* %2
%15 = call double @fmod(double %14, i32 10)
%16 = call i32 @sprintf(i8* %13, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), double %15)
ret i8* getelementptr inbounds ([128 x i8], [128 x i8]* @timetostr.buf, i64 0, i64 0)
}

LLVM IR (-O2):
@timetostr.buf = internal global [128 x i8] zeroinitializer
@.str = [18 x i8] c"%Y-%m-%d %H:%M:%S\00"
@.str.1 = [5 x i8] c"%.6f\00"
define i8* @timetostr(double %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = fptosi double %0 to i32
store i32 %4, i32* %2
%5 = call i32 @localtime(i32* %2)
%6 = call i32 @strftime(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @timetostr.buf, i64 0, i64 0), i32 128, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = call i32 @strlen(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @timetostr.buf, i64 0, i64 0))
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds [128 x i8], [128 x i8]* @timetostr.buf, i64 0, i64 %8
%10 = getelementptr inbounds i8, i8* %9, i64 -1
%11 = call double @fmod(double %0, i32 10)
%12 = call i32 @sprintf(i8* %10, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), double %11)
ret i8* getelementptr inbounds ([128 x i8], [128 x i8]* @timetostr.buf, i64 0, i64 0)
}