#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 */
typedef int u_int8_t;

/* Variables and functions */
double update_token(double avtok, double reftok, u_int8_t cwrp, double rwinav) {
  double token = avtok + (reftok * (double)(cwrp / 100));
  if (token > 0.0 && token < 1.0)
    return token;
  else
    return (token < rwinav) ? token : rwinav;
}


x86 assembly (clang, -O0):
<update_token>:
push   %rbp
mov    %rsp,%rbp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
mov    %edi,-0x1c(%rbp)
movsd  %xmm2,-0x28(%rbp)
movsd  -0x10(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm0
mov    -0x1c(%rbp),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
cvtsi2sd %eax,%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    1170 <update_token+0x70>
movsd  0xeaa(%rip),%xmm0
ucomisd -0x30(%rbp),%xmm0
jbe    1170 <update_token+0x70>
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11a7 <update_token+0xa7>
movsd  -0x30(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    1193 <update_token+0x93>
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
jmp    119d <update_token+0x9d>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<update_token>:
movslq %edi,%rax
imul   $0x51eb851f,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x25,%rax
add    %ecx,%eax
cvtsi2sd %eax,%xmm3
mulsd  %xmm1,%xmm3
addsd  %xmm0,%xmm3
movapd %xmm3,%xmm0
cmpltsd %xmm2,%xmm0
movapd %xmm0,%xmm1
andpd  %xmm3,%xmm1
movapd %xmm3,%xmm4
cmpltsd 0xebf(%rip),%xmm4
movapd %xmm4,%xmm5
andpd  %xmm3,%xmm5
andnpd %xmm2,%xmm4
orpd   %xmm5,%xmm4
xorpd  %xmm5,%xmm5
cmpltsd %xmm3,%xmm5
andpd  %xmm5,%xmm4
andnpd %xmm2,%xmm5
orpd   %xmm4,%xmm5
andnpd %xmm5,%xmm0
orpd   %xmm1,%xmm0
ret

LLVM IR (-O0):
define double @update_token(double %0, double %1, i32 %2, double %3) {
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca i32
%9 = alloca double
%10 = alloca double
store double %0, double* %6
store double %1, double* %7
store i32 %2, i32* %8
store double %3, double* %9
%11 = load double, double* %6
%12 = load double, double* %7
%13 = load i32, i32* %8
%14 = sdiv i32 %13, 100
%15 = sitofp i32 %14 to double
%16 = call double @llvm.fmuladd.f64(double %12, double %15, double %11)
store double %16, double* %10
%17 = load double, double* %10
%18 = fcmp ogt double %17, 0.000000e+00
br i1 %18, label %19, label %24
19: ; preds = %4
%20 = load double, double* %10
%21 = fcmp olt double %20, 1.000000e+00
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = load double, double* %10
store double %23, double* %5
br label %34
24: ; preds = %19, %4
%25 = load double, double* %10
%26 = load double, double* %9
%27 = fcmp olt double %25, %26
br i1 %27, label %28, label %30
28: ; preds = %24
%29 = load double, double* %10
br label %32
30: ; preds = %24
%31 = load double, double* %9
br label %32
32: ; preds = %30, %28
%33 = phi double [ %29, %28 ], [ %31, %30 ]
store double %33, double* %5
br label %34
34: ; preds = %32, %22
%35 = load double, double* %5
ret double %35
}

LLVM IR (-O2):
define double @update_token(double %0, double %1, i32 %2, double %3) {
%5 = sdiv i32 %2, 100
%6 = sitofp i32 %5 to double
%7 = tail call double @llvm.fmuladd.f64(double %1, double %6, double %0)
%8 = fcmp ogt double %7, 0.000000e+00
%9 = fcmp olt double %7, 1.000000e+00
%10 = and i1 %8, %9
%11 = fcmp olt double %7, %3
%12 = or i1 %11, %10
%13 = select i1 %12, double %7, double %3
ret double %13
}