#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 */
struct timespec {
  double tv_sec;
  double tv_nsec;
};

/* Variables and functions */
int /*<<< orphan*/ fabs(double);
int /*<<< orphan*/ timespec_add(struct timespec, struct timespec,
                                struct timespec *);
int /*<<< orphan*/ timespec_fromdouble(int /*<<< orphan*/, struct timespec *);
int /*<<< orphan*/ timespec_sub(struct timespec, struct timespec,
                                struct timespec *);
void timespec_shift(struct timespec base, double fraction,
                    struct timespec *target) {
  struct timespec ts;
  double shift = base.tv_sec * fraction;
  shift += (base.tv_nsec * fraction) / 1000000000.0;
  timespec_fromdouble(fabs(shift), &ts);
  if (fraction >= 0) {
    timespec_add(*target, ts, target);
  } else {
    timespec_sub(*target, ts, target);
  }
}


x86 assembly (clang, -O0):
<timespec_shift>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x8(%rbp)
movsd  %xmm2,-0x18(%rbp)
mov    %rdi,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x8(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  0xe84(%rip),%xmm1
divsd  %xmm1,%xmm0
addsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
call   1040 <fabs@plt>
mov    %eax,%edi
lea    -0x30(%rbp),%rsi
call   1060 <timespec_fromdouble@plt>
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     11d6 <timespec_shift+0x96>
mov    -0x20(%rbp),%rax
mov    -0x20(%rbp),%rdi
movsd  (%rax),%xmm0
movsd  0x8(%rax),%xmm1
movsd  -0x30(%rbp),%xmm2
movsd  -0x28(%rbp),%xmm3
call   1030 <timespec_add@plt>
jmp    11f6 <timespec_shift+0xb6>
mov    -0x20(%rbp),%rax
mov    -0x20(%rbp),%rdi
movsd  (%rax),%xmm0
movsd  0x8(%rax),%xmm1
movsd  -0x30(%rbp),%xmm2
movsd  -0x28(%rbp),%xmm3
call   1050 <timespec_sub@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<timespec_shift>:
push   %rbx
sub    $0x20,%rsp
mov    %rdi,%rbx
movsd  %xmm2,0x8(%rsp)
mulsd  %xmm2,%xmm0
mulsd  %xmm2,%xmm1
divsd  0xea2(%rip),%xmm1
addsd  %xmm1,%xmm0
call   1040 <fabs@plt>
lea    0x10(%rsp),%rsi
mov    %eax,%edi
call   1060 <timespec_fromdouble@plt>
xorpd  %xmm0,%xmm0
movsd  0x8(%rsp),%xmm1
ucomisd %xmm0,%xmm1
movsd  (%rbx),%xmm0
movsd  0x8(%rbx),%xmm1
movsd  0x10(%rsp),%xmm2
movsd  0x18(%rsp),%xmm3
mov    %rbx,%rdi
jae    11a2 <timespec_shift+0x62>
call   1050 <timespec_sub@plt>
jmp    11a7 <timespec_shift+0x67>
call   1030 <timespec_add@plt>
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.timespec = type { double, double }
define void @timespec_shift(double %0, double %1, double %2, %struct.timespec* %3) {
%5 = alloca %struct.timespec
%6 = alloca double
%7 = alloca %struct.timespec*
%8 = alloca %struct.timespec
%9 = alloca double
%10 = bitcast %struct.timespec* %5 to { double, double }*
%11 = getelementptr inbounds { double, double }, { double, double }* %10, i32 0, i32 0
store double %0, double* %11
%12 = getelementptr inbounds { double, double }, { double, double }* %10, i32 0, i32 1
store double %1, double* %12
store double %2, double* %6
store %struct.timespec* %3, %struct.timespec** %7
%13 = getelementptr inbounds %struct.timespec, %struct.timespec* %5, i32 0, i32 0
%14 = load double, double* %13
%15 = load double, double* %6
%16 = fmul double %14, %15
store double %16, double* %9
%17 = getelementptr inbounds %struct.timespec, %struct.timespec* %5, i32 0, i32 1
%18 = load double, double* %17
%19 = load double, double* %6
%20 = fmul double %18, %19
%21 = fdiv double %20, 1.000000e+09
%22 = load double, double* %9
%23 = fadd double %22, %21
store double %23, double* %9
%24 = load double, double* %9
%25 = call i32 @fabs(double %24)
%26 = call i32 @timespec_fromdouble(i32 %25, %struct.timespec* %8)
%27 = load double, double* %6
%28 = fcmp oge double %27, 0.000000e+00
br i1 %28, label %29, label %43
29: ; preds = %4
%30 = load %struct.timespec*, %struct.timespec** %7
%31 = load %struct.timespec*, %struct.timespec** %7
%32 = bitcast %struct.timespec* %30 to { double, double }*
%33 = getelementptr inbounds { double, double }, { double, double }* %32, i32 0, i32 0
%34 = load double, double* %33
%35 = getelementptr inbounds { double, double }, { double, double }* %32, i32 0, i32 1
%36 = load double, double* %35
%37 = bitcast %struct.timespec* %8 to { double, double }*
%38 = getelementptr inbounds { double, double }, { double, double }* %37, i32 0, i32 0
%39 = load double, double* %38
%40 = getelementptr inbounds { double, double }, { double, double }* %37, i32 0, i32 1
%41 = load double, double* %40
%42 = call i32 @timespec_add(double %34, double %36, double %39, double %41, %struct.timespec* %31)
br label %57
43: ; preds = %4
%44 = load %struct.timespec*, %struct.timespec** %7
%45 = load %struct.timespec*, %struct.timespec** %7
%46 = bitcast %struct.timespec* %44 to { double, double }*
%47 = getelementptr inbounds { double, double }, { double, double }* %46, i32 0, i32 0
%48 = load double, double* %47
%49 = getelementptr inbounds { double, double }, { double, double }* %46, i32 0, i32 1
%50 = load double, double* %49
%51 = bitcast %struct.timespec* %8 to { double, double }*
%52 = getelementptr inbounds { double, double }, { double, double }* %51, i32 0, i32 0
%53 = load double, double* %52
%54 = getelementptr inbounds { double, double }, { double, double }* %51, i32 0, i32 1
%55 = load double, double* %54
%56 = call i32 @timespec_sub(double %48, double %50, double %53, double %55, %struct.timespec* %45)
br label %57
57: ; preds = %43, %29
ret void
}

LLVM IR (-O2):
%struct.timespec = type { double, double }
define void @timespec_shift(double %0, double %1, double %2, %struct.timespec* %3) {
%5 = alloca %struct.timespec
%6 = bitcast %struct.timespec* %5 to i8*
%7 = fmul double %0, %2
%8 = fmul double %1, %2
%9 = fdiv double %8, 1.000000e+09
%10 = fadd double %7, %9
%11 = tail call i32 @fabs(double %10)
%12 = call i32 @timespec_fromdouble(i32 %11, %struct.timespec* %5)
%13 = fcmp ult double %2, 0.000000e+00
%14 = getelementptr %struct.timespec, %struct.timespec* %3, i64 0, i32 0
%15 = load double, double* %14
%16 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i64 0, i32 1
%17 = load double, double* %16
%18 = getelementptr inbounds %struct.timespec, %struct.timespec* %5, i64 0, i32 0
%19 = load double, double* %18
%20 = getelementptr inbounds %struct.timespec, %struct.timespec* %5, i64 0, i32 1
%21 = load double, double* %20
br i1 %13, label %24, label %22
22: ; preds = %4
%23 = call i32 @timespec_add(double %15, double %17, double %19, double %21, %struct.timespec* %3)
br label %26
24: ; preds = %4
%25 = call i32 @timespec_sub(double %15, double %17, double %19, double %21, %struct.timespec* %3)
br label %26
26: ; preds = %24, %22
ret void
}