#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*/ AccWit(int);
int /*<<< orphan*/ ClrGyr(int, int);
int /*<<< orphan*/ GyOutSignal();
int /*<<< orphan*/ RegReadA(int, unsigned char *);
int /*<<< orphan*/ RegWriteA(int, int);
int /*<<< orphan*/ WitTim(int);
void SelectGySleep(unsigned char UcSelMode) {
  unsigned char UcRamIni;
  unsigned char UcGrini;
  if (UcSelMode == 0x01) {
    RegWriteA(0x0101, 0x00);
    RegWriteA(0x0280, 0x01);
    RegReadA(0x0281, &UcGrini);
    RegWriteA(0x0281, (UcGrini | 0x04));
    RegWriteA(0x0283, 0x6B);
    RegWriteA(0x0282, 0x01);
    AccWit(0x01);
    RegReadA(0x0290, &UcRamIni);
    UcRamIni |= 0x40;
    RegWriteA(0x0283, 0x6B);
    RegWriteA(0x028A, UcRamIni);
    RegWriteA(0x0282, 0x10);
    AccWit(0x10);
  } else {
    RegWriteA(0x0283, 0x6B);
    RegWriteA(0x0282, 0x01);
    AccWit(0x01);
    RegReadA(0x0290, &UcRamIni);
    UcRamIni &= ~0x40;
    RegWriteA(0x028A, UcRamIni);
    RegWriteA(0x0282, 0x10);
    AccWit(0x10);
    RegReadA(0x0281, &UcGrini);
    RegWriteA(0x0281, (UcGrini & ~0x04));
    GyOutSignal();
    WitTim(50);
    RegWriteA(0x0101, 0x01);
    ClrGyr(0x007F, 0x02);
  }
}


x86 assembly (clang, -O0):
<SelectGySleep>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
movzbl -0x1(%rbp),%eax
cmp    $0x1,%eax
jne    1230 <SelectGySleep+0xd0>
mov    $0x101,%edi
xor    %esi,%esi
call   1070 <RegWriteA@plt>
mov    $0x280,%edi
mov    $0x1,%esi
call   1070 <RegWriteA@plt>
mov    $0x281,%edi
lea    -0x3(%rbp),%rsi
call   1060 <RegReadA@plt>
movzbl -0x3(%rbp),%esi
or     $0x4,%esi
mov    $0x281,%edi
call   1070 <RegWriteA@plt>
mov    $0x283,%edi
mov    $0x6b,%esi
call   1070 <RegWriteA@plt>
mov    $0x282,%edi
mov    $0x1,%esi
call   1070 <RegWriteA@plt>
mov    $0x1,%edi
call   1030 <AccWit@plt>
mov    $0x290,%edi
lea    -0x2(%rbp),%rsi
call   1060 <RegReadA@plt>
movzbl -0x2(%rbp),%eax
or     $0x40,%eax
mov    %al,-0x2(%rbp)
mov    $0x283,%edi
mov    $0x6b,%esi
call   1070 <RegWriteA@plt>
movzbl -0x2(%rbp),%esi
mov    $0x28a,%edi
call   1070 <RegWriteA@plt>
mov    $0x282,%edi
mov    $0x10,%esi
call   1070 <RegWriteA@plt>
mov    $0x10,%edi
call   1030 <AccWit@plt>
jmp    12e5 <SelectGySleep+0x185>
mov    $0x283,%edi
mov    $0x6b,%esi
call   1070 <RegWriteA@plt>
mov    $0x282,%edi
mov    $0x1,%esi
call   1070 <RegWriteA@plt>
mov    $0x1,%edi
call   1030 <AccWit@plt>
mov    $0x290,%edi
lea    -0x2(%rbp),%rsi
call   1060 <RegReadA@plt>
movzbl -0x2(%rbp),%eax
and    $0xffffffbf,%eax
mov    %al,-0x2(%rbp)
movzbl -0x2(%rbp),%esi
mov    $0x28a,%edi
call   1070 <RegWriteA@plt>
mov    $0x282,%edi
mov    $0x10,%esi
call   1070 <RegWriteA@plt>
mov    $0x10,%edi
call   1030 <AccWit@plt>
mov    $0x281,%edi
lea    -0x3(%rbp),%rsi
call   1060 <RegReadA@plt>
movzbl -0x3(%rbp),%esi
and    $0xfffffffb,%esi
mov    $0x281,%edi
call   1070 <RegWriteA@plt>
mov    $0x0,%al
call   1080 <GyOutSignal@plt>
mov    $0x32,%edi
call   1050 <WitTim@plt>
mov    $0x101,%edi
mov    $0x1,%esi
call   1070 <RegWriteA@plt>
mov    $0x7f,%edi
mov    $0x2,%esi
call   1040 <ClrGyr@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SelectGySleep>:
push   %rax
cmp    $0x1,%dil
jne    121c <SelectGySleep+0xbc>
mov    $0x101,%edi
xor    %esi,%esi
call   1070 <RegWriteA@plt>
mov    $0x280,%edi
mov    $0x1,%esi
call   1070 <RegWriteA@plt>
lea    0x7(%rsp),%rsi
mov    $0x281,%edi
call   1060 <RegReadA@plt>
movzbl 0x7(%rsp),%esi
or     $0x4,%esi
mov    $0x281,%edi
call   1070 <RegWriteA@plt>
mov    $0x283,%edi
mov    $0x6b,%esi
call   1070 <RegWriteA@plt>
mov    $0x282,%edi
mov    $0x1,%esi
call   1070 <RegWriteA@plt>
mov    $0x1,%edi
call   1030 <AccWit@plt>
lea    0x6(%rsp),%rsi
mov    $0x290,%edi
call   1060 <RegReadA@plt>
orb    $0x40,0x6(%rsp)
mov    $0x283,%edi
mov    $0x6b,%esi
call   1070 <RegWriteA@plt>
movzbl 0x6(%rsp),%esi
mov    $0x28a,%edi
call   1070 <RegWriteA@plt>
mov    $0x282,%edi
mov    $0x10,%esi
call   1070 <RegWriteA@plt>
mov    $0x10,%edi
call   1030 <AccWit@plt>
pop    %rax
ret
mov    $0x283,%edi
mov    $0x6b,%esi
call   1070 <RegWriteA@plt>
mov    $0x282,%edi
mov    $0x1,%esi
call   1070 <RegWriteA@plt>
mov    $0x1,%edi
call   1030 <AccWit@plt>
lea    0x6(%rsp),%rsi
mov    $0x290,%edi
call   1060 <RegReadA@plt>
movzbl 0x6(%rsp),%esi
and    $0xffffffbf,%esi
mov    %sil,0x6(%rsp)
mov    $0x28a,%edi
call   1070 <RegWriteA@plt>
mov    $0x282,%edi
mov    $0x10,%esi
call   1070 <RegWriteA@plt>
mov    $0x10,%edi
call   1030 <AccWit@plt>
lea    0x7(%rsp),%rsi
mov    $0x281,%edi
call   1060 <RegReadA@plt>
movzbl 0x7(%rsp),%esi
and    $0xfffffffb,%esi
mov    $0x281,%edi
call   1070 <RegWriteA@plt>
xor    %eax,%eax
call   1080 <GyOutSignal@plt>
mov    $0x32,%edi
call   1050 <WitTim@plt>
mov    $0x101,%edi
mov    $0x1,%esi
call   1070 <RegWriteA@plt>
mov    $0x7f,%edi
mov    $0x2,%esi
call   1040 <ClrGyr@plt>
pop    %rax
ret

LLVM IR (-O0):
define void @SelectGySleep(i8 zeroext %0) {
%2 = alloca i8
%3 = alloca i8
%4 = alloca i8
store i8 %0, i8* %2
%5 = load i8, i8* %2
%6 = zext i8 %5 to i32
%7 = icmp eq i32 %6, 1
br i1 %7, label %8, label %30
8: ; preds = %1
%9 = call i32 @RegWriteA(i32 257, i32 0)
%10 = call i32 @RegWriteA(i32 640, i32 1)
%11 = call i32 @RegReadA(i32 641, i8* %4)
%12 = load i8, i8* %4
%13 = zext i8 %12 to i32
%14 = or i32 %13, 4
%15 = call i32 @RegWriteA(i32 641, i32 %14)
%16 = call i32 @RegWriteA(i32 643, i32 107)
%17 = call i32 @RegWriteA(i32 642, i32 1)
%18 = call i32 @AccWit(i32 1)
%19 = call i32 @RegReadA(i32 656, i8* %3)
%20 = load i8, i8* %3
%21 = zext i8 %20 to i32
%22 = or i32 %21, 64
%23 = trunc i32 %22 to i8
store i8 %23, i8* %3
%24 = call i32 @RegWriteA(i32 643, i32 107)
%25 = load i8, i8* %3
%26 = zext i8 %25 to i32
%27 = call i32 @RegWriteA(i32 650, i32 %26)
%28 = call i32 @RegWriteA(i32 642, i32 16)
%29 = call i32 @AccWit(i32 16)
br label %53
30: ; preds = %1
%31 = call i32 @RegWriteA(i32 643, i32 107)
%32 = call i32 @RegWriteA(i32 642, i32 1)
%33 = call i32 @AccWit(i32 1)
%34 = call i32 @RegReadA(i32 656, i8* %3)
%35 = load i8, i8* %3
%36 = zext i8 %35 to i32
%37 = and i32 %36, -65
%38 = trunc i32 %37 to i8
store i8 %38, i8* %3
%39 = load i8, i8* %3
%40 = zext i8 %39 to i32
%41 = call i32 @RegWriteA(i32 650, i32 %40)
%42 = call i32 @RegWriteA(i32 642, i32 16)
%43 = call i32 @AccWit(i32 16)
%44 = call i32 @RegReadA(i32 641, i8* %4)
%45 = load i8, i8* %4
%46 = zext i8 %45 to i32
%47 = and i32 %46, -5
%48 = call i32 @RegWriteA(i32 641, i32 %47)
%49 = call i32 (...) @GyOutSignal()
%50 = call i32 @WitTim(i32 50)
%51 = call i32 @RegWriteA(i32 257, i32 1)
%52 = call i32 @ClrGyr(i32 127, i32 2)
br label %53
53: ; preds = %30, %8
ret void
}

LLVM IR (-O2):
define void @SelectGySleep(i8 zeroext %0) {
%2 = alloca i8
%3 = alloca i8
%4 = icmp eq i8 %0, 1
br i1 %4, label %5, label %25
5: ; preds = %1
%6 = tail call i32 @RegWriteA(i32 257, i32 0)
%7 = tail call i32 @RegWriteA(i32 640, i32 1)
%8 = call i32 @RegReadA(i32 641, i8* %3)
%9 = load i8, i8* %3
%10 = or i8 %9, 4
%11 = zext i8 %10 to i32
%12 = call i32 @RegWriteA(i32 641, i32 %11)
%13 = call i32 @RegWriteA(i32 643, i32 107)
%14 = call i32 @RegWriteA(i32 642, i32 1)
%15 = call i32 @AccWit(i32 1)
%16 = call i32 @RegReadA(i32 656, i8* %2)
%17 = load i8, i8* %2
%18 = or i8 %17, 64
store i8 %18, i8* %2
%19 = call i32 @RegWriteA(i32 643, i32 107)
%20 = load i8, i8* %2
%21 = zext i8 %20 to i32
%22 = call i32 @RegWriteA(i32 650, i32 %21)
%23 = call i32 @RegWriteA(i32 642, i32 16)
%24 = call i32 @AccWit(i32 16)
br label %45
25: ; preds = %1
%26 = tail call i32 @RegWriteA(i32 643, i32 107)
%27 = tail call i32 @RegWriteA(i32 642, i32 1)
%28 = tail call i32 @AccWit(i32 1)
%29 = call i32 @RegReadA(i32 656, i8* %2)
%30 = load i8, i8* %2
%31 = and i8 %30, -65
store i8 %31, i8* %2
%32 = zext i8 %31 to i32
%33 = call i32 @RegWriteA(i32 650, i32 %32)
%34 = call i32 @RegWriteA(i32 642, i32 16)
%35 = call i32 @AccWit(i32 16)
%36 = call i32 @RegReadA(i32 641, i8* %3)
%37 = load i8, i8* %3
%38 = and i8 %37, -5
%39 = zext i8 %38 to i32
%40 = call i32 @RegWriteA(i32 641, i32 %39)
%41 = call i32 (...) @GyOutSignal()
%42 = call i32 @WitTim(i32 50)
%43 = call i32 @RegWriteA(i32 257, i32 1)
%44 = call i32 @ClrGyr(i32 127, i32 2)
br label %45
45: ; preds = %25, %5
ret void
}