#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*/ printf(char *);
uint64_t scale(uint64_t value, uint64_t time_enabled, uint64_t time_running) {
  uint64_t res = 0;
  if (time_running > time_enabled) {
    printf("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    1146 <scale+0x36>
lea    0xebf(%rip),%rdi
call   1030 <printf@plt>
cmpq   $0x0,-0x18(%rbp)
je     1174 <scale+0x64>
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    112f <scale+0x1f>
lea    0xed6(%rip),%rdi
call   1030 <puts@plt>
test   %rbx,%rbx
je     1152 <scale+0x42>
cvtsi2sd %r15,%xmm0
cvtsi2sd %r14,%xmm1
cvtsi2sd %rbx,%xmm2
mulsd  %xmm0,%xmm1
divsd  %xmm2,%xmm1
cvttsd2si %xmm1,%rax
jmp    1154 <scale+0x44>
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 @printf(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 = [28 x i8] c"time_running > time_enabled\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 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 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
}