void UARTBridgeWrite(unsigned long ulChar) {
  if (ulChar == 0xff) {
    UARTBridgeWrite(0xfffffffe);
    UARTBridgeWrite(0xfffffffe);
  } else if (ulChar == 0xfe) {
    UARTBridgeWrite(0xfffffffe);
    UARTBridgeWrite(0xfd);
  } else {
    while ((*((volatile unsigned long *)(0x4000C000 + 0x00000018))) &
           0x00000020) {
    }
    (*((volatile unsigned long *)(0x4000C000 + 0x00000000))) = ulChar & 0xff;
  }
}


x86 assembly (clang, -O0):
<UARTBridgeWrite>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0xff,-0x8(%rbp)
jne    1143 <UARTBridgeWrite+0x33>
mov    $0xfffffffe,%edi
call   1030 <UARTBridgeWrite@plt>
mov    $0xfffffffe,%edi
call   1030 <UARTBridgeWrite@plt>
jmp    11a2 <UARTBridgeWrite+0x92>
cmpq   $0xfe,-0x8(%rbp)
jne    116a <UARTBridgeWrite+0x5a>
mov    $0xfffffffe,%edi
call   1030 <UARTBridgeWrite@plt>
mov    $0xfd,%edi
call   1030 <UARTBridgeWrite@plt>
jmp    119d <UARTBridgeWrite+0x8d>
jmp    116f <UARTBridgeWrite+0x5f>
mov    $0x4000c018,%eax
mov    (%rax),%rax
and    $0x20,%rax
cmp    $0x0,%rax
je     118a <UARTBridgeWrite+0x7a>
jmp    116f <UARTBridgeWrite+0x5f>
mov    -0x8(%rbp),%rcx
and    $0xff,%rcx
mov    $0x4000c000,%eax
mov    %rcx,(%rax)
jmp    11a2 <UARTBridgeWrite+0x92>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<UARTBridgeWrite>:
cmp    $0xff,%rdi
je     1160 <UARTBridgeWrite+0x60>
cmp    $0xfe,%rdi
jne    11a0 <UARTBridgeWrite+0xa0>
cs nopw 0x0(%rax,%rax,1)
testq  $0x20,0x4000c018
jne    1120 <UARTBridgeWrite+0x20>
movq   $0xfe,0x4000c000
nopw   0x0(%rax,%rax,1)
testq  $0x20,0x4000c018
jne    1140 <UARTBridgeWrite+0x40>
mov    $0xfd,%eax
mov    %rax,0x4000c000
40
ret
nopl   0x0(%rax)
testq  $0x20,0x4000c018
jne    1160 <UARTBridgeWrite+0x60>
movq   $0xfe,0x4000c000
nopw   0x0(%rax,%rax,1)
testq  $0x20,0x4000c018
jne    1180 <UARTBridgeWrite+0x80>
mov    $0xfe,%eax
mov    %rax,0x4000c000
40
ret
nopl   0x0(%rax)
testq  $0x20,0x4000c018
jne    11a0 <UARTBridgeWrite+0xa0>
movzbl %dil,%eax
mov    %rax,0x4000c000
40
ret

LLVM IR (-O0):
define void @UARTBridgeWrite(i64 %0) {
%2 = alloca i64
store i64 %0, i64* %2
%3 = load i64, i64* %2
%4 = icmp eq i64 %3, 255
br i1 %4, label %5, label %6
5: ; preds = %1
br label %20
6: ; preds = %1
%7 = load i64, i64* %2
%8 = icmp eq i64 %7, 254
br i1 %8, label %9, label %10
9: ; preds = %6
br label %19
10: ; preds = %6
br label %11
11: ; preds = %15, %10
%12 = load volatile i64, i64* inttoptr (i64 1073791000 to i64*)
%13 = and i64 %12, 32
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %11
br label %11
16: ; preds = %11
%17 = load i64, i64* %2
%18 = and i64 %17, 255
store volatile i64 %18, i64* inttoptr (i64 1073790976 to i64*)
br label %19
19: ; preds = %16, %9
br label %20
20: ; preds = %19, %5
ret void
}

LLVM IR (-O2):
define void @UARTBridgeWrite(i64 %0) {
switch i64 %0, label %20 [
i64 255, label %2
i64 254, label %11
]
2: ; preds = %1, %2
%3 = load volatile i64, i64* inttoptr (i64 1073791000 to i64*)
%4 = and i64 %3, 32
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %2
6: ; preds = %2
store volatile i64 254, i64* inttoptr (i64 1073790976 to i64*)
br label %7
7: ; preds = %7, %6
%8 = load volatile i64, i64* inttoptr (i64 1073791000 to i64*)
%9 = and i64 %8, 32
%10 = icmp eq i64 %9, 0
br i1 %10, label %26, label %7
11: ; preds = %1, %11
%12 = load volatile i64, i64* inttoptr (i64 1073791000 to i64*)
%13 = and i64 %12, 32
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %11
15: ; preds = %11
store volatile i64 254, i64* inttoptr (i64 1073790976 to i64*)
br label %16
16: ; preds = %16, %15
%17 = load volatile i64, i64* inttoptr (i64 1073791000 to i64*)
%18 = and i64 %17, 32
%19 = icmp eq i64 %18, 0
br i1 %19, label %26, label %16
20: ; preds = %1, %20
%21 = load volatile i64, i64* inttoptr (i64 1073791000 to i64*)
%22 = and i64 %21, 32
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %20
24: ; preds = %20
%25 = and i64 %0, 255
br label %26
26: ; preds = %16, %7, %24
%27 = phi i64 [ %25, %24 ], [ 254, %7 ], [ 253, %16 ]
store volatile i64 %27, i64* inttoptr (i64 1073790976 to i64*)
ret void
}