#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 */
int /*<<< orphan*/ printf(char *);
unsigned char reg_read_8(void *);
int /*<<< orphan*/ reg_write_8(unsigned char, void *);
void ls1c_spi_clear(void *spi_base) {
  unsigned char val = 0;
  val = reg_read_8(spi_base + (1));
  val |= (0x01 << (7));
  reg_write_8(val, spi_base + (1));
  val = reg_read_8(spi_base + (1));
  if ((0x01 << (6)) & val) {
    printf("[%s] clear register SPSR's wcol!\r\n");
    reg_write_8(val & ~(0x01 << (6)), spi_base + (1));
  }
  return;
}


x86 assembly (clang, -O0):
<ls1c_spi_clear>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movb   $0x0,-0x9(%rbp)
mov    -0x8(%rbp),%rdi
add    $0x1,%rdi
call   1040 <reg_read_8@plt>
mov    %al,-0x9(%rbp)
movzbl -0x9(%rbp),%eax
or     $0x80,%eax
mov    %al,-0x9(%rbp)
mov    -0x9(%rbp),%al
mov    -0x8(%rbp),%rsi
add    $0x1,%rsi
movzbl %al,%edi
call   1050 <reg_write_8@plt>
mov    -0x8(%rbp),%rdi
add    $0x1,%rdi
call   1040 <reg_read_8@plt>
mov    %al,-0x9(%rbp)
movzbl -0x9(%rbp),%eax
and    $0x40,%eax
cmp    $0x0,%eax
je     11b2 <ls1c_spi_clear+0x82>
lea    0xe6a(%rip),%rdi
call   1030 <printf@plt>
movzbl -0x9(%rbp),%eax
and    $0xffffffbf,%eax
mov    -0x8(%rbp),%rsi
add    $0x1,%rsi
movzbl %al,%edi
call   1050 <reg_write_8@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ls1c_spi_clear>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
add    $0x1,%rbx
mov    %rbx,%rdi
call   1040 <reg_read_8@plt>
or     $0x80,%al
movzbl %al,%edi
mov    %rbx,%rsi
call   1050 <reg_write_8@plt>
mov    %rbx,%rdi
call   1040 <reg_read_8@plt>
test   $0x40,%al
jne    1162 <ls1c_spi_clear+0x32>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    %eax,%ebp
lea    0xe95(%rip),%rdi
call   1030 <printf@plt>
and    $0xbf,%bpl
movzbl %bpl,%edi
mov    %rbx,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1050 <reg_write_8@plt>

LLVM IR (-O0):
@.str = [35 x i8] c"[%s] clear register SPSR's wcol!\0D\0A\00"
define void @ls1c_spi_clear(i8* %0) {
%2 = alloca i8*
%3 = alloca i8
store i8* %0, i8** %2
store i8 0, i8* %3
%4 = load i8*, i8** %2
%5 = getelementptr i8, i8* %4, i64 1
%6 = call zeroext i8 @reg_read_8(i8* %5)
store i8 %6, i8* %3
%7 = load i8, i8* %3
%8 = zext i8 %7 to i32
%9 = or i32 %8, 128
%10 = trunc i32 %9 to i8
store i8 %10, i8* %3
%11 = load i8, i8* %3
%12 = load i8*, i8** %2
%13 = getelementptr i8, i8* %12, i64 1
%14 = call i32 @reg_write_8(i8 zeroext %11, i8* %13)
%15 = load i8*, i8** %2
%16 = getelementptr i8, i8* %15, i64 1
%17 = call zeroext i8 @reg_read_8(i8* %16)
store i8 %17, i8* %3
%18 = load i8, i8* %3
%19 = zext i8 %18 to i32
%20 = and i32 64, %19
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %31
22: ; preds = %1
%23 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
%24 = load i8, i8* %3
%25 = zext i8 %24 to i32
%26 = and i32 %25, -65
%27 = trunc i32 %26 to i8
%28 = load i8*, i8** %2
%29 = getelementptr i8, i8* %28, i64 1
%30 = call i32 @reg_write_8(i8 zeroext %27, i8* %29)
br label %31
31: ; preds = %22, %1
ret void
}

LLVM IR (-O2):
@.str = [35 x i8] c"[%s] clear register SPSR's wcol!\0D\0A\00"
define void @ls1c_spi_clear(i8* %0) {
%2 = getelementptr i8, i8* %0, i64 1
%3 = tail call zeroext i8 @reg_read_8(i8* %2)
%4 = or i8 %3, -128
%5 = tail call i32 @reg_write_8(i8 zeroext %4, i8* %2)
%6 = tail call zeroext i8 @reg_read_8(i8* %2)
%7 = and i8 %6, 64
%8 = icmp eq i8 %7, 0
br i1 %8, label %13, label %9
9: ; preds = %1
%10 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
%11 = and i8 %6, -65
%12 = tail call i32 @reg_write_8(i8 zeroext %11, i8* %2)
br label %13
13: ; preds = %9, %1
ret void
}