#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 long time_t;
struct tm {
  int tm_mon;
  int tm_year;
  scalar_t__ tm_mday;
  scalar_t__ tm_sec;
  scalar_t__ tm_min;
  scalar_t__ tm_hour;
};

/* Variables and functions */
struct tm *localtime(long *);
scalar_t__ time(int /*<<< orphan*/ *);
double dotime(int which, double when) {
  static long t_cache;
  static struct tm *tp;
  time_t tloc;
  if (which == 256 + 26)
    return (double)time(NULL);
  tloc = (time_t)when;
  if (tloc != t_cache) {
    tp = localtime(&tloc);
    tp->tm_mon += 1;
    tp->tm_year += 1900;
    t_cache = tloc;
  }
  switch (which) {
  case 256 + 20:
    return ((double)(tp->tm_hour));
  case 256 + 21:
    return ((double)(tp->tm_min));
  case 256 + 22:
    return ((double)(tp->tm_sec));
  case 256 + 23:
    return ((double)(tp->tm_mon));
  case 256 + 24:
    return ((double)(tp->tm_mday));
  case 256 + 25:
    return ((double)(tp->tm_year));
  }
  return (0.0);
}


x86 assembly (clang, -O0):
<dotime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0xc(%rbp)
movsd  %xmm0,-0x18(%rbp)
cmpl   $0x11a,-0xc(%rbp)
jne    1155 <dotime+0x35>
xor    %eax,%eax
mov    %eax,%edi
call   1040 <time@plt>
cvtsi2sd %rax,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1266 <dotime+0x146>
cvttsd2si -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    0x2ece(%rip),%rax
je     11ac <dotime+0x8c>
lea    -0x20(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,0x2ec0(%rip)
mov    0x2eb9(%rip),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
mov    0x2eab(%rip),%rax
mov    0x4(%rax),%ecx
add    $0x76c,%ecx
mov    %ecx,0x4(%rax)
mov    -0x20(%rbp),%rax
mov    %rax,0x2e8c(%rip)
mov    -0xc(%rbp),%eax
add    $0xfffffeec,%eax
mov    %eax,%ecx
mov    %rcx,-0x28(%rbp)
sub    $0x5,%eax
ja     125e <dotime+0x13e>
mov    -0x28(%rbp),%rax
lea    0xe32(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    0x2e62(%rip),%rax
cvtsi2sdq 0x20(%rax),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1266 <dotime+0x146>
mov    0x2e4b(%rip),%rax
cvtsi2sdq 0x18(%rax),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1266 <dotime+0x146>
mov    0x2e34(%rip),%rax
cvtsi2sdq 0x10(%rax),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1266 <dotime+0x146>
mov    0x2e1d(%rip),%rax
cvtsi2sdl (%rax),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1266 <dotime+0x146>
mov    0x2e08(%rip),%rax
cvtsi2sdq 0x8(%rax),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1266 <dotime+0x146>
mov    0x2df1(%rip),%rax
cvtsi2sdl 0x4(%rax),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1266 <dotime+0x146>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dotime>:
push   %rbx
sub    $0x10,%rsp
cmp    $0x11a,%edi
jne    1142 <dotime+0x22>
xor    %edi,%edi
call   1040 <time@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
add    $0x10,%rsp
pop    %rbx
ret
mov    %edi,%ebx
cvttsd2si %xmm0,%rax
mov    %rax,0x8(%rsp)
cmp    %rax,0x2ee3(%rip)
je     117e <dotime+0x5e>
lea    0x8(%rsp),%rdi
call   1030 <localtime@plt>
mov    %rax,0x2ed8(%rip)
addl   $0x1,(%rax)
addl   $0x76c,0x4(%rax)
mov    0x8(%rsp),%rax
mov    %rax,0x2eba(%rip)
add    $0xfffffeec,%ebx
cmp    $0x5,%ebx
ja     11ab <dotime+0x8b>
lea    0xe70(%rip),%rax
movslq (%rax,%rbx,4),%rcx
add    %rax,%rcx
jmp    *%rcx
mov    0x2ea0(%rip),%rax
xorps  %xmm0,%xmm0
cvtsi2sdq 0x20(%rax),%xmm0
jmp    113c <dotime+0x1c>
xorpd  %xmm0,%xmm0
jmp    113c <dotime+0x1c>
mov    0x2e88(%rip),%rax
xorps  %xmm0,%xmm0
cvtsi2sdq 0x18(%rax),%xmm0
jmp    113c <dotime+0x1c>
mov    0x2e73(%rip),%rax
xorps  %xmm0,%xmm0
cvtsi2sdq 0x10(%rax),%xmm0
jmp    113c <dotime+0x1c>
mov    0x2e5e(%rip),%rax
xorps  %xmm0,%xmm0
cvtsi2sdl (%rax),%xmm0
jmp    113c <dotime+0x1c>
mov    0x2e4b(%rip),%rax
xorps  %xmm0,%xmm0
cvtsi2sdq 0x8(%rax),%xmm0
jmp    113c <dotime+0x1c>
mov    0x2e36(%rip),%rax
xorps  %xmm0,%xmm0
cvtsi2sdl 0x4(%rax),%xmm0
jmp    113c <dotime+0x1c>

LLVM IR (-O0):
%struct.tm = type { i32, i32, i64, i64, i64, i64 }
@dotime.t_cache = internal global i64 0
@dotime.tp = internal global %struct.tm* null
define double @dotime(i32 %0, double %1) {
%3 = alloca double
%4 = alloca i32
%5 = alloca double
%6 = alloca i64
store i32 %0, i32* %4
store double %1, double* %5
%7 = load i32, i32* %4
%8 = icmp eq i32 %7, 282
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = call i64 @time(i32* null)
%11 = sitofp i64 %10 to double
store double %11, double* %3
br label %62
12: ; preds = %2
%13 = load double, double* %5
%14 = fptosi double %13 to i64
store i64 %14, i64* %6
%15 = load i64, i64* %6
%16 = load i64, i64* @dotime.t_cache
%17 = icmp ne i64 %15, %16
br i1 %17, label %18, label %29
18: ; preds = %12
%19 = call %struct.tm* @localtime(i64* %6)
store %struct.tm* %19, %struct.tm** @dotime.tp
%20 = load %struct.tm*, %struct.tm** @dotime.tp
%21 = getelementptr inbounds %struct.tm, %struct.tm* %20, i32 0, i32 0
%22 = load i32, i32* %21
%23 = add nsw i32 %22, 1
store i32 %23, i32* %21
%24 = load %struct.tm*, %struct.tm** @dotime.tp
%25 = getelementptr inbounds %struct.tm, %struct.tm* %24, i32 0, i32 1
%26 = load i32, i32* %25
%27 = add nsw i32 %26, 1900
store i32 %27, i32* %25
%28 = load i64, i64* %6
store i64 %28, i64* @dotime.t_cache
br label %29
29: ; preds = %18, %12
%30 = load i32, i32* %4
switch i32 %30, label %61 [
i32 276, label %31
i32 277, label %36
i32 278, label %41
i32 279, label %46
i32 280, label %51
i32 281, label %56
]
31: ; preds = %29
%32 = load %struct.tm*, %struct.tm** @dotime.tp
%33 = getelementptr inbounds %struct.tm, %struct.tm* %32, i32 0, i32 5
%34 = load i64, i64* %33
%35 = sitofp i64 %34 to double
store double %35, double* %3
br label %62
36: ; preds = %29
%37 = load %struct.tm*, %struct.tm** @dotime.tp
%38 = getelementptr inbounds %struct.tm, %struct.tm* %37, i32 0, i32 4
%39 = load i64, i64* %38
%40 = sitofp i64 %39 to double
store double %40, double* %3
br label %62
41: ; preds = %29
%42 = load %struct.tm*, %struct.tm** @dotime.tp
%43 = getelementptr inbounds %struct.tm, %struct.tm* %42, i32 0, i32 3
%44 = load i64, i64* %43
%45 = sitofp i64 %44 to double
store double %45, double* %3
br label %62
46: ; preds = %29
%47 = load %struct.tm*, %struct.tm** @dotime.tp
%48 = getelementptr inbounds %struct.tm, %struct.tm* %47, i32 0, i32 0
%49 = load i32, i32* %48
%50 = sitofp i32 %49 to double
store double %50, double* %3
br label %62
51: ; preds = %29
%52 = load %struct.tm*, %struct.tm** @dotime.tp
%53 = getelementptr inbounds %struct.tm, %struct.tm* %52, i32 0, i32 2
%54 = load i64, i64* %53
%55 = sitofp i64 %54 to double
store double %55, double* %3
br label %62
56: ; preds = %29
%57 = load %struct.tm*, %struct.tm** @dotime.tp
%58 = getelementptr inbounds %struct.tm, %struct.tm* %57, i32 0, i32 1
%59 = load i32, i32* %58
%60 = sitofp i32 %59 to double
store double %60, double* %3
br label %62
61: ; preds = %29
store double 0.000000e+00, double* %3
br label %62
62: ; preds = %61, %56, %51, %46, %41, %36, %31, %9
%63 = load double, double* %3
ret double %63
}

LLVM IR (-O2):
%struct.tm = type { i32, i32, i64, i64, i64, i64 }
@dotime.t_cache = internal unnamed_addr global i64 0
@dotime.tp = internal unnamed_addr global %struct.tm* null
define double @dotime(i32 %0, double %1) {
%3 = alloca i64
%4 = bitcast i64* %3 to i8*
%5 = icmp eq i32 %0, 282
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = tail call i64 @time(i32* null)
%8 = sitofp i64 %7 to double
br label %53
9: ; preds = %2
%10 = fptosi double %1 to i64
store i64 %10, i64* %3
%11 = load i64, i64* @dotime.t_cache
%12 = icmp eq i64 %11, %10
br i1 %12, label %22, label %13
13: ; preds = %9
%14 = call %struct.tm* @localtime(i64* %3)
store %struct.tm* %14, %struct.tm** @dotime.tp
%15 = getelementptr inbounds %struct.tm, %struct.tm* %14, i64 0, i32 0
%16 = load i32, i32* %15
%17 = add nsw i32 %16, 1
store i32 %17, i32* %15
%18 = getelementptr inbounds %struct.tm, %struct.tm* %14, i64 0, i32 1
%19 = load i32, i32* %18
%20 = add nsw i32 %19, 1900
store i32 %20, i32* %18
%21 = load i64, i64* %3
store i64 %21, i64* @dotime.t_cache
br label %22
22: ; preds = %13, %9
switch i32 %0, label %53 [
i32 276, label %23
i32 277, label %28
i32 278, label %33
i32 279, label %38
i32 280, label %43
i32 281, label %48
]
23: ; preds = %22
%24 = load %struct.tm*, %struct.tm** @dotime.tp
%25 = getelementptr inbounds %struct.tm, %struct.tm* %24, i64 0, i32 5
%26 = load i64, i64* %25
%27 = sitofp i64 %26 to double
br label %53
28: ; preds = %22
%29 = load %struct.tm*, %struct.tm** @dotime.tp
%30 = getelementptr inbounds %struct.tm, %struct.tm* %29, i64 0, i32 4
%31 = load i64, i64* %30
%32 = sitofp i64 %31 to double
br label %53
33: ; preds = %22
%34 = load %struct.tm*, %struct.tm** @dotime.tp
%35 = getelementptr inbounds %struct.tm, %struct.tm* %34, i64 0, i32 3
%36 = load i64, i64* %35
%37 = sitofp i64 %36 to double
br label %53
38: ; preds = %22
%39 = load %struct.tm*, %struct.tm** @dotime.tp
%40 = getelementptr inbounds %struct.tm, %struct.tm* %39, i64 0, i32 0
%41 = load i32, i32* %40
%42 = sitofp i32 %41 to double
br label %53
43: ; preds = %22
%44 = load %struct.tm*, %struct.tm** @dotime.tp
%45 = getelementptr inbounds %struct.tm, %struct.tm* %44, i64 0, i32 2
%46 = load i64, i64* %45
%47 = sitofp i64 %46 to double
br label %53
48: ; preds = %22
%49 = load %struct.tm*, %struct.tm** @dotime.tp
%50 = getelementptr inbounds %struct.tm, %struct.tm* %49, i64 0, i32 1
%51 = load i32, i32* %50
%52 = sitofp i32 %51 to double
br label %53
53: ; preds = %22, %48, %43, %38, %33, %28, %23, %6
%54 = phi double [ %8, %6 ], [ %52, %48 ], [ %47, %43 ], [ %42, %38 ], [ %37, %33 ], [ %32, %28 ], [ %27, %23 ], [ 0.000000e+00, %22 ]
ret double %54
}