#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 {
  int dummy;
};

/* Variables and functions */
long long diff_timespec(struct timespec, struct timespec);
int /*<<< orphan*/ get_monotonic_and_raw(struct timespec *, struct timespec *);
int /*<<< orphan*/ sleep(int);
long long get_ppm_drift(void) {
  struct timespec mon_start, raw_start, mon_end, raw_end;
  long long delta1, delta2, eppm;
  get_monotonic_and_raw(&mon_start, &raw_start);
  sleep(15);
  get_monotonic_and_raw(&mon_end, &raw_end);
  delta1 = diff_timespec(mon_start, mon_end);
  delta2 = diff_timespec(raw_start, raw_end);
  eppm = (delta1 * 1000000) / delta2 - 1000000;
  return eppm;
}


x86 assembly (clang, -O0):
<get_ppm_drift>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
lea    -0x8(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   1030 <get_monotonic_and_raw@plt>
mov    $0xf,%edi
call   1050 <sleep@plt>
lea    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1030 <get_monotonic_and_raw@plt>
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%esi
call   1040 <diff_timespec@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%edi
mov    -0x20(%rbp),%esi
call   1040 <diff_timespec@plt>
mov    %rax,-0x30(%rbp)
imul   $0xf4240,-0x28(%rbp),%rax
cqto
idivq  -0x30(%rbp)
sub    $0xf4240,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_ppm_drift>:
push   %rbx
sub    $0x20,%rsp
lea    0x18(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   1030 <get_monotonic_and_raw@plt>
mov    $0xf,%edi
call   1050 <sleep@plt>
lea    0x8(%rsp),%rdi
mov    %rsp,%rsi
call   1030 <get_monotonic_and_raw@plt>
mov    0x18(%rsp),%edi
mov    0x8(%rsp),%esi
call   1040 <diff_timespec@plt>
mov    %rax,%rbx
mov    0x10(%rsp),%edi
mov    (%rsp),%esi
call   1040 <diff_timespec@plt>
mov    %rax,%rcx
imul   $0xf4240,%rbx,%rax
mov    %rcx,%rdx
or     %rax,%rdx
shr    $0x20,%rdx
je     1194 <get_ppm_drift+0x64>
cqto
idiv   %rcx
jmp    1198 <get_ppm_drift+0x68>
xor    %edx,%edx
div    %ecx
add    $0xfffffffffff0bdc0,%rax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.timespec = type { i32 }
define i64 @get_ppm_drift() {
%1 = alloca %struct.timespec
%2 = alloca %struct.timespec
%3 = alloca %struct.timespec
%4 = alloca %struct.timespec
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = call i32 @get_monotonic_and_raw(%struct.timespec* %1, %struct.timespec* %2)
%9 = call i32 @sleep(i32 15)
%10 = call i32 @get_monotonic_and_raw(%struct.timespec* %3, %struct.timespec* %4)
%11 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i32 0, i32 0
%12 = load i32, i32* %11
%13 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i32 0, i32 0
%14 = load i32, i32* %13
%15 = call i64 @diff_timespec(i32 %12, i32 %14)
store i64 %15, i64* %5
%16 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i32 0, i32 0
%17 = load i32, i32* %16
%18 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i32 0, i32 0
%19 = load i32, i32* %18
%20 = call i64 @diff_timespec(i32 %17, i32 %19)
store i64 %20, i64* %6
%21 = load i64, i64* %5
%22 = mul nsw i64 %21, 1000000
%23 = load i64, i64* %6
%24 = sdiv i64 %22, %23
%25 = sub nsw i64 %24, 1000000
store i64 %25, i64* %7
%26 = load i64, i64* %7
ret i64 %26
}

LLVM IR (-O2):
%struct.timespec = type { i32 }
define i64 @get_ppm_drift() {
%1 = alloca %struct.timespec
%2 = alloca %struct.timespec
%3 = alloca %struct.timespec
%4 = alloca %struct.timespec
%5 = bitcast %struct.timespec* %1 to i8*
%6 = bitcast %struct.timespec* %2 to i8*
%7 = bitcast %struct.timespec* %3 to i8*
%8 = bitcast %struct.timespec* %4 to i8*
%9 = call i32 @get_monotonic_and_raw(%struct.timespec* %1, %struct.timespec* %2)
%10 = call i32 @sleep(i32 15)
%11 = call i32 @get_monotonic_and_raw(%struct.timespec* %3, %struct.timespec* %4)
%12 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 0
%13 = load i32, i32* %12
%14 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i64 0, i32 0
%15 = load i32, i32* %14
%16 = call i64 @diff_timespec(i32 %13, i32 %15)
%17 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 0
%18 = load i32, i32* %17
%19 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i64 0, i32 0
%20 = load i32, i32* %19
%21 = call i64 @diff_timespec(i32 %18, i32 %20)
%22 = mul nsw i64 %16, 1000000
%23 = sdiv i64 %22, %21
%24 = add nsw i64 %23, -1000000
ret i64 %24
}