#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_nsec;
  double tv_sec;
};

/* Variables and functions */
scalar_t__ getclocktime(struct timespec *);
int getclockdiff(struct timespec *st, double *diffd) {
  struct timespec en;
  if (getclocktime(&en))
    return (1);
  *diffd = (en.tv_nsec - st->tv_nsec) * 0.000000001 + (en.tv_sec - st->tv_sec);
  return (0);
}


x86 assembly (clang, -O0):
<getclockdiff>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    -0x28(%rbp),%rdi
call   1030 <getclocktime@plt>
cmp    $0x0,%rax
je     113f <getclockdiff+0x2f>
movl   $0x1,-0x4(%rbp)
jmp    1179 <getclockdiff+0x69>
movsd  -0x28(%rbp),%xmm0
mov    -0x10(%rbp),%rax
subsd  (%rax),%xmm0
movsd  -0x20(%rbp),%xmm1
mov    -0x10(%rbp),%rax
subsd  0x8(%rax),%xmm1
movsd  0xe9e(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getclockdiff>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0x8(%rsp),%rdi
call   1030 <getclocktime@plt>
mov    %rax,%rcx
mov    $0x1,%eax
test   %rcx,%rcx
jne    115c <getclockdiff+0x4c>
movsd  0x8(%rsp),%xmm0
movsd  0x10(%rsp),%xmm1
subsd  (%rbx),%xmm0
subsd  0x8(%rbx),%xmm1
mulsd  0xeaf(%rip),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,(%r14)
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.timespec = type { double, double }
define i32 @getclockdiff(%struct.timespec* %0, double* %1) {
%3 = alloca i32
%4 = alloca %struct.timespec*
%5 = alloca double*
%6 = alloca %struct.timespec
store %struct.timespec* %0, %struct.timespec** %4
store double* %1, double** %5
%7 = call i64 @getclocktime(%struct.timespec* %6)
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %2
store i32 1, i32* %3
br label %25
10: ; preds = %2
%11 = getelementptr inbounds %struct.timespec, %struct.timespec* %6, i32 0, i32 0
%12 = load double, double* %11
%13 = load %struct.timespec*, %struct.timespec** %4
%14 = getelementptr inbounds %struct.timespec, %struct.timespec* %13, i32 0, i32 0
%15 = load double, double* %14
%16 = fsub double %12, %15
%17 = getelementptr inbounds %struct.timespec, %struct.timespec* %6, i32 0, i32 1
%18 = load double, double* %17
%19 = load %struct.timespec*, %struct.timespec** %4
%20 = getelementptr inbounds %struct.timespec, %struct.timespec* %19, i32 0, i32 1
%21 = load double, double* %20
%22 = fsub double %18, %21
%23 = call double @llvm.fmuladd.f64(double %16, double 1.000000e-09, double %22)
%24 = load double*, double** %5
store double %23, double* %24
store i32 0, i32* %3
br label %25
25: ; preds = %10, %9
%26 = load i32, i32* %3
ret i32 %26
}

LLVM IR (-O2):
%struct.timespec = type { double, double }
define i32 @getclockdiff(%struct.timespec* nocapture %0, double* nocapture writeonly %1) {
%3 = alloca %struct.timespec
%4 = bitcast %struct.timespec* %3 to i8*
%5 = call i64 @getclocktime(%struct.timespec* %3)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %19
7: ; preds = %2
%8 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i64 0, i32 0
%9 = load double, double* %8
%10 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i64 0, i32 0
%11 = load double, double* %10
%12 = fsub double %9, %11
%13 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i64 0, i32 1
%14 = load double, double* %13
%15 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i64 0, i32 1
%16 = load double, double* %15
%17 = fsub double %14, %16
%18 = call double @llvm.fmuladd.f64(double %12, double 1.000000e-09, double %17)
store double %18, double* %1
br label %19
19: ; preds = %2, %7
%20 = phi i32 [ 0, %7 ], [ 1, %2 ]
ret i32 %20
}