#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 double time_t;
struct tm {
  long tm_gmtoff;
};

/* Variables and functions */
double fmod(double, double);
struct tm *localtime(double *);
double libt_timetointerval4(double walltime, double interval, double offset,
                            double pad) {
  double value;
  if (interval >= 3600 * 1.5) {
    long gmtoff;
    time_t lwalltime, newtime;
    struct tm *tm;
    lwalltime = walltime;
    gmtoff = localtime(&lwalltime)->tm_gmtoff;
    value = interval - fmod(walltime + gmtoff - offset, interval);
    newtime = walltime + value;
    tm = localtime(&newtime);
    if (tm->tm_gmtoff != gmtoff)
      value = value + gmtoff - tm->tm_gmtoff;
  } else {
    value = interval - fmod(walltime - offset, interval);
  }
  if (value < pad)
    value = value + pad +
            libt_timetointerval4(walltime + value + pad, interval, offset, pad);
  return value;
}


x86 assembly (clang, -O0):
<libt_timetointerval4>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  %xmm2,-0x18(%rbp)
movsd  %xmm3,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xea7(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     1209 <libt_timetointerval4+0xd9>
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
lea    -0x38(%rbp),%rdi
call   1030 <localtime@plt>
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x8(%rbp),%xmm0
cvtsi2sdq -0x30(%rbp),%xmm1
addsd  %xmm1,%xmm0
subsd  -0x18(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
call   1040 <fmod@plt>
movaps %xmm0,%xmm1
movsd  -0x50(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x8(%rbp),%xmm0
addsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
lea    -0x40(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
mov    (%rax),%rax
cmp    -0x30(%rbp),%rax
je     1204 <libt_timetointerval4+0xd4>
movsd  -0x28(%rbp),%xmm0
cvtsi2sdq -0x30(%rbp),%xmm1
addsd  %xmm1,%xmm0
mov    -0x48(%rbp),%rax
cvtsi2sdq (%rax),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    1238 <libt_timetointerval4+0x108>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x8(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
call   1040 <fmod@plt>
movaps %xmm0,%xmm1
movsd  -0x58(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    128f <libt_timetointerval4+0x15f>
movsd  -0x28(%rbp),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x8(%rbp),%xmm0
addsd  -0x28(%rbp),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm2
movsd  -0x20(%rbp),%xmm3
call   1050 <libt_timetointerval4@plt>
movaps %xmm0,%xmm1
movsd  -0x60(%rbp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<libt_timetointerval4>:
push   %rbx
sub    $0x40,%rsp
movsd  %xmm3,0x8(%rsp)
ucomisd 0xebd(%rip),%xmm1
movsd  %xmm2,0x20(%rsp)
movsd  %xmm1,(%rsp)
movsd  %xmm0,0x10(%rsp)
jae    1186 <libt_timetointerval4+0x56>
subsd  %xmm2,%xmm0
movsd  (%rsp),%xmm1
call   1040 <fmod@plt>
movsd  (%rsp),%xmm1
movapd %xmm1,%xmm2
subsd  %xmm0,%xmm2
movsd  0x8(%rsp),%xmm3
ucomisd %xmm2,%xmm3
ja     121f <libt_timetointerval4+0xef>
jmp    1250 <libt_timetointerval4+0x120>
movsd  %xmm0,0x38(%rsp)
lea    0x38(%rsp),%rdi
call   1030 <localtime@plt>
mov    (%rax),%rbx
xorps  %xmm0,%xmm0
cvtsi2sd %rbx,%xmm0
movsd  %xmm0,0x28(%rsp)
addsd  0x10(%rsp),%xmm0
subsd  0x20(%rsp),%xmm0
movsd  (%rsp),%xmm1
call   1040 <fmod@plt>
movsd  (%rsp),%xmm1
subsd  %xmm0,%xmm1
movsd  %xmm1,0x18(%rsp)
movapd %xmm1,%xmm0
addsd  0x10(%rsp),%xmm0
movsd  %xmm0,0x30(%rsp)
lea    0x30(%rsp),%rdi
call   1030 <localtime@plt>
mov    (%rax),%rax
cmp    %rbx,%rax
je     1208 <libt_timetointerval4+0xd8>
movsd  0x18(%rsp),%xmm2
addsd  0x28(%rsp),%xmm2
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
subsd  %xmm0,%xmm2
jmp    120e <libt_timetointerval4+0xde>
movsd  0x18(%rsp),%xmm2
movsd  0x8(%rsp),%xmm3
movsd  (%rsp),%xmm1
ucomisd %xmm2,%xmm3
jbe    1250 <libt_timetointerval4+0x120>
movapd %xmm2,%xmm0
addsd  %xmm3,%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0x10(%rsp),%xmm0
addsd  %xmm2,%xmm0
addsd  %xmm3,%xmm0
movsd  0x20(%rsp),%xmm2
call   1050 <libt_timetointerval4@plt>
movapd %xmm0,%xmm2
addsd  0x8(%rsp),%xmm2
movapd %xmm2,%xmm0
add    $0x40,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.tm = type { i64 }
define double @libt_timetointerval4(double %0, double %1, double %2, double %3) {
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca i64
%11 = alloca double
%12 = alloca double
%13 = alloca %struct.tm*
store double %0, double* %5
store double %1, double* %6
store double %2, double* %7
store double %3, double* %8
%14 = load double, double* %6
%15 = fcmp oge double %14, 5.400000e+03
br i1 %15, label %16, label %51
16: ; preds = %4
%17 = load double, double* %5
store double %17, double* %11
%18 = call %struct.tm* @localtime(double* %11)
%19 = getelementptr inbounds %struct.tm, %struct.tm* %18, i32 0, i32 0
%20 = load i64, i64* %19
store i64 %20, i64* %10
%21 = load double, double* %6
%22 = load double, double* %5
%23 = load i64, i64* %10
%24 = sitofp i64 %23 to double
%25 = fadd double %22, %24
%26 = load double, double* %7
%27 = fsub double %25, %26
%28 = load double, double* %6
%29 = call double @fmod(double %27, double %28)
%30 = fsub double %21, %29
store double %30, double* %9
%31 = load double, double* %5
%32 = load double, double* %9
%33 = fadd double %31, %32
store double %33, double* %12
%34 = call %struct.tm* @localtime(double* %12)
store %struct.tm* %34, %struct.tm** %13
%35 = load %struct.tm*, %struct.tm** %13
%36 = getelementptr inbounds %struct.tm, %struct.tm* %35, i32 0, i32 0
%37 = load i64, i64* %36
%38 = load i64, i64* %10
%39 = icmp ne i64 %37, %38
br i1 %39, label %40, label %50
40: ; preds = %16
%41 = load double, double* %9
%42 = load i64, i64* %10
%43 = sitofp i64 %42 to double
%44 = fadd double %41, %43
%45 = load %struct.tm*, %struct.tm** %13
%46 = getelementptr inbounds %struct.tm, %struct.tm* %45, i32 0, i32 0
%47 = load i64, i64* %46
%48 = sitofp i64 %47 to double
%49 = fsub double %44, %48
store double %49, double* %9
br label %50
50: ; preds = %40, %16
br label %59
51: ; preds = %4
%52 = load double, double* %6
%53 = load double, double* %5
%54 = load double, double* %7
%55 = fsub double %53, %54
%56 = load double, double* %6
%57 = call double @fmod(double %55, double %56)
%58 = fsub double %52, %57
store double %58, double* %9
br label %59
59: ; preds = %51, %50
%60 = load double, double* %9
%61 = load double, double* %8
%62 = fcmp olt double %60, %61
br i1 %62, label %63, label %77
63: ; preds = %59
%64 = load double, double* %9
%65 = load double, double* %8
%66 = fadd double %64, %65
%67 = load double, double* %5
%68 = load double, double* %9
%69 = fadd double %67, %68
%70 = load double, double* %8
%71 = fadd double %69, %70
%72 = load double, double* %6
%73 = load double, double* %7
%74 = load double, double* %8
%75 = call double @libt_timetointerval4(double %71, double %72, double %73, double %74)
%76 = fadd double %66, %75
store double %76, double* %9
br label %77
77: ; preds = %63, %59
%78 = load double, double* %9
ret double %78
}

LLVM IR (-O2):
%struct.tm = type { i64 }
define double @libt_timetointerval4(double %0, double %1, double %2, double %3) {
%5 = alloca double
%6 = alloca double
%7 = fcmp ult double %1, 5.400000e+03
br i1 %7, label %28, label %8
8: ; preds = %4
%9 = bitcast double* %5 to i8*
%10 = bitcast double* %6 to i8*
store double %0, double* %5
%11 = call %struct.tm* @localtime(double* %5)
%12 = getelementptr inbounds %struct.tm, %struct.tm* %11, i64 0, i32 0
%13 = load i64, i64* %12
%14 = sitofp i64 %13 to double
%15 = fadd double %14, %0
%16 = fsub double %15, %2
%17 = call double @fmod(double %16, double %1)
%18 = fsub double %1, %17
%19 = fadd double %18, %0
store double %19, double* %6
%20 = call %struct.tm* @localtime(double* %6)
%21 = getelementptr inbounds %struct.tm, %struct.tm* %20, i64 0, i32 0
%22 = load i64, i64* %21
%23 = icmp eq i64 %22, %13
%24 = fadd double %18, %14
%25 = sitofp i64 %22 to double
%26 = fsub double %24, %25
%27 = select i1 %23, double %18, double %26
br label %32
28: ; preds = %4
%29 = fsub double %0, %2
%30 = tail call double @fmod(double %29, double %1)
%31 = fsub double %1, %30
br label %32
32: ; preds = %28, %8
%33 = phi double [ %27, %8 ], [ %31, %28 ]
%34 = fcmp olt double %33, %3
br i1 %34, label %35, label %41
35: ; preds = %32
%36 = fadd double %33, %3
%37 = fadd double %33, %0
%38 = fadd double %37, %3
%39 = call double @libt_timetointerval4(double %38, double %1, double %2, double %3)
%40 = fadd double %36, %39
br label %41
41: ; preds = %35, %32
%42 = phi double [ %40, %35 ], [ %33, %32 ]
ret double %42
}