#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 timeval {
  int tv_sec;
  scalar_t__ tv_usec;
};

/* Variables and functions */
int /*<<< orphan*/ timersub(struct timeval const *, struct timeval const *,
                            struct timeval *);
size_t normalize(const struct timeval *start, const struct timeval *stop,
                 unsigned int num) {
  struct timeval diff;
  timersub(stop, start, &diff);
  return (double)(diff.tv_sec * 1000000 + diff.tv_usec) / num * 1000;
}


x86 assembly (clang, -O0):
<normalize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
lea    -0x28(%rbp),%rdx
call   1030 <timersub@plt>
mov    -0x28(%rbp),%eax
imul   $0xf4240,%eax,%eax
cltq
mov    -0x20(%rbp),%rcx
add    %rcx,%rax
cvtsi2sd %rax,%xmm0
mov    -0x14(%rbp),%eax
cvtsi2sd %rax,%xmm1
divsd  %xmm1,%xmm0
movsd  0xea1(%rip),%xmm1
mulsd  %xmm1,%xmm0
movaps %xmm0,%xmm1
cvttsd2si %xmm1,%rax
mov    %rax,%rdx
sar    $0x3f,%rdx
movsd  0xe8e(%rip),%xmm1
subsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rcx
and    %rdx,%rcx
or     %rcx,%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<normalize>:
push   %rbx
sub    $0x10,%rsp
mov    %edx,%ebx
mov    %rdi,%rax
mov    %rsp,%rdx
mov    %rsi,%rdi
mov    %rax,%rsi
call   1030 <timersub@plt>
movslq (%rsp),%rax
imul   $0xf4240,%rax,%rax
add    0x8(%rsp),%rax
cvtsi2sd %rax,%xmm0
mov    %ebx,%eax
cvtsi2sd %rax,%xmm1
divsd  %xmm1,%xmm0
mulsd  0xeb0(%rip),%xmm0
cvttsd2si %xmm0,%rcx
mov    %rcx,%rdx
sar    $0x3f,%rdx
subsd  0xea4(%rip),%xmm0
cvttsd2si %xmm0,%rax
and    %rdx,%rax
or     %rcx,%rax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i64 }
define i64 @normalize(%struct.timeval* %0, %struct.timeval* %1, i32 %2) {
%4 = alloca %struct.timeval*
%5 = alloca %struct.timeval*
%6 = alloca i32
%7 = alloca %struct.timeval
store %struct.timeval* %0, %struct.timeval** %4
store %struct.timeval* %1, %struct.timeval** %5
store i32 %2, i32* %6
%8 = load %struct.timeval*, %struct.timeval** %5
%9 = load %struct.timeval*, %struct.timeval** %4
%10 = call i32 @timersub(%struct.timeval* %8, %struct.timeval* %9, %struct.timeval* %7)
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 0
%12 = load i32, i32* %11
%13 = mul nsw i32 %12, 1000000
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 1
%16 = load i64, i64* %15
%17 = add nsw i64 %14, %16
%18 = sitofp i64 %17 to double
%19 = load i32, i32* %6
%20 = uitofp i32 %19 to double
%21 = fdiv double %18, %20
%22 = fmul double %21, 1.000000e+03
%23 = fptoui double %22 to i64
ret i64 %23
}

LLVM IR (-O2):
%struct.timeval = type { i32, i64 }
define i64 @normalize(%struct.timeval* %0, %struct.timeval* %1, i32 %2) {
%4 = alloca %struct.timeval
%5 = bitcast %struct.timeval* %4 to i8*
%6 = call i32 @timersub(%struct.timeval* %1, %struct.timeval* %0, %struct.timeval* %4)
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 0
%8 = load i32, i32* %7
%9 = mul nsw i32 %8, 1000000
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 1
%12 = load i64, i64* %11
%13 = add nsw i64 %12, %10
%14 = sitofp i64 %13 to double
%15 = uitofp i32 %2 to double
%16 = fdiv double %14, %15
%17 = fmul double %16, 1.000000e+03
%18 = fptoui double %17 to i64
ret i64 %18
}