#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 /*<<< orphan*/ uint8_t;
typedef int uint32_t;

/* Variables and functions */
void pwm_config_timer(uint8_t *instance, uint32_t resolution,
                      float duty_cycle) {
  uint32_t counter_start = 0xffffffff - resolution;
  uint32_t dc = 0xffffffff - ((uint32_t)(resolution * duty_cycle));
  if (0xffffffff - dc <= 2) {
    dc = 0xffffffff - 2;
  }
  if (0xffffffff - counter_start <= 2) {
    counter_start = 0xffffffff - 2;
  }
  *((volatile uint32_t *)(instance + 0x024)) = 0;
  *((volatile uint32_t *)(instance + 0x028)) = counter_start;
  *((volatile uint32_t *)(instance + 0x02c)) = counter_start;
  *((volatile uint32_t *)(instance + 0x038)) = dc;
  *((volatile uint32_t *)(instance + 0x024)) =
      ((1 << 0) | (1 << 1) | (1 << 6) | (1 << 7) | (2 << 10) | (1 << 12));
}


x86 assembly (clang, -O0):
<pwm_config_timer>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movss  %xmm0,-0x10(%rbp)
mov    $0xffffffff,%eax
sub    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
cvtsi2ssl -0xc(%rbp),%xmm0
mulss  -0x10(%rbp),%xmm0
cvttss2si %xmm0,%ecx
mov    $0xffffffff,%eax
sub    %ecx,%eax
mov    %eax,-0x18(%rbp)
mov    $0xffffffff,%eax
sub    -0x18(%rbp),%eax
cmp    $0x2,%eax
ja     114b <pwm_config_timer+0x4b>
movl   $0xfffffffd,-0x18(%rbp)
mov    $0xffffffff,%eax
sub    -0x14(%rbp),%eax
cmp    $0x2,%eax
ja     1163 <pwm_config_timer+0x63>
movl   $0xfffffffd,-0x14(%rbp)
mov    -0x8(%rbp),%rax
movl   $0x0,0x90(%rax)
mov    -0x14(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0xa0(%rax)
mov    -0x14(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0xb0(%rax)
mov    -0x18(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0xe0(%rax)
mov    -0x8(%rbp),%rax
movl   $0x18c3,0x90(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<pwm_config_timer>:
cvtsi2ss %esi,%xmm1
mulss  %xmm0,%xmm1
cvttss2si %xmm1,%eax
cmp    $0x3,%eax
not    %eax
mov    $0xfffffffd,%ecx
cmovb  %ecx,%eax
cmp    $0x3,%esi
not    %esi
cmovb  %ecx,%esi
movl   $0x0,0x90(%rdi)
mov    %esi,0xa0(%rdi)
mov    %esi,0xb0(%rdi)
mov    %eax,0xe0(%rdi)
movl   $0x18c3,0x90(%rdi)
ret

LLVM IR (-O0):
define void @pwm_config_timer(i32* %0, i32 %1, float %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca float
%7 = alloca i32
%8 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
store float %2, float* %6
%9 = load i32, i32* %5
%10 = sub i32 -1, %9
store i32 %10, i32* %7
%11 = load i32, i32* %5
%12 = sitofp i32 %11 to float
%13 = load float, float* %6
%14 = fmul float %12, %13
%15 = fptosi float %14 to i32
%16 = sub i32 -1, %15
store i32 %16, i32* %8
%17 = load i32, i32* %8
%18 = sub i32 -1, %17
%19 = icmp ule i32 %18, 2
br i1 %19, label %20, label %21
20: ; preds = %3
store i32 -3, i32* %8
br label %21
21: ; preds = %20, %3
%22 = load i32, i32* %7
%23 = sub i32 -1, %22
%24 = icmp ule i32 %23, 2
br i1 %24, label %25, label %26
25: ; preds = %21
store i32 -3, i32* %7
br label %26
26: ; preds = %25, %21
%27 = load i32*, i32** %4
%28 = getelementptr inbounds i32, i32* %27, i64 36
store volatile i32 0, i32* %28
%29 = load i32, i32* %7
%30 = load i32*, i32** %4
%31 = getelementptr inbounds i32, i32* %30, i64 40
store volatile i32 %29, i32* %31
%32 = load i32, i32* %7
%33 = load i32*, i32** %4
%34 = getelementptr inbounds i32, i32* %33, i64 44
store volatile i32 %32, i32* %34
%35 = load i32, i32* %8
%36 = load i32*, i32** %4
%37 = getelementptr inbounds i32, i32* %36, i64 56
store volatile i32 %35, i32* %37
%38 = load i32*, i32** %4
%39 = getelementptr inbounds i32, i32* %38, i64 36
store volatile i32 6339, i32* %39
ret void
}

LLVM IR (-O2):
define void @pwm_config_timer(i32* %0, i32 %1, float %2) {
%4 = xor i32 %1, -1
%5 = sitofp i32 %1 to float
%6 = fmul float %5, %2
%7 = fptosi float %6 to i32
%8 = xor i32 %7, -1
%9 = icmp ult i32 %7, 3
%10 = select i1 %9, i32 -3, i32 %8
%11 = icmp ult i32 %1, 3
%12 = select i1 %11, i32 -3, i32 %4
%13 = getelementptr inbounds i32, i32* %0, i64 36
store volatile i32 0, i32* %13
%14 = getelementptr inbounds i32, i32* %0, i64 40
store volatile i32 %12, i32* %14
%15 = getelementptr inbounds i32, i32* %0, i64 44
store volatile i32 %12, i32* %15
%16 = getelementptr inbounds i32, i32* %0, i64 56
store volatile i32 %10, i32* %16
store volatile i32 6339, i32* %13
ret void
}