#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*/ RamAccFixMod(int);
int /*<<< orphan*/ RamReadA(int, unsigned short *);
int /*<<< orphan*/ RamWriteA(int, int);
int /*<<< orphan*/ RegWriteA(int, int);
int /*<<< orphan*/ WitTim(int);
void SmoothSvrOff(void) {
  unsigned short UsStep = 0x0100, UcCnt;
  unsigned short UsDrv;
  RegWriteA(0x0170, 0x02);
  RamAccFixMod(0x01);
  for (UsStep = 0; UcCnt < 200; UcCnt++) {
    RamReadA(0x1477, &UsDrv);
    if (UsDrv > 0x8000) {
      if (UsDrv >= 0xFF00) {
        UsDrv = 0x0000;
        break;
      } else {
        UsDrv += 0x0100;
      }
    } else {
      if (UsDrv <= 0x0100) {
        UsDrv = 0x0000;
        break;
      } else {
        UsDrv -= 0x0100;
      }
    }
    RamWriteA(0x1477, UsDrv);
    WitTim(1);
  }
  RamAccFixMod(0x00);
  RegWriteA(0x0171, 0x02);
  RamAccFixMod(0x01);
  for (UsStep = 0; UcCnt < 200; UcCnt++) {
    RamReadA(0x14F7, &UsDrv);
    if (UsDrv > 0x8000) {
      if (UsDrv >= 0xFF00) {
        UsDrv = 0x0000;
        break;
      } else {
        UsDrv += 0x0100;
      }
    } else {
      if (UsDrv <= 0x0100) {
        UsDrv = 0x0000;
        break;
      } else {
        UsDrv -= 0x0100;
      }
    }
    RamWriteA(0x14F7, UsDrv);
    WitTim(1);
  }
  RamWriteA(0x1477, 0x00);
  RamWriteA(0x14F7, 0x00);
  RamAccFixMod(0x00);
}


x86 assembly (clang, -O0):
<SmoothSvrOff>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movw   $0x100,-0x2(%rbp)
mov    $0x170,%edi
mov    $0x2,%esi
call   1070 <RegWriteA@plt>
mov    $0x1,%edi
call   1060 <RamAccFixMod@plt>
movw   $0x0,-0x2(%rbp)
movzwl -0x4(%rbp),%eax
cmp    $0xc8,%eax
jge    122a <SmoothSvrOff+0xda>
mov    $0x1477,%edi
lea    -0x6(%rbp),%rsi
call   1040 <RamReadA@plt>
movzwl -0x6(%rbp),%eax
cmp    $0x8000,%eax
jle    11d5 <SmoothSvrOff+0x85>
movzwl -0x6(%rbp),%eax
cmp    $0xff00,%eax
jl     11c3 <SmoothSvrOff+0x73>
movw   $0x0,-0x6(%rbp)
jmp    122a <SmoothSvrOff+0xda>
movzwl -0x6(%rbp),%eax
add    $0x100,%eax
mov    %ax,-0x6(%rbp)
jmp    1201 <SmoothSvrOff+0xb1>
movzwl -0x6(%rbp),%eax
cmp    $0x100,%eax
jg     11ef <SmoothSvrOff+0x9f>
movw   $0x0,-0x6(%rbp)
jmp    122a <SmoothSvrOff+0xda>
movzwl -0x6(%rbp),%eax
sub    $0x100,%eax
mov    %ax,-0x6(%rbp)
jmp    1201 <SmoothSvrOff+0xb1>
movzwl -0x6(%rbp),%esi
mov    $0x1477,%edi
call   1030 <RamWriteA@plt>
mov    $0x1,%edi
call   1050 <WitTim@plt>
mov    -0x4(%rbp),%ax
add    $0x1,%ax
mov    %ax,-0x4(%rbp)
jmp    117d <SmoothSvrOff+0x2d>
xor    %edi,%edi
call   1060 <RamAccFixMod@plt>
mov    $0x171,%edi
mov    $0x2,%esi
call   1070 <RegWriteA@plt>
mov    $0x1,%edi
call   1060 <RamAccFixMod@plt>
movw   $0x0,-0x2(%rbp)
movzwl -0x4(%rbp),%eax
cmp    $0xc8,%eax
jge    12fd <SmoothSvrOff+0x1ad>
mov    $0x14f7,%edi
lea    -0x6(%rbp),%rsi
call   1040 <RamReadA@plt>
movzwl -0x6(%rbp),%eax
cmp    $0x8000,%eax
jle    12a8 <SmoothSvrOff+0x158>
movzwl -0x6(%rbp),%eax
cmp    $0xff00,%eax
jl     1296 <SmoothSvrOff+0x146>
movw   $0x0,-0x6(%rbp)
jmp    12fd <SmoothSvrOff+0x1ad>
movzwl -0x6(%rbp),%eax
add    $0x100,%eax
mov    %ax,-0x6(%rbp)
jmp    12d4 <SmoothSvrOff+0x184>
movzwl -0x6(%rbp),%eax
cmp    $0x100,%eax
jg     12c2 <SmoothSvrOff+0x172>
movw   $0x0,-0x6(%rbp)
jmp    12fd <SmoothSvrOff+0x1ad>
movzwl -0x6(%rbp),%eax
sub    $0x100,%eax
mov    %ax,-0x6(%rbp)
jmp    12d4 <SmoothSvrOff+0x184>
movzwl -0x6(%rbp),%esi
mov    $0x14f7,%edi
call   1030 <RamWriteA@plt>
mov    $0x1,%edi
call   1050 <WitTim@plt>
mov    -0x4(%rbp),%ax
add    $0x1,%ax
mov    %ax,-0x4(%rbp)
jmp    1250 <SmoothSvrOff+0x100>
mov    $0x1477,%edi
xor    %esi,%esi
call   1030 <RamWriteA@plt>
mov    $0x14f7,%edi
xor    %esi,%esi
call   1030 <RamWriteA@plt>
xor    %edi,%edi
call   1060 <RamAccFixMod@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SmoothSvrOff>:
push   %rax
mov    $0x170,%edi
mov    $0x2,%esi
call   1050 <RegWriteA@plt>
mov    $0x1,%edi
call   1040 <RamAccFixMod@plt>
xor    %edi,%edi
call   1040 <RamAccFixMod@plt>
mov    $0x171,%edi
mov    $0x2,%esi
call   1050 <RegWriteA@plt>
mov    $0x1,%edi
call   1040 <RamAccFixMod@plt>
mov    $0x1477,%edi
xor    %esi,%esi
call   1030 <RamWriteA@plt>
mov    $0x14f7,%edi
xor    %esi,%esi
call   1030 <RamWriteA@plt>
xor    %edi,%edi
call   1040 <RamAccFixMod@plt>
pop    %rax
ret

LLVM IR (-O0):
define void @SmoothSvrOff() {
%1 = alloca i16
%2 = alloca i16
%3 = alloca i16
store i16 256, i16* %1
%4 = call i32 @RegWriteA(i32 368, i32 2)
%5 = call i32 @RamAccFixMod(i32 1)
store i16 0, i16* %1
br label %6
6: ; preds = %42, %0
%7 = load i16, i16* %2
%8 = zext i16 %7 to i32
%9 = icmp slt i32 %8, 200
br i1 %9, label %10, label %45
10: ; preds = %6
%11 = call i32 @RamReadA(i32 5239, i16* %3)
%12 = load i16, i16* %3
%13 = zext i16 %12 to i32
%14 = icmp sgt i32 %13, 32768
br i1 %14, label %15, label %26
15: ; preds = %10
%16 = load i16, i16* %3
%17 = zext i16 %16 to i32
%18 = icmp sge i32 %17, 65280
br i1 %18, label %19, label %20
19: ; preds = %15
store i16 0, i16* %3
br label %45
20: ; preds = %15
%21 = load i16, i16* %3
%22 = zext i16 %21 to i32
%23 = add nsw i32 %22, 256
%24 = trunc i32 %23 to i16
store i16 %24, i16* %3
br label %25
25: ; preds = %20
br label %37
26: ; preds = %10
%27 = load i16, i16* %3
%28 = zext i16 %27 to i32
%29 = icmp sle i32 %28, 256
br i1 %29, label %30, label %31
30: ; preds = %26
store i16 0, i16* %3
br label %45
31: ; preds = %26
%32 = load i16, i16* %3
%33 = zext i16 %32 to i32
%34 = sub nsw i32 %33, 256
%35 = trunc i32 %34 to i16
store i16 %35, i16* %3
br label %36
36: ; preds = %31
br label %37
37: ; preds = %36, %25
%38 = load i16, i16* %3
%39 = zext i16 %38 to i32
%40 = call i32 @RamWriteA(i32 5239, i32 %39)
%41 = call i32 @WitTim(i32 1)
br label %42
42: ; preds = %37
%43 = load i16, i16* %2
%44 = add i16 %43, 1
store i16 %44, i16* %2
br label %6
45: ; preds = %30, %19, %6
%46 = call i32 @RamAccFixMod(i32 0)
%47 = call i32 @RegWriteA(i32 369, i32 2)
%48 = call i32 @RamAccFixMod(i32 1)
store i16 0, i16* %1
br label %49
49: ; preds = %85, %45
%50 = load i16, i16* %2
%51 = zext i16 %50 to i32
%52 = icmp slt i32 %51, 200
br i1 %52, label %53, label %88
53: ; preds = %49
%54 = call i32 @RamReadA(i32 5367, i16* %3)
%55 = load i16, i16* %3
%56 = zext i16 %55 to i32
%57 = icmp sgt i32 %56, 32768
br i1 %57, label %58, label %69
58: ; preds = %53
%59 = load i16, i16* %3
%60 = zext i16 %59 to i32
%61 = icmp sge i32 %60, 65280
br i1 %61, label %62, label %63
62: ; preds = %58
store i16 0, i16* %3
br label %88
63: ; preds = %58
%64 = load i16, i16* %3
%65 = zext i16 %64 to i32
%66 = add nsw i32 %65, 256
%67 = trunc i32 %66 to i16
store i16 %67, i16* %3
br label %68
68: ; preds = %63
br label %80
69: ; preds = %53
%70 = load i16, i16* %3
%71 = zext i16 %70 to i32
%72 = icmp sle i32 %71, 256
br i1 %72, label %73, label %74
73: ; preds = %69
store i16 0, i16* %3
br label %88
74: ; preds = %69
%75 = load i16, i16* %3
%76 = zext i16 %75 to i32
%77 = sub nsw i32 %76, 256
%78 = trunc i32 %77 to i16
store i16 %78, i16* %3
br label %79
79: ; preds = %74
br label %80
80: ; preds = %79, %68
%81 = load i16, i16* %3
%82 = zext i16 %81 to i32
%83 = call i32 @RamWriteA(i32 5367, i32 %82)
%84 = call i32 @WitTim(i32 1)
br label %85
85: ; preds = %80
%86 = load i16, i16* %2
%87 = add i16 %86, 1
store i16 %87, i16* %2
br label %49
88: ; preds = %73, %62, %49
%89 = call i32 @RamWriteA(i32 5239, i32 0)
%90 = call i32 @RamWriteA(i32 5367, i32 0)
%91 = call i32 @RamAccFixMod(i32 0)
ret void
}

LLVM IR (-O2):
define void @SmoothSvrOff() {
%1 = tail call i32 @RegWriteA(i32 368, i32 2)
%2 = tail call i32 @RamAccFixMod(i32 1)
%3 = call i32 @RamAccFixMod(i32 0)
%4 = call i32 @RegWriteA(i32 369, i32 2)
%5 = call i32 @RamAccFixMod(i32 1)
%6 = call i32 @RamWriteA(i32 5239, i32 0)
%7 = call i32 @RamWriteA(i32 5367, i32 0)
%8 = call i32 @RamAccFixMod(i32 0)
ret void
}