#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 uint32_t;

/* Variables and functions */
void mio_set_clkdiv(volatile uint32_t *regs, uint32_t clkdiv) {
  uint32_t rise0, fall0, rise1, fall1;
  uint32_t clkphase;
  if (clkdiv > 254)
    clkdiv = 254;
  rise0 = 0;
  fall0 = 0xff & ((clkdiv + 1) >> 1);
  rise1 = 0xff & ((clkdiv + 1) >> 2);
  fall1 = 0xff & (((clkdiv + 1) >> 2) + ((clkdiv + 1) >> 1));
  regs[2] = clkdiv;
  regs[3] = fall1 << 24 | rise1 << 16 | fall0 << 8 | rise0 << 0;
}


x86 assembly (clang, -O0):
<mio_set_clkdiv>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0xfe,-0xc(%rbp)
jle    111f <mio_set_clkdiv+0x1f>
movl   $0xfe,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
sar    $0x1,%eax
and    $0xff,%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
sar    $0x2,%eax
and    $0xff,%eax
mov    %eax,-0x18(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
sar    $0x2,%eax
mov    -0xc(%rbp),%ecx
add    $0x1,%ecx
sar    $0x1,%ecx
add    %ecx,%eax
and    $0xff,%eax
mov    %eax,-0x1c(%rbp)
mov    -0xc(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    -0x1c(%rbp),%ecx
shl    $0x18,%ecx
mov    -0x18(%rbp),%eax
shl    $0x10,%eax
or     %eax,%ecx
mov    -0x14(%rbp),%eax
shl    $0x8,%eax
or     %eax,%ecx
mov    -0x10(%rbp),%eax
shl    $0x0,%eax
or     %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0xc(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<mio_set_clkdiv>:
cmp    $0xfe,%esi
mov    $0xfe,%eax
cmovl  %esi,%eax
lea    0x1(%rax),%ecx
mov    %ecx,%edx
sar    %edx
sar    $0x2,%ecx
lea    (%rcx,%rdx,1),%esi
mov    %eax,0x8(%rdi)
shl    $0x18,%esi
movzbl %cl,%eax
shl    $0x10,%eax
or     %esi,%eax
shl    $0x8,%edx
movzwl %dx,%ecx
or     %eax,%ecx
mov    %ecx,0xc(%rdi)
ret

LLVM IR (-O0):
define void @mio_set_clkdiv(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
%10 = load i32, i32* %4
%11 = icmp sgt i32 %10, 254
br i1 %11, label %12, label %13
12: ; preds = %2
store i32 254, i32* %4
br label %13
13: ; preds = %12, %2
store i32 0, i32* %5
%14 = load i32, i32* %4
%15 = add nsw i32 %14, 1
%16 = ashr i32 %15, 1
%17 = and i32 255, %16
store i32 %17, i32* %6
%18 = load i32, i32* %4
%19 = add nsw i32 %18, 1
%20 = ashr i32 %19, 2
%21 = and i32 255, %20
store i32 %21, i32* %7
%22 = load i32, i32* %4
%23 = add nsw i32 %22, 1
%24 = ashr i32 %23, 2
%25 = load i32, i32* %4
%26 = add nsw i32 %25, 1
%27 = ashr i32 %26, 1
%28 = add nsw i32 %24, %27
%29 = and i32 255, %28
store i32 %29, i32* %8
%30 = load i32, i32* %4
%31 = load i32*, i32** %3
%32 = getelementptr inbounds i32, i32* %31, i64 2
store volatile i32 %30, i32* %32
%33 = load i32, i32* %8
%34 = shl i32 %33, 24
%35 = load i32, i32* %7
%36 = shl i32 %35, 16
%37 = or i32 %34, %36
%38 = load i32, i32* %6
%39 = shl i32 %38, 8
%40 = or i32 %37, %39
%41 = load i32, i32* %5
%42 = shl i32 %41, 0
%43 = or i32 %40, %42
%44 = load i32*, i32** %3
%45 = getelementptr inbounds i32, i32* %44, i64 3
store volatile i32 %43, i32* %45
ret void
}

LLVM IR (-O2):
define void @mio_set_clkdiv(i32* %0, i32 %1) {
%3 = icmp slt i32 %1, 254
%4 = select i1 %3, i32 %1, i32 254
%5 = add nsw i32 %4, 1
%6 = ashr i32 %5, 1
%7 = ashr i32 %5, 2
%8 = add nsw i32 %7, %6
%9 = getelementptr inbounds i32, i32* %0, i64 2
store volatile i32 %4, i32* %9
%10 = shl i32 %8, 24
%11 = shl i32 %7, 16
%12 = and i32 %11, 16711680
%13 = or i32 %10, %12
%14 = shl i32 %6, 8
%15 = and i32 %14, 65280
%16 = or i32 %13, %15
%17 = getelementptr inbounds i32, i32* %0, i64 3
store volatile i32 %16, i32* %17
ret void
}