#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 */
scalar_t__ CmdRdChk();
int /*<<< orphan*/ RegReadA(unsigned short, unsigned char *);
int /*<<< orphan*/ RegWriteA(unsigned short, unsigned char);
void BsyWit(unsigned short UsTrgAdr, unsigned char UcTrgDat) {
  unsigned char UcFlgVal;
  RegWriteA(UsTrgAdr, UcTrgDat);
  UcFlgVal = 1;
  while (UcFlgVal) {
    RegReadA(UsTrgAdr, &UcFlgVal);
    UcFlgVal &= (UcTrgDat & 0x0F);
    if (CmdRdChk() != 0)
      break;
  };
}


x86 assembly (clang, -O0):
<BsyWit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %sil,%al
mov    %di,%cx
mov    %cx,-0x2(%rbp)
mov    %al,-0x3(%rbp)
mov    -0x2(%rbp),%ax
movzwl %ax,%edi
movzbl -0x3(%rbp),%esi
call   1050 <RegWriteA@plt>
movb   $0x1,-0x4(%rbp)
cmpb   $0x0,-0x4(%rbp)
je     119b <BsyWit+0x6b>
lea    -0x4(%rbp),%rsi
movzwl -0x2(%rbp),%edi
call   1040 <RegReadA@plt>
movzbl -0x3(%rbp),%ecx
and    $0xf,%ecx
movzbl -0x4(%rbp),%eax
and    %ecx,%eax
mov    %al,-0x4(%rbp)
mov    $0x0,%al
call   1030 <CmdRdChk@plt>
cmp    $0x0,%rax
je     1196 <BsyWit+0x66>
jmp    119b <BsyWit+0x6b>
jmp    1159 <BsyWit+0x29>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<BsyWit>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebx
mov    %edi,%ebp
call   1050 <RegWriteA@plt>
movb   $0x1,0xf(%rsp)
and    $0xf,%bl
movzwl %bp,%ebp
lea    0xf(%rsp),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %r14,%rsi
call   1040 <RegReadA@plt>
and    %bl,0xf(%rsp)
xor    %eax,%eax
call   1030 <CmdRdChk@plt>
test   %rax,%rax
jne    1181 <BsyWit+0x51>
cmpb   $0x0,0xf(%rsp)
jne    1160 <BsyWit+0x30>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @BsyWit(i16 zeroext %0, i8 zeroext %1) {
%3 = alloca i16
%4 = alloca i8
%5 = alloca i8
store i16 %0, i16* %3
store i8 %1, i8* %4
%6 = load i16, i16* %3
%7 = load i8, i8* %4
%8 = call i32 @RegWriteA(i16 zeroext %6, i8 zeroext %7)
store i8 1, i8* %5
br label %9
9: ; preds = %25, %2
%10 = load i8, i8* %5
%11 = icmp ne i8 %10, 0
br i1 %11, label %12, label %26
12: ; preds = %9
%13 = load i16, i16* %3
%14 = call i32 @RegReadA(i16 zeroext %13, i8* %5)
%15 = load i8, i8* %4
%16 = zext i8 %15 to i32
%17 = and i32 %16, 15
%18 = load i8, i8* %5
%19 = zext i8 %18 to i32
%20 = and i32 %19, %17
%21 = trunc i32 %20 to i8
store i8 %21, i8* %5
%22 = call i64 (...) @CmdRdChk()
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %12
br label %26
25: ; preds = %12
br label %9
26: ; preds = %24, %9
ret void
}

LLVM IR (-O2):
define void @BsyWit(i16 zeroext %0, i8 zeroext %1) {
%3 = alloca i8
%4 = tail call i32 @RegWriteA(i16 zeroext %0, i8 zeroext %1)
store i8 1, i8* %3
%5 = and i8 %1, 15
br label %6
6: ; preds = %2, %6
%7 = call i32 @RegReadA(i16 zeroext %0, i8* %3)
%8 = load i8, i8* %3
%9 = and i8 %5, %8
store i8 %9, i8* %3
%10 = call i64 (...) @CmdRdChk()
%11 = icmp eq i64 %10, 0
%12 = load i8, i8* %3
%13 = icmp ne i8 %12, 0
%14 = select i1 %11, i1 %13, i1 false
br i1 %14, label %6, label %15
15: ; preds = %6
ret void
}