void spi_init(int slave, int fq, int bit_nb, int lsb, int tx_pol, int rx_pol) {
  int ctrl = 0;
  *((volatile unsigned long *)(0xb0000000 + 0x08)) = 50000000 / (fq * 2) - 1;
  ctrl = bit_nb << 3;
  ctrl |= lsb ? 0x00000100 : 0;
  ctrl |= tx_pol ? 0x00000004 : 0;
  ctrl |= rx_pol ? 0x00000002 : 0;
  *((volatile unsigned long *)(0xb0000000 + 0x04)) = ctrl;
  *((volatile unsigned long *)(0xb0000000 + 0x0c)) = 1 << slave;
}


x86 assembly (clang, -O0):
<spi_init>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
mov    %r8d,-0x14(%rbp)
mov    %r9d,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%ecx
shl    $0x1,%ecx
mov    $0x2faf080,%eax
cltd
idiv   %ecx
sub    $0x1,%eax
movslq %eax,%rcx
mov    $0xb0000008,%eax
mov    %rcx,(%rax)
mov    -0xc(%rbp),%eax
shl    $0x3,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%edx
xor    %eax,%eax
mov    $0x100,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
or     -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%edx
xor    %eax,%eax
mov    $0x4,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
or     -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%edx
xor    %eax,%eax
mov    $0x2,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
or     -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
movslq -0x1c(%rbp),%rcx
mov    $0xb0000004,%eax
mov    %rcx,(%rax)
mov    -0x4(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
movslq %eax,%rcx
mov    $0xb000000c,%eax
mov    %rcx,(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<spi_init>:
mov    %ecx,%eax
mov    %edx,%r10d
mov    %edi,%ecx
xor    %r11d,%r11d
test   %r9d,%r9d
setne  %r11b
xor    %r9d,%r9d
test   %r8d,%r8d
setne  %r9b
xor    %edi,%edi
test   %eax,%eax
setne  %dil
add    %esi,%esi
mov    $0x2faf080,%eax
xor    %edx,%edx
idiv   %esi
add    $0xffffffff,%eax
cltq
mov    $0xb0000004,%edx
mov    %rax,0x4(%rdx)
shl    $0x3,%r10d
shl    $0x8,%edi
or     %r10d,%edi
lea    (%rdi,%r9,4),%eax
lea    (%rax,%r11,2),%eax
mov    $0x1,%esi
shl    %cl,%esi
cltq
mov    %rax,(%rdx)
movslq %esi,%rax
mov    %rax,0x8(%rdx)
ret

LLVM IR (-O0):
define void @spi_init(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5) {
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i32 %0, i32* %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store i32 %3, i32* %10
store i32 %4, i32* %11
store i32 %5, i32* %12
store i32 0, i32* %13
%14 = load i32, i32* %8
%15 = mul nsw i32 %14, 2
%16 = sdiv i32 50000000, %15
%17 = sub nsw i32 %16, 1
%18 = sext i32 %17 to i64
store volatile i64 %18, i64* inttoptr (i64 2952790024 to i64*)
%19 = load i32, i32* %9
%20 = shl i32 %19, 3
store i32 %20, i32* %13
%21 = load i32, i32* %10
%22 = icmp ne i32 %21, 0
%23 = zext i1 %22 to i64
%24 = select i1 %22, i32 256, i32 0
%25 = load i32, i32* %13
%26 = or i32 %25, %24
store i32 %26, i32* %13
%27 = load i32, i32* %11
%28 = icmp ne i32 %27, 0
%29 = zext i1 %28 to i64
%30 = select i1 %28, i32 4, i32 0
%31 = load i32, i32* %13
%32 = or i32 %31, %30
store i32 %32, i32* %13
%33 = load i32, i32* %12
%34 = icmp ne i32 %33, 0
%35 = zext i1 %34 to i64
%36 = select i1 %34, i32 2, i32 0
%37 = load i32, i32* %13
%38 = or i32 %37, %36
store i32 %38, i32* %13
%39 = load i32, i32* %13
%40 = sext i32 %39 to i64
store volatile i64 %40, i64* inttoptr (i64 2952790020 to i64*)
%41 = load i32, i32* %7
%42 = shl i32 1, %41
%43 = sext i32 %42 to i64
store volatile i64 %43, i64* inttoptr (i64 2952790028 to i64*)
ret void
}

LLVM IR (-O2):
define void @spi_init(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5) {
%7 = shl nsw i32 %1, 1
%8 = sdiv i32 50000000, %7
%9 = add nsw i32 %8, -1
%10 = sext i32 %9 to i64
store volatile i64 %10, i64* inttoptr (i64 2952790024 to i64*)
%11 = shl i32 %2, 3
%12 = icmp eq i32 %3, 0
%13 = select i1 %12, i32 0, i32 256
%14 = or i32 %13, %11
%15 = icmp eq i32 %4, 0
%16 = select i1 %15, i32 0, i32 4
%17 = or i32 %14, %16
%18 = icmp eq i32 %5, 0
%19 = select i1 %18, i32 0, i32 2
%20 = or i32 %17, %19
%21 = sext i32 %20 to i64
store volatile i64 %21, i64* inttoptr (i64 2952790020 to i64*)
%22 = shl nuw i32 1, %0
%23 = sext i32 %22 to i64
store volatile i64 %23, i64* inttoptr (i64 2952790028 to i64*)
ret void
}