#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 scalar_t__ uint64_t;

/* Variables and functions */
int /*<<< orphan*/ debug_print(int /*<<< orphan*/ *, int, char *);
uint64_t scale(uint64_t value, uint64_t time_enabled, uint64_t time_running) {
  uint64_t res = 0;
  if (time_running > time_enabled) {
    debug_print(NULL, 2, "time_running > time_enabled\n");
  }
  if (time_running) {
    res =
        (uint64_t)((double)value * (double)time_enabled / (double)time_running);
  }
  return (res);
}


x86 assembly (clang, -O0):
<scale>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jle    114f <scale+0x3f>
xor    %eax,%eax
mov    %eax,%edi
mov    $0x2,%esi
lea    0xeb6(%rip),%rdx
call   1030 <debug_print@plt>
cmpq   $0x0,-0x18(%rbp)
je     117d <scale+0x6d>
cvtsi2sdq -0x8(%rbp),%xmm0
cvtsi2sdq -0x10(%rbp),%xmm1
mulsd  %xmm1,%xmm0
cvtsi2sdq -0x18(%rbp),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<scale>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %rdi,%r15
cmp    %rsi,%rdx
jle    1136 <scale+0x26>
lea    0xed6(%rip),%rdx
xor    %edi,%edi
mov    $0x2,%esi
call   1030 <debug_print@plt>
test   %rbx,%rbx
je     1159 <scale+0x49>
cvtsi2sd %r15,%xmm0
cvtsi2sd %r14,%xmm1
cvtsi2sd %rbx,%xmm2
mulsd  %xmm0,%xmm1
divsd  %xmm2,%xmm1
cvttsd2si %xmm1,%rax
jmp    115b <scale+0x4b>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [29 x i8] c"time_running > time_enabled\0A\00"
define i64 @scale(i64 %0, i64 %1, i64 %2) {
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
store i64 %0, i64* %4
store i64 %1, i64* %5
store i64 %2, i64* %6
store i64 0, i64* %7
%8 = load i64, i64* %6
%9 = load i64, i64* %5
%10 = icmp sgt i64 %8, %9
br i1 %10, label %11, label %13
11: ; preds = %3
%12 = call i32 @debug_print(i32* null, i32 2, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %11, %3
%14 = load i64, i64* %6
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %26
16: ; preds = %13
%17 = load i64, i64* %4
%18 = sitofp i64 %17 to double
%19 = load i64, i64* %5
%20 = sitofp i64 %19 to double
%21 = fmul double %18, %20
%22 = load i64, i64* %6
%23 = sitofp i64 %22 to double
%24 = fdiv double %21, %23
%25 = fptosi double %24 to i64
store i64 %25, i64* %7
br label %26
26: ; preds = %16, %13
%27 = load i64, i64* %7
ret i64 %27
}

LLVM IR (-O2):
@.str = [29 x i8] c"time_running > time_enabled\0A\00"
define i64 @scale(i64 %0, i64 %1, i64 %2) {
%4 = icmp sgt i64 %2, %1
br i1 %4, label %5, label %7
5: ; preds = %3
%6 = tail call i32 @debug_print(i32* null, i32 2, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
br label %7
7: ; preds = %5, %3
%8 = icmp eq i64 %2, 0
br i1 %8, label %16, label %9
9: ; preds = %7
%10 = sitofp i64 %0 to double
%11 = sitofp i64 %1 to double
%12 = fmul double %10, %11
%13 = sitofp i64 %2 to double
%14 = fdiv double %12, %13
%15 = fptosi double %14 to i64
br label %16
16: ; preds = %9, %7
%17 = phi i64 [ %15, %9 ], [ 0, %7 ]
ret i64 %17
}