#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 tv_sec;
  int tv_nsec;
};

/* Variables and functions */
unsigned int calculate_watt(const struct timespec *last_pulse,
                            const struct timespec *now) {
  unsigned int delta;
  unsigned int watt;
  delta = (now->tv_sec - last_pulse->tv_sec) * 1000000 + (now->tv_nsec / 1000) -
          (last_pulse->tv_nsec / 1000);
  watt = (3600000000u / delta) * 1000 / 600;
  return watt;
}


x86 assembly (clang, -O0):
<calculate_watt>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    -0x8(%rbp),%rcx
sub    (%rcx),%eax
imul   $0xf4240,%eax,%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    $0xd693a400,%eax
xor    %edx,%edx
divl   -0x14(%rbp)
imul   $0x3e8,%eax,%eax
mov    $0x258,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<calculate_watt>:
mov    (%rsi),%eax
sub    (%rdi),%eax
imul   $0xf4240,%eax,%eax
movslq 0x4(%rsi),%rcx
imul   $0x10624dd3,%rcx,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x26,%rcx
add    %edx,%ecx
add    %eax,%ecx
movslq 0x4(%rdi),%rax
imul   $0xffffffffef9db22d,%rax,%rsi
mov    %rsi,%rax
shr    $0x3f,%rax
sar    $0x26,%rsi
add    %eax,%esi
add    %ecx,%esi
mov    $0xd693a400,%eax
xor    %edx,%edx
div    %esi
imul   $0x3e8,%eax,%eax
imul   $0x1b4e81b5,%rax,%rax
shr    $0x26,%rax
ret

LLVM IR (-O0):
%struct.timespec = type { i32, i32 }
define i32 @calculate_watt(%struct.timespec* %0, %struct.timespec* %1) {
%3 = alloca %struct.timespec*
%4 = alloca %struct.timespec*
%5 = alloca i32
%6 = alloca i32
store %struct.timespec* %0, %struct.timespec** %3
store %struct.timespec* %1, %struct.timespec** %4
%7 = load %struct.timespec*, %struct.timespec** %4
%8 = getelementptr inbounds %struct.timespec, %struct.timespec* %7, i32 0, i32 0
%9 = load i32, i32* %8
%10 = load %struct.timespec*, %struct.timespec** %3
%11 = getelementptr inbounds %struct.timespec, %struct.timespec* %10, i32 0, i32 0
%12 = load i32, i32* %11
%13 = sub nsw i32 %9, %12
%14 = mul nsw i32 %13, 1000000
%15 = load %struct.timespec*, %struct.timespec** %4
%16 = getelementptr inbounds %struct.timespec, %struct.timespec* %15, i32 0, i32 1
%17 = load i32, i32* %16
%18 = sdiv i32 %17, 1000
%19 = add nsw i32 %14, %18
%20 = load %struct.timespec*, %struct.timespec** %3
%21 = getelementptr inbounds %struct.timespec, %struct.timespec* %20, i32 0, i32 1
%22 = load i32, i32* %21
%23 = sdiv i32 %22, 1000
%24 = sub nsw i32 %19, %23
store i32 %24, i32* %5
%25 = load i32, i32* %5
%26 = udiv i32 -694967296, %25
%27 = mul i32 %26, 1000
%28 = udiv i32 %27, 600
store i32 %28, i32* %6
%29 = load i32, i32* %6
ret i32 %29
}

LLVM IR (-O2):
%struct.timespec = type { i32, i32 }
define i32 @calculate_watt(%struct.timespec* nocapture %0, %struct.timespec* nocapture %1) {
%3 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 0
%4 = load i32, i32* %3
%5 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i64 0, i32 0
%6 = load i32, i32* %5
%7 = sub nsw i32 %4, %6
%8 = mul nsw i32 %7, 1000000
%9 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 1
%10 = load i32, i32* %9
%11 = sdiv i32 %10, 1000
%12 = add nsw i32 %8, %11
%13 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i64 0, i32 1
%14 = load i32, i32* %13
%15 = sdiv i32 %14, -1000
%16 = add i32 %12, %15
%17 = udiv i32 -694967296, %16
%18 = mul i32 %17, 1000
%19 = udiv i32 %18, 600
ret i32 %19
}