#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 unsigned long uint64_t;

/* Variables and functions */
unsigned long get_average_perf(unsigned long max_freq, uint64_t aperf_diff,
                               uint64_t mperf_diff) {
  unsigned int perf_percent = 0;
  if (((unsigned long)(-1) / 100) < aperf_diff) {
    int shift_count = 7;
    aperf_diff >>= shift_count;
    mperf_diff >>= shift_count;
  }
  perf_percent = (aperf_diff * 100) / mperf_diff;
  return (max_freq * perf_percent) / 100;
}


x86 assembly (clang, -O0):
<get_average_perf>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movabs $0x28f5c28f5c28f5c,%rax
5c 8f 02
cmp    -0x10(%rbp),%rax
jae    1152 <get_average_perf+0x52>
movl   $0x7,-0x20(%rbp)
mov    -0x20(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,%ecx
shr    %cl,%rax
mov    %rax,-0x10(%rbp)
mov    -0x20(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,%ecx
shr    %cl,%rax
mov    %rax,-0x18(%rbp)
imul   $0x64,-0x10(%rbp),%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x18(%rbp)
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x1c(%rbp),%ecx
imul   %rcx,%rax
mov    $0x64,%ecx
xor    %edx,%edx
div    %rcx
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_average_perf>:
mov    %rsi,%rax
shr    $0x7,%rax
mov    %rdx,%r8
shr    $0x7,%r8
movabs $0x28f5c28f5c28f5c,%rcx
5c 8f 02
cmp    %rcx,%rsi
cmovbe %rdx,%r8
cmovbe %rsi,%rax
imul   $0x64,%rax,%rax
mov    %rax,%rcx
or     %r8,%rcx
shr    $0x20,%rcx
je     113a <get_average_perf+0x3a>
xor    %edx,%edx
div    %r8
jmp    113f <get_average_perf+0x3f>
xor    %edx,%edx
div    %r8d
mov    %eax,%eax
imul   %rdi,%rax
shr    $0x2,%rax
movabs $0x28f5c28f5c28f5c3,%rcx
c2 f5 28
mul    %rcx
mov    %rdx,%rax
shr    $0x2,%rax
ret

LLVM IR (-O0):
define i64 @get_average_perf(i64 %0, i64 %1, i64 %2) {
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32
store i64 %0, i64* %4
store i64 %1, i64* %5
store i64 %2, i64* %6
store i32 0, i32* %7
%9 = load i64, i64* %5
%10 = icmp ult i64 184467440737095516, %9
br i1 %10, label %11, label %20
11: ; preds = %3
store i32 7, i32* %8
%12 = load i32, i32* %8
%13 = load i64, i64* %5
%14 = zext i32 %12 to i64
%15 = lshr i64 %13, %14
store i64 %15, i64* %5
%16 = load i32, i32* %8
%17 = load i64, i64* %6
%18 = zext i32 %16 to i64
%19 = lshr i64 %17, %18
store i64 %19, i64* %6
br label %20
20: ; preds = %11, %3
%21 = load i64, i64* %5
%22 = mul i64 %21, 100
%23 = load i64, i64* %6
%24 = udiv i64 %22, %23
%25 = trunc i64 %24 to i32
store i32 %25, i32* %7
%26 = load i64, i64* %4
%27 = load i32, i32* %7
%28 = zext i32 %27 to i64
%29 = mul i64 %26, %28
%30 = udiv i64 %29, 100
ret i64 %30
}

LLVM IR (-O2):
define i64 @get_average_perf(i64 %0, i64 %1, i64 %2) {
%4 = icmp ugt i64 %1, 184467440737095516
%5 = lshr i64 %1, 7
%6 = lshr i64 %2, 7
%7 = select i1 %4, i64 %6, i64 %2
%8 = select i1 %4, i64 %5, i64 %1
%9 = mul nuw i64 %8, 100
%10 = udiv i64 %9, %7
%11 = and i64 %10, 4294967295
%12 = mul i64 %11, %0
%13 = udiv i64 %12, 100
ret i64 %13
}