#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 */

/* Variables and functions */
int get_processor_number_online();
void normalize_loadavg(double *loadavg, int numcpus) {
  int i;
  if (!numcpus)
    numcpus = get_processor_number_online();
  for (i = 0; i < 3; i++) {
    if (numcpus > 1)
      loadavg[i] /= numcpus;
  }
}


x86 assembly (clang, -O0):
<normalize_loadavg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    1133 <normalize_loadavg+0x23>
mov    $0x0,%al
call   1030 <get_processor_number_online@plt>
mov    %eax,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x3,-0x10(%rbp)
jge    117c <normalize_loadavg+0x6c>
cmpl   $0x1,-0xc(%rbp)
jle    1169 <normalize_loadavg+0x59>
cvtsi2sdl -0xc(%rbp),%xmm1
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
jmp    116e <normalize_loadavg+0x5e>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    113a <normalize_loadavg+0x2a>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<normalize_loadavg>:
push   %rbx
mov    %rdi,%rbx
test   %esi,%esi
je     111f <normalize_loadavg+0xf>
cmp    $0x2,%esi
jge    112d <normalize_loadavg+0x1d>
pop    %rbx
ret
xor    %eax,%eax
call   1030 <get_processor_number_online@plt>
mov    %eax,%esi
cmp    $0x2,%esi
jl     111d <normalize_loadavg+0xd>
cvtsi2sd %esi,%xmm0
movupd (%rbx),%xmm1
movapd %xmm0,%xmm2
unpcklpd %xmm0,%xmm2
divpd  %xmm2,%xmm1
movupd %xmm1,(%rbx)
movsd  0x10(%rbx),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,0x10(%rbx)
pop    %rbx
ret

LLVM IR (-O0):
define void @normalize_loadavg(double* %0, i32 %1) {
%3 = alloca double*
%4 = alloca i32
%5 = alloca i32
store double* %0, double** %3
store i32 %1, i32* %4
%6 = load i32, i32* %4
%7 = icmp ne i32 %6, 0
br i1 %7, label %10, label %8
8: ; preds = %2
%9 = call i32 (...) @get_processor_number_online()
store i32 %9, i32* %4
br label %10
10: ; preds = %8, %2
store i32 0, i32* %5
br label %11
11: ; preds = %27, %10
%12 = load i32, i32* %5
%13 = icmp slt i32 %12, 3
br i1 %13, label %14, label %30
14: ; preds = %11
%15 = load i32, i32* %4
%16 = icmp sgt i32 %15, 1
br i1 %16, label %17, label %26
17: ; preds = %14
%18 = load i32, i32* %4
%19 = sitofp i32 %18 to double
%20 = load double*, double** %3
%21 = load i32, i32* %5
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds double, double* %20, i64 %22
%24 = load double, double* %23
%25 = fdiv double %24, %19
store double %25, double* %23
br label %26
26: ; preds = %17, %14
br label %27
27: ; preds = %26
%28 = load i32, i32* %5
%29 = add nsw i32 %28, 1
store i32 %29, i32* %5
br label %11
30: ; preds = %11
ret void
}

LLVM IR (-O2):
define void @normalize_loadavg(double* nocapture %0, i32 %1) {
%3 = icmp eq i32 %1, 0
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 (...) @get_processor_number_online()
br label %6
6: ; preds = %4, %2
%7 = phi i32 [ %1, %2 ], [ %5, %4 ]
%8 = icmp sgt i32 %7, 1
%9 = sitofp i32 %7 to double
br i1 %8, label %10, label %20
10: ; preds = %6
%11 = bitcast double* %0 to <2 x double>*
%12 = load <2 x double>, <2 x double>* %11
%13 = insertelement <2 x double> poison, double %9, i64 0
%14 = shufflevector <2 x double> %13, <2 x double> poison, <2 x i32> zeroinitializer
%15 = fdiv <2 x double> %12, %14
%16 = bitcast double* %0 to <2 x double>*
store <2 x double> %15, <2 x double>* %16
%17 = getelementptr inbounds double, double* %0, i64 2
%18 = load double, double* %17
%19 = fdiv double %18, %9
store double %19, double* %17
br label %20
20: ; preds = %6, %10
ret void
}