#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 int uint8_t;

/* Variables and functions */
int floor(float);
int read8(int, int);
int /*<<< orphan*/ write8(int, int, int);
int pwmFreq(int fh, float freq) {
  float prescaleval = 25000000;
  prescaleval /= 4096;
  prescaleval /= freq;
  prescaleval -= 1;
  uint8_t prescale = floor(prescaleval + 0.5);
  uint8_t oldmode = read8(fh, 0x0);
  uint8_t newmode = (oldmode & 0x7F) | 0x10;
  write8(fh, 0x0, newmode);
  write8(fh, 0xFE, prescale);
  write8(fh, 0x0, oldmode);
  write8(fh, 0x0, oldmode | 0xa1);
  return 1;
}


x86 assembly (clang, -O0):
<pwmFreq>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movss  %xmm0,-0x8(%rbp)
movss  0xec8(%rip),%xmm0
movss  %xmm0,-0xc(%rbp)
movss  -0xc(%rbp),%xmm0
movss  0xeb2(%rip),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0xc(%rbp)
movss  -0x8(%rbp),%xmm1
movss  -0xc(%rbp),%xmm0
divss  %xmm1,%xmm0
movss  %xmm0,-0xc(%rbp)
movss  -0xc(%rbp),%xmm0
movss  0xe85(%rip),%xmm1
subss  %xmm1,%xmm0
movss  %xmm0,-0xc(%rbp)
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe63(%rip),%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
call   1050 <floor@plt>
mov    %eax,-0x10(%rbp)
mov    -0x4(%rbp),%edi
xor    %esi,%esi
call   1030 <read8@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
and    $0x7f,%eax
or     $0x10,%eax
mov    %eax,-0x18(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x18(%rbp),%edx
xor    %esi,%esi
call   1040 <write8@plt>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%edx
mov    $0xfe,%esi
call   1040 <write8@plt>
mov    -0x4(%rbp),%edi
mov    -0x14(%rbp),%edx
xor    %esi,%esi
call   1040 <write8@plt>
mov    -0x4(%rbp),%edi
mov    -0x14(%rbp),%edx
or     $0xa1,%edx
xor    %esi,%esi
call   1040 <write8@plt>
mov    $0x1,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pwmFreq>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%ebx
movss  0xec2(%rip),%xmm1
divss  %xmm0,%xmm1
addss  0xeba(%rip),%xmm1
addss  0xeb6(%rip),%xmm1
movaps %xmm1,%xmm0
call   1050 <floor@plt>
mov    %eax,%r14d
mov    %ebx,%edi
xor    %esi,%esi
call   1030 <read8@plt>
mov    %eax,%ebp
mov    %eax,%edx
and    $0x6f,%edx
or     $0x10,%edx
mov    %ebx,%edi
xor    %esi,%esi
call   1040 <write8@plt>
mov    %ebx,%edi
mov    $0xfe,%esi
mov    %r14d,%edx
call   1040 <write8@plt>
mov    %ebx,%edi
xor    %esi,%esi
mov    %ebp,%edx
call   1040 <write8@plt>
or     $0xa1,%ebp
mov    %ebx,%edi
xor    %esi,%esi
mov    %ebp,%edx
call   1040 <write8@plt>
mov    $0x1,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @pwmFreq(i32 %0, float %1) {
%3 = alloca i32
%4 = alloca float
%5 = alloca float
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %3
store float %1, float* %4
store float 2.500000e+07, float* %5
%9 = load float, float* %5
%10 = fdiv float %9, 4.096000e+03
store float %10, float* %5
%11 = load float, float* %4
%12 = load float, float* %5
%13 = fdiv float %12, %11
store float %13, float* %5
%14 = load float, float* %5
%15 = fsub float %14, 1.000000e+00
store float %15, float* %5
%16 = load float, float* %5
%17 = fpext float %16 to double
%18 = fadd double %17, 5.000000e-01
%19 = fptrunc double %18 to float
%20 = call i32 @floor(float %19)
store i32 %20, i32* %6
%21 = load i32, i32* %3
%22 = call i32 @read8(i32 %21, i32 0)
store i32 %22, i32* %7
%23 = load i32, i32* %7
%24 = and i32 %23, 127
%25 = or i32 %24, 16
store i32 %25, i32* %8
%26 = load i32, i32* %3
%27 = load i32, i32* %8
%28 = call i32 @write8(i32 %26, i32 0, i32 %27)
%29 = load i32, i32* %3
%30 = load i32, i32* %6
%31 = call i32 @write8(i32 %29, i32 254, i32 %30)
%32 = load i32, i32* %3
%33 = load i32, i32* %7
%34 = call i32 @write8(i32 %32, i32 0, i32 %33)
%35 = load i32, i32* %3
%36 = load i32, i32* %7
%37 = or i32 %36, 161
%38 = call i32 @write8(i32 %35, i32 0, i32 %37)
ret i32 1
}

LLVM IR (-O2):
define i32 @pwmFreq(i32 %0, float %1) {
%3 = fdiv float 0x40B7D78400000000, %1
%4 = fadd float %3, -1.000000e+00
%5 = fadd float %4, 5.000000e-01
%6 = tail call i32 @floor(float %5)
%7 = tail call i32 @read8(i32 %0, i32 0)
%8 = and i32 %7, 111
%9 = or i32 %8, 16
%10 = tail call i32 @write8(i32 %0, i32 0, i32 %9)
%11 = tail call i32 @write8(i32 %0, i32 254, i32 %6)
%12 = tail call i32 @write8(i32 %0, i32 0, i32 %7)
%13 = or i32 %7, 161
%14 = tail call i32 @write8(i32 %0, i32 0, i32 %13)
ret i32 1
}