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

/* Variables and functions */
double CalcJD(int, int, int, double);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
struct tm *gmtime(int /*<<< orphan*/ *);
double JDNow(void) {
  int year, month, day;
  int hours, minutes, seconds, milliseconds;
  long int usecs;
  double ut, jd;
  time_t now;
  struct timeval t;
  struct tm *g;
  gettimeofday(&t, NULL);
  now = t.tv_sec;
  usecs = t.tv_usec;
  g = gmtime(&now);
  year = g->tm_year;
  year = year + 1900;
  month = g->tm_mon;
  month = month + 1;
  day = g->tm_mday;
  hours = g->tm_hour;
  minutes = g->tm_min;
  seconds = g->tm_sec;
  milliseconds = usecs / 1000;
  ut = ((double)milliseconds) / 3600000. + ((double)seconds) / 3600. +
       ((double)minutes) / 60. + ((double)hours);
  jd = CalcJD(year, month, day, ut);
  return (jd);
}


x86 assembly (clang, -O0):
<JDNow>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
lea    -0x50(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
mov    -0x48(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x50(%rbp),%rax
mov    %rax,-0x28(%rbp)
lea    -0x3c(%rbp),%rdi
call   1050 <gmtime@plt>
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x76c,%eax
mov    %eax,-0x4(%rbp)
mov    -0x58(%rbp),%rax
mov    0x4(%rax),%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0x58(%rbp),%rax
mov    0x8(%rax),%eax
mov    %eax,-0xc(%rbp)
mov    -0x58(%rbp),%rax
mov    0xc(%rax),%eax
mov    %eax,-0x10(%rbp)
mov    -0x58(%rbp),%rax
mov    0x10(%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x58(%rbp),%rax
mov    0x14(%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x28(%rbp),%rax
mov    $0x3e8,%ecx
cqto
idiv   %rcx
mov    %eax,-0x1c(%rbp)
cvtsi2sdl -0x1c(%rbp),%xmm0
movsd  0xe43(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsi2sdl -0x18(%rbp),%xmm1
movsd  0xe2a(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
cvtsi2sdl -0x14(%rbp),%xmm1
movsd  0xe0d(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
cvtsi2sdl -0x10(%rbp),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
movsd  -0x30(%rbp),%xmm0
call   1040 <CalcJD@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<JDNow>:
push   %rbx
sub    $0x20,%rsp
lea    0x10(%rsp),%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
mov    0x18(%rsp),%eax
mov    %eax,0xc(%rsp)
movabs $0x20c49ba5e353f7cf,%rax
9b c4 20
imulq  0x10(%rsp)
mov    %rdx,%rbx
lea    0xc(%rsp),%rdi
call   1050 <gmtime@plt>
mov    $0x76c,%edi
add    (%rax),%edi
mov    0x4(%rax),%esi
mov    0x8(%rax),%edx
add    $0x1,%esi
mov    %rbx,%rcx
shr    $0x3f,%rcx
shr    $0x7,%rbx
cvtsi2sdl 0x14(%rax),%xmm0
add    %ecx,%ebx
divsd  0xe71(%rip),%xmm0
movd   %ebx,%xmm1
movd   0x10(%rax),%xmm2
punpckldq %xmm1,%xmm2
cvtdq2pd %xmm2,%xmm1
divpd  0xe68(%rip),%xmm1
movapd %xmm1,%xmm2
unpckhpd %xmm1,%xmm2
addsd  %xmm0,%xmm2
addsd  %xmm1,%xmm2
xorps  %xmm0,%xmm0
cvtsi2sdl 0xc(%rax),%xmm0
addsd  %xmm2,%xmm0
call   1040 <CalcJD@plt>
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.timeval = type { i64, i32 }
%struct.tm = type { i32, i32, i32, i32, i32, i32 }
define double @JDNow() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i64
%9 = alloca double
%10 = alloca double
%11 = alloca i32
%12 = alloca %struct.timeval
%13 = alloca %struct.tm*
%14 = call i32 @gettimeofday(%struct.timeval* %12, i32* null)
%15 = getelementptr inbounds %struct.timeval, %struct.timeval* %12, i32 0, i32 1
%16 = load i32, i32* %15
store i32 %16, i32* %11
%17 = getelementptr inbounds %struct.timeval, %struct.timeval* %12, i32 0, i32 0
%18 = load i64, i64* %17
store i64 %18, i64* %8
%19 = call %struct.tm* @gmtime(i32* %11)
store %struct.tm* %19, %struct.tm** %13
%20 = load %struct.tm*, %struct.tm** %13
%21 = getelementptr inbounds %struct.tm, %struct.tm* %20, i32 0, i32 0
%22 = load i32, i32* %21
store i32 %22, i32* %1
%23 = load i32, i32* %1
%24 = add nsw i32 %23, 1900
store i32 %24, i32* %1
%25 = load %struct.tm*, %struct.tm** %13
%26 = getelementptr inbounds %struct.tm, %struct.tm* %25, i32 0, i32 1
%27 = load i32, i32* %26
store i32 %27, i32* %2
%28 = load i32, i32* %2
%29 = add nsw i32 %28, 1
store i32 %29, i32* %2
%30 = load %struct.tm*, %struct.tm** %13
%31 = getelementptr inbounds %struct.tm, %struct.tm* %30, i32 0, i32 2
%32 = load i32, i32* %31
store i32 %32, i32* %3
%33 = load %struct.tm*, %struct.tm** %13
%34 = getelementptr inbounds %struct.tm, %struct.tm* %33, i32 0, i32 3
%35 = load i32, i32* %34
store i32 %35, i32* %4
%36 = load %struct.tm*, %struct.tm** %13
%37 = getelementptr inbounds %struct.tm, %struct.tm* %36, i32 0, i32 4
%38 = load i32, i32* %37
store i32 %38, i32* %5
%39 = load %struct.tm*, %struct.tm** %13
%40 = getelementptr inbounds %struct.tm, %struct.tm* %39, i32 0, i32 5
%41 = load i32, i32* %40
store i32 %41, i32* %6
%42 = load i64, i64* %8
%43 = sdiv i64 %42, 1000
%44 = trunc i64 %43 to i32
store i32 %44, i32* %7
%45 = load i32, i32* %7
%46 = sitofp i32 %45 to double
%47 = fdiv double %46, 3.600000e+06
%48 = load i32, i32* %6
%49 = sitofp i32 %48 to double
%50 = fdiv double %49, 3.600000e+03
%51 = fadd double %47, %50
%52 = load i32, i32* %5
%53 = sitofp i32 %52 to double
%54 = fdiv double %53, 6.000000e+01
%55 = fadd double %51, %54
%56 = load i32, i32* %4
%57 = sitofp i32 %56 to double
%58 = fadd double %55, %57
store double %58, double* %9
%59 = load i32, i32* %1
%60 = load i32, i32* %2
%61 = load i32, i32* %3
%62 = load double, double* %9
%63 = call double @CalcJD(i32 %59, i32 %60, i32 %61, double %62)
store double %63, double* %10
%64 = load double, double* %10
ret double %64
}

LLVM IR (-O2):
%struct.timeval = type { i64, i32 }
%struct.tm = type { i32, i32, i32, i32, i32, i32 }
define double @JDNow() {
%1 = alloca i32
%2 = alloca %struct.timeval
%3 = bitcast i32* %1 to i8*
%4 = bitcast %struct.timeval* %2 to i8*
%5 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
%6 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 1
%7 = load i32, i32* %6
store i32 %7, i32* %1
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
%9 = load i64, i64* %8
%10 = call %struct.tm* @gmtime(i32* %1)
%11 = getelementptr inbounds %struct.tm, %struct.tm* %10, i64 0, i32 0
%12 = load i32, i32* %11
%13 = add nsw i32 %12, 1900
%14 = getelementptr inbounds %struct.tm, %struct.tm* %10, i64 0, i32 1
%15 = load i32, i32* %14
%16 = add nsw i32 %15, 1
%17 = getelementptr inbounds %struct.tm, %struct.tm* %10, i64 0, i32 2
%18 = load i32, i32* %17
%19 = getelementptr inbounds %struct.tm, %struct.tm* %10, i64 0, i32 3
%20 = load i32, i32* %19
%21 = getelementptr inbounds %struct.tm, %struct.tm* %10, i64 0, i32 4
%22 = load i32, i32* %21
%23 = getelementptr inbounds %struct.tm, %struct.tm* %10, i64 0, i32 5
%24 = load i32, i32* %23
%25 = sdiv i64 %9, 1000
%26 = trunc i64 %25 to i32
%27 = sitofp i32 %24 to double
%28 = fdiv double %27, 3.600000e+03
%29 = insertelement <2 x i32> poison, i32 %22, i64 0
%30 = insertelement <2 x i32> %29, i32 %26, i64 1
%31 = sitofp <2 x i32> %30 to <2 x double>
%32 = fdiv <2 x double> %31, <double 6.000000e+01, double 3.600000e+06>
%33 = extractelement <2 x double> %32, i64 1
%34 = fadd double %33, %28
%35 = extractelement <2 x double> %32, i64 0
%36 = fadd double %35, %34
%37 = sitofp i32 %20 to double
%38 = fadd double %36, %37
%39 = call double @CalcJD(i32 %13, i32 %16, i32 %18, double %38)
ret double %39
}