#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 */
unsigned int ls1c_spi_get_div(unsigned long);
unsigned char reg_read_8(void *);
int /*<<< orphan*/ reg_write_8(unsigned char, void *);
void ls1c_spi_set_clock(void *spi_base, unsigned long max_hz) {
  unsigned int div = 0;
  unsigned char val = 0;
  div = ls1c_spi_get_div(max_hz);
  val = reg_read_8(spi_base + (0));
  val &= (~(0x03 << (0)));
  val |= (div & (0x03 << (0)));
  reg_write_8(val, spi_base + (0));
  val = reg_read_8(spi_base + (3));
  val &= (~(0x3 << (0)));
  val |= ((div >> 2) & (0x3 << (0)));
  reg_write_8(val, spi_base + (3));
  return;
}


x86 assembly (clang, -O0):
<ls1c_spi_set_clock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movb   $0x0,-0x15(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <ls1c_spi_get_div@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <reg_read_8@plt>
mov    %al,-0x15(%rbp)
movzbl -0x15(%rbp),%eax
and    $0xfffffffc,%eax
mov    %al,-0x15(%rbp)
mov    -0x14(%rbp),%ecx
and    $0x3,%ecx
movzbl -0x15(%rbp),%eax
or     %ecx,%eax
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
mov    -0x8(%rbp),%rsi
movzbl %al,%edi
call   1050 <reg_write_8@plt>
mov    -0x8(%rbp),%rdi
add    $0x3,%rdi
call   1040 <reg_read_8@plt>
mov    %al,-0x15(%rbp)
movzbl -0x15(%rbp),%eax
and    $0xfffffffc,%eax
mov    %al,-0x15(%rbp)
mov    -0x14(%rbp),%ecx
shr    $0x2,%ecx
and    $0x3,%ecx
movzbl -0x15(%rbp),%eax
or     %ecx,%eax
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
mov    -0x8(%rbp),%rsi
add    $0x3,%rsi
movzbl %al,%edi
call   1050 <reg_write_8@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ls1c_spi_set_clock>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    %rsi,%rdi
call   1030 <ls1c_spi_get_div@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1040 <reg_read_8@plt>
and    $0xfc,%al
mov    %ebp,%ecx
and    $0x3,%cl
or     %al,%cl
movzbl %cl,%edi
mov    %rbx,%rsi
call   1050 <reg_write_8@plt>
add    $0x3,%rbx
mov    %rbx,%rdi
call   1040 <reg_read_8@plt>
and    $0xfc,%al
shr    $0x2,%bpl
and    $0x3,%bpl
or     %al,%bpl
movzbl %bpl,%edi
mov    %rbx,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1050 <reg_write_8@plt>

LLVM IR (-O0):
define void @ls1c_spi_set_clock(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
%6 = alloca i8
store i8* %0, i8** %3
store i64 %1, i64* %4
store i32 0, i32* %5
store i8 0, i8* %6
%7 = load i64, i64* %4
%8 = call i32 @ls1c_spi_get_div(i64 %7)
store i32 %8, i32* %5
%9 = load i8*, i8** %3
%10 = getelementptr i8, i8* %9, i64 0
%11 = call zeroext i8 @reg_read_8(i8* %10)
store i8 %11, i8* %6
%12 = load i8, i8* %6
%13 = zext i8 %12 to i32
%14 = and i32 %13, -4
%15 = trunc i32 %14 to i8
store i8 %15, i8* %6
%16 = load i32, i32* %5
%17 = and i32 %16, 3
%18 = load i8, i8* %6
%19 = zext i8 %18 to i32
%20 = or i32 %19, %17
%21 = trunc i32 %20 to i8
store i8 %21, i8* %6
%22 = load i8, i8* %6
%23 = load i8*, i8** %3
%24 = getelementptr i8, i8* %23, i64 0
%25 = call i32 @reg_write_8(i8 zeroext %22, i8* %24)
%26 = load i8*, i8** %3
%27 = getelementptr i8, i8* %26, i64 3
%28 = call zeroext i8 @reg_read_8(i8* %27)
store i8 %28, i8* %6
%29 = load i8, i8* %6
%30 = zext i8 %29 to i32
%31 = and i32 %30, -4
%32 = trunc i32 %31 to i8
store i8 %32, i8* %6
%33 = load i32, i32* %5
%34 = lshr i32 %33, 2
%35 = and i32 %34, 3
%36 = load i8, i8* %6
%37 = zext i8 %36 to i32
%38 = or i32 %37, %35
%39 = trunc i32 %38 to i8
store i8 %39, i8* %6
%40 = load i8, i8* %6
%41 = load i8*, i8** %3
%42 = getelementptr i8, i8* %41, i64 3
%43 = call i32 @reg_write_8(i8 zeroext %40, i8* %42)
ret void
}

LLVM IR (-O2):
define void @ls1c_spi_set_clock(i8* %0, i64 %1) {
%3 = tail call i32 @ls1c_spi_get_div(i64 %1)
%4 = tail call zeroext i8 @reg_read_8(i8* %0)
%5 = and i8 %4, -4
%6 = trunc i32 %3 to i8
%7 = and i8 %6, 3
%8 = or i8 %7, %5
%9 = tail call i32 @reg_write_8(i8 zeroext %8, i8* %0)
%10 = getelementptr i8, i8* %0, i64 3
%11 = tail call zeroext i8 @reg_read_8(i8* %10)
%12 = and i8 %11, -4
%13 = lshr i8 %6, 2
%14 = and i8 %13, 3
%15 = or i8 %12, %14
%16 = tail call i32 @reg_write_8(i8 zeroext %15, i8* %10)
ret void
}