#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 char reg_read_8(void *);
int /*<<< orphan*/ reg_write_8(unsigned char, void *);
void ls1c_spi_set_cs(void *spi_base, unsigned char cs, int new_status) {
  unsigned char val = 0;
  val = reg_read_8(spi_base + (5));
  val |= 0x01 << cs;
  if (new_status) {
    val |= (0x10 << cs);
  } else {
    val &= ~(0x10 << cs);
  }
  reg_write_8(val, spi_base + (5));
  return;
}


x86 assembly (clang, -O0):
<ls1c_spi_set_cs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    %edx,-0x10(%rbp)
movb   $0x0,-0x11(%rbp)
mov    -0x8(%rbp),%rdi
add    $0x5,%rdi
call   1030 <reg_read_8@plt>
mov    %al,-0x11(%rbp)
movzbl -0x9(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
mov    %eax,%ecx
movzbl -0x11(%rbp),%eax
or     %ecx,%eax
mov    %al,-0x11(%rbp)
cmpl   $0x0,-0x10(%rbp)
je     1184 <ls1c_spi_set_cs+0x64>
movzbl -0x9(%rbp),%ecx
mov    $0x10,%eax
shl    %cl,%eax
mov    %eax,%ecx
movzbl -0x11(%rbp),%eax
or     %ecx,%eax
mov    %al,-0x11(%rbp)
jmp    119d <ls1c_spi_set_cs+0x7d>
movzbl -0x9(%rbp),%ecx
mov    $0x10,%eax
shl    %cl,%eax
mov    %eax,%ecx
xor    $0xffffffff,%ecx
movzbl -0x11(%rbp),%eax
and    %ecx,%eax
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
mov    -0x8(%rbp),%rsi
add    $0x5,%rsi
movzbl %al,%edi
call   1040 <reg_write_8@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ls1c_spi_set_cs>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%r14d
mov    %esi,%ebp
lea    0x5(%rdi),%rbx
mov    %rbx,%rdi
call   1030 <reg_read_8@plt>
mov    $0x1,%edx
mov    %ebp,%ecx
shl    %cl,%edx
or     %al,%dl
mov    $0x10,%eax
shl    %cl,%eax
mov    %edx,%ecx
or     %al,%cl
not    %al
and    %dl,%al
test   %r14d,%r14d
movzbl %al,%eax
movzbl %cl,%ecx
cmove  %eax,%ecx
movzbl %cl,%edi
mov    %rbx,%rsi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <reg_write_8@plt>

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

LLVM IR (-O2):
define void @ls1c_spi_set_cs(i8* %0, i8 zeroext %1, i32 %2) {
%4 = getelementptr i8, i8* %0, i64 5
%5 = tail call zeroext i8 @reg_read_8(i8* %4)
%6 = zext i8 %1 to i32
%7 = shl nuw i32 1, %6
%8 = trunc i32 %7 to i8
%9 = or i8 %5, %8
%10 = icmp eq i32 %2, 0
%11 = shl i32 16, %6
%12 = trunc i32 %11 to i8
%13 = or i8 %9, %12
%14 = xor i8 %12, -1
%15 = and i8 %9, %14
%16 = select i1 %10, i8 %15, i8 %13
%17 = tail call i32 @reg_write_8(i8 zeroext %16, i8* %4)
ret void
}