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

/* Variables and functions */
int tv_to_usec(struct timeval const *);
float timeval_percentage_of(const struct timeval *value,
                            const struct timeval *from, unsigned int divider) {
  unsigned long long v;
  float p;
  v = (100 * 100 * tv_to_usec(value)) / tv_to_usec(from);
  p = (float)v / (100.0 * divider);
  return p;
}


x86 assembly (clang, -O0):
<timeval_percentage_of>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <tv_to_usec@plt>
imul   $0x2710,%eax,%eax
mov    %eax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <tv_to_usec@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%eax
cltd
idiv   %ecx
cltq
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rdx
shr    %rdx
mov    %eax,%ecx
and    $0x1,%ecx
or     %rdx,%rcx
cvtsi2ss %rcx,%xmm0
addss  %xmm0,%xmm0
cvtsi2ss %rax,%xmm1
movss  %xmm1,-0x2c(%rbp)
test   %rax,%rax
movss  %xmm0,-0x28(%rbp)
js     1189 <timeval_percentage_of+0x79>
movss  -0x2c(%rbp),%xmm0
movss  %xmm0,-0x28(%rbp)
movss  -0x28(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
mov    -0x14(%rbp),%eax
cvtsi2sd %rax,%xmm2
movsd  0xe5e(%rip),%xmm1
mulsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x24(%rbp)
movss  -0x24(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<timeval_percentage_of>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%r14d
mov    %rsi,%rbx
call   1030 <tv_to_usec@plt>
imul   $0x2710,%eax,%ebp
mov    %rbx,%rdi
call   1030 <tv_to_usec@plt>
mov    %eax,%ecx
mov    %ebp,%eax
cltd
idiv   %ecx
movslq %eax,%rcx
test   %rcx,%rcx
js     1142 <timeval_percentage_of+0x32>
cvtsi2ss %eax,%xmm0
jmp    1154 <timeval_percentage_of+0x44>
shr    %rcx
and    $0x1,%eax
or     %rcx,%rax
cvtsi2ss %rax,%xmm0
addss  %xmm0,%xmm0
mov    %r14d,%eax
cvtsi2sd %rax,%xmm1
mulsd  0xe9c(%rip),%xmm1
cvtss2sd %xmm0,%xmm0
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i32 }
define float @timeval_percentage_of(%struct.timeval* %0, %struct.timeval* %1, i32 %2) {
%4 = alloca %struct.timeval*
%5 = alloca %struct.timeval*
%6 = alloca i32
%7 = alloca i64
%8 = alloca float
store %struct.timeval* %0, %struct.timeval** %4
store %struct.timeval* %1, %struct.timeval** %5
store i32 %2, i32* %6
%9 = load %struct.timeval*, %struct.timeval** %4
%10 = call i32 @tv_to_usec(%struct.timeval* %9)
%11 = mul nsw i32 10000, %10
%12 = load %struct.timeval*, %struct.timeval** %5
%13 = call i32 @tv_to_usec(%struct.timeval* %12)
%14 = sdiv i32 %11, %13
%15 = sext i32 %14 to i64
store i64 %15, i64* %7
%16 = load i64, i64* %7
%17 = uitofp i64 %16 to float
%18 = fpext float %17 to double
%19 = load i32, i32* %6
%20 = uitofp i32 %19 to double
%21 = fmul double 1.000000e+02, %20
%22 = fdiv double %18, %21
%23 = fptrunc double %22 to float
store float %23, float* %8
%24 = load float, float* %8
ret float %24
}

LLVM IR (-O2):
%struct.timeval = type { i32 }
define float @timeval_percentage_of(%struct.timeval* %0, %struct.timeval* %1, i32 %2) {
%4 = tail call i32 @tv_to_usec(%struct.timeval* %0)
%5 = mul nsw i32 %4, 10000
%6 = tail call i32 @tv_to_usec(%struct.timeval* %1)
%7 = sdiv i32 %5, %6
%8 = sext i32 %7 to i64
%9 = uitofp i64 %8 to float
%10 = fpext float %9 to double
%11 = uitofp i32 %2 to double
%12 = fmul double %11, 1.000000e+02
%13 = fdiv double %10, %12
%14 = fptrunc double %13 to float
ret float %14
}