#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 /*<<< orphan*/ printf(char *, ...);
int read_ec(int);
void dump_fan_config(void) {
  printf("Dump FAN\n");
  int raw_duty = read_ec(0xCE);
  int val_duty = (int)((double)raw_duty / 255.0 * 100.0);
  int raw_rpm = (read_ec(0xD0) << 8) + (read_ec(0xD1));
  int val_rpm;
  if (raw_rpm == 0)
    val_rpm = 0;
  else
    val_rpm = 2156220 / raw_rpm;
  printf("FAN Duty: %d%%\n", val_duty);
  printf("FAN RPMs: %d RPM\n", val_rpm);
  printf("CPU Temp: %d°C\n", read_ec(0x07));
}


x86 assembly (clang, -O0):
<dump_fan_config>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xee1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0xce,%edi
call   1040 <read_ec@plt>
mov    %eax,-0x4(%rbp)
cvtsi2sdl -0x4(%rbp),%xmm0
movsd  0xeb8(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  0xea4(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x8(%rbp)
mov    $0xd0,%edi
call   1040 <read_ec@plt>
shl    $0x8,%eax
mov    %eax,-0x14(%rbp)
mov    $0xd1,%edi
call   1040 <read_ec@plt>
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    11a1 <dump_fan_config+0x81>
movl   $0x0,-0x10(%rbp)
jmp    11ad <dump_fan_config+0x8d>
mov    $0x20e6bc,%eax
cltd
idivl  -0xc(%rbp)
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%esi
lea    0xe63(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%esi
lea    0xe62(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x7,%edi
call   1040 <read_ec@plt>
mov    %eax,%esi
lea    0xe5a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_fan_config>:
push   %rbp
push   %rbx
push   %rax
lea    0xf09(%rip),%rdi
call   1030 <puts@plt>
mov    $0xce,%edi
call   1050 <read_ec@plt>
mov    %eax,%ebx
mov    $0xd0,%edi
call   1050 <read_ec@plt>
mov    %eax,%ebp
shl    $0x8,%ebp
mov    $0xd1,%edi
call   1050 <read_ec@plt>
mov    %eax,%ecx
add    %ebp,%ecx
je     1177 <dump_fan_config+0x47>
mov    $0x20e6bc,%eax
xor    %edx,%edx
idiv   %ecx
mov    %eax,%ebp
jmp    1179 <dump_fan_config+0x49>
xor    %ebp,%ebp
cvtsi2sd %ebx,%xmm0
divsd  0xe7b(%rip),%xmm0
mulsd  0xe7b(%rip),%xmm0
cvttsd2si %xmm0,%esi
lea    0xe78(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe7a(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x7,%edi
call   1050 <read_ec@plt>
lea    0xe72(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <printf@plt>

LLVM IR (-O0):
@.str = [10 x i8] c"Dump FAN\0A\00"
@.str.1 = [16 x i8] c"FAN Duty: %d%%\0A\00"
@.str.2 = [18 x i8] c"FAN RPMs: %d RPM\0A\00"
@.str.3 = [17 x i8] c"CPU Temp: %d\C2\B0C\0A\00"
define void @dump_fan_config() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @read_ec(i32 206)
store i32 %6, i32* %1
%7 = load i32, i32* %1
%8 = sitofp i32 %7 to double
%9 = fdiv double %8, 2.550000e+02
%10 = fmul double %9, 1.000000e+02
%11 = fptosi double %10 to i32
store i32 %11, i32* %2
%12 = call i32 @read_ec(i32 208)
%13 = shl i32 %12, 8
%14 = call i32 @read_ec(i32 209)
%15 = add nsw i32 %13, %14
store i32 %15, i32* %3
%16 = load i32, i32* %3
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %0
store i32 0, i32* %4
br label %22
19: ; preds = %0
%20 = load i32, i32* %3
%21 = sdiv i32 2156220, %20
store i32 %21, i32* %4
br label %22
22: ; preds = %19, %18
%23 = load i32, i32* %2
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %23)
%25 = load i32, i32* %4
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %25)
%27 = call i32 @read_ec(i32 7)
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i32 %27)
ret void
}

LLVM IR (-O2):
@.str.1 = [16 x i8] c"FAN Duty: %d%%\0A\00"
@.str.2 = [18 x i8] c"FAN RPMs: %d RPM\0A\00"
@.str.3 = [17 x i8] c"CPU Temp: %d\C2\B0C\0A\00"
@str = [9 x i8] c"Dump FAN\00"
define void @dump_fan_config() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str, i64 0, i64 0))
%2 = tail call i32 @read_ec(i32 206)
%3 = tail call i32 @read_ec(i32 208)
%4 = shl i32 %3, 8
%5 = tail call i32 @read_ec(i32 209)
%6 = add nsw i32 %4, %5
%7 = icmp eq i32 %6, 0
br i1 %7, label %10, label %8
8: ; preds = %0
%9 = sdiv i32 2156220, %6
br label %10
10: ; preds = %0, %8
%11 = phi i32 [ %9, %8 ], [ 0, %0 ]
%12 = sitofp i32 %2 to double
%13 = fdiv double %12, 2.550000e+02
%14 = fmul double %13, 1.000000e+02
%15 = fptosi double %14 to i32
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %15)
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %11)
%18 = tail call i32 @read_ec(i32 7)
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i32 %18)
ret void
}