#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 timeval {
  long tv_sec;
  long tv_usec;
};

/* Variables and functions */
double floor(double);
int /*<<< orphan*/ localtime(int /*<<< orphan*/ const *);
size_t strftime(char *, size_t, char const *, int /*<<< orphan*/);
size_t dstrftime(char *buf, size_t maxsize, const char *format, double tm) {
  struct timeval tv;
  double tm_floor;
  tm_floor = floor(tm);
  tv.tv_sec = (long)tm_floor;
  tv.tv_usec = (long)(tm - floor(tm)) * 1000000;
  return strftime(buf, maxsize, format, localtime((const time_t *)&tv));
}


x86 assembly (clang, -O0):
<dstrftime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1050 <floor@plt>
movsd  %xmm0,-0x38(%rbp)
cvttsd2si -0x38(%rbp),%rax
mov    %rax,-0x30(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1050 <floor@plt>
movaps %xmm0,%xmm1
movsd  -0x58(%rbp),%xmm0
subsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rax
imul   $0xf4240,%rax,%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
lea    -0x30(%rbp),%rdi
call   1030 <localtime@plt>
mov    -0x50(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    -0x40(%rbp),%rdx
mov    %eax,%ecx
call   1040 <strftime@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dstrftime>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
movsd  %xmm0,0x8(%rsp)
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
call   1050 <floor@plt>
cvttsd2si %xmm0,%rax
mov    %rax,0x10(%rsp)
movsd  0x8(%rsp),%xmm1
subsd  %xmm0,%xmm1
cvttsd2si %xmm1,%rax
imul   $0xf4240,%rax,%rax
mov    %rax,0x18(%rsp)
lea    0x10(%rsp),%rdi
call   1030 <localtime@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
mov    %eax,%ecx
call   1040 <strftime@plt>
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.timeval = type { i64, i64 }
define i64 @dstrftime(i8* %0, i64 %1, i8* %2, double %3) {
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8*
%8 = alloca double
%9 = alloca %struct.timeval
%10 = alloca double
store i8* %0, i8** %5
store i64 %1, i64* %6
store i8* %2, i8** %7
store double %3, double* %8
%11 = load double, double* %8
%12 = call double @llvm.floor.f64(double %11)
store double %12, double* %10
%13 = load double, double* %10
%14 = fptosi double %13 to i64
%15 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 0
store i64 %14, i64* %15
%16 = load double, double* %8
%17 = load double, double* %8
%18 = call double @llvm.floor.f64(double %17)
%19 = fsub double %16, %18
%20 = fptosi double %19 to i64
%21 = mul nsw i64 %20, 1000000
%22 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 1
store i64 %21, i64* %22
%23 = load i8*, i8** %5
%24 = load i64, i64* %6
%25 = load i8*, i8** %7
%26 = bitcast %struct.timeval* %9 to i32*
%27 = call i32 @localtime(i32* %26)
%28 = call i64 @strftime(i8* %23, i64 %24, i8* %25, i32 %27)
ret i64 %28
}

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
define i64 @dstrftime(i8* %0, i64 %1, i8* %2, double %3) {
%5 = alloca %struct.timeval
%6 = bitcast %struct.timeval* %5 to i8*
%7 = tail call double @llvm.floor.f64(double %3)
%8 = fptosi double %7 to i64
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 0
store i64 %8, i64* %9
%10 = fsub double %3, %7
%11 = fptosi double %10 to i64
%12 = mul nsw i64 %11, 1000000
%13 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 1
store i64 %12, i64* %13
%14 = bitcast %struct.timeval* %5 to i32*
%15 = call i32 @localtime(i32* %14)
%16 = call i64 @strftime(i8* %0, i64 %1, i8* %2, i32 %15)
ret i64 %16
}