#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*/ RegReadA(unsigned short, unsigned char *);
int /*<<< orphan*/ RegWriteA(unsigned short, unsigned char);
int /*<<< orphan*/ WitTim(int);
void BsyWit(unsigned short UsTrgAdr, unsigned char UcTrgDat) {
  unsigned char UcFlgVal;
  unsigned char UcCnt;
  RegWriteA(UsTrgAdr, UcTrgDat);
  for (UcCnt = 0; UcCnt < 60; UcCnt++) {
    RegReadA(UsTrgAdr, &UcFlgVal);
    UcFlgVal &= (UcTrgDat & 0x0F);
    if (UcFlgVal == 0)
      break;
    WitTim(10);
  }
}


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   $0x0,-0x5(%rbp)
movzbl -0x5(%rbp),%eax
cmp    $0x3c,%eax
jge    11ac <BsyWit+0x7c>
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)
movzbl -0x4(%rbp),%eax
cmp    $0x0,%eax
jne    1195 <BsyWit+0x65>
jmp    11ac <BsyWit+0x7c>
mov    $0xa,%edi
call   1030 <WitTim@plt>
mov    -0x5(%rbp),%al
add    $0x1,%al
mov    %al,-0x5(%rbp)
jmp    1159 <BsyWit+0x29>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<BsyWit>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r15d
mov    %edi,%ebp
call   1050 <RegWriteA@plt>
and    $0xf,%r15b
mov    $0x3c,%bl
movzwl %bp,%ebp
lea    0x7(%rsp),%r14
nop
mov    %ebp,%edi
mov    %r14,%rsi
call   1040 <RegReadA@plt>
and    %r15b,0x7(%rsp)
je     1170 <BsyWit+0x40>
mov    $0xa,%edi
call   1030 <WitTim@plt>
add    $0xff,%bl
jne    1150 <BsyWit+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @BsyWit(i16 zeroext %0, i8 zeroext %1) {
%3 = alloca i16
%4 = alloca i8
%5 = alloca i8
%6 = alloca i8
store i16 %0, i16* %3
store i8 %1, i8* %4
%7 = load i16, i16* %3
%8 = load i8, i8* %4
%9 = call i32 @RegWriteA(i16 zeroext %7, i8 zeroext %8)
store i8 0, i8* %6
br label %10
10: ; preds = %30, %2
%11 = load i8, i8* %6
%12 = zext i8 %11 to i32
%13 = icmp slt i32 %12, 60
br i1 %13, label %14, label %33
14: ; preds = %10
%15 = load i16, i16* %3
%16 = call i32 @RegReadA(i16 zeroext %15, i8* %5)
%17 = load i8, i8* %4
%18 = zext i8 %17 to i32
%19 = and i32 %18, 15
%20 = load i8, i8* %5
%21 = zext i8 %20 to i32
%22 = and i32 %21, %19
%23 = trunc i32 %22 to i8
store i8 %23, i8* %5
%24 = load i8, i8* %5
%25 = zext i8 %24 to i32
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %14
br label %33
28: ; preds = %14
%29 = call i32 @WitTim(i32 10)
br label %30
30: ; preds = %28
%31 = load i8, i8* %6
%32 = add i8 %31, 1
store i8 %32, i8* %6
br label %10
33: ; preds = %27, %10
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)
%5 = and i8 %1, 15
br label %6
6: ; preds = %2, %12
%7 = phi i8 [ 0, %2 ], [ %14, %12 ]
%8 = call i32 @RegReadA(i16 zeroext %0, i8* %3)
%9 = load i8, i8* %3
%10 = and i8 %5, %9
store i8 %10, i8* %3
%11 = icmp eq i8 %10, 0
br i1 %11, label %16, label %12
12: ; preds = %6
%13 = call i32 @WitTim(i32 10)
%14 = add nuw nsw i8 %7, 1
%15 = icmp eq i8 %14, 60
br i1 %15, label %16, label %6
16: ; preds = %6, %12
ret void
}