#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 GET32(int);
int /*<<< orphan*/ PUT32(int, int);
unsigned mbox_writeread(unsigned nData) {
  while (GET32(((0x20000000 + 0xB880) + 0x38)) & 0x80000000) {
  }
  PUT32(((0x20000000 + 0xB880) + 0x20), 8 | nData);
  unsigned nResult;
  do {
    while (GET32(((0x20000000 + 0xB880) + 0x18)) & 0x40000000) {
    }
    nResult = GET32(((0x20000000 + 0xB880) + 0x00));
  } while ((nResult & 0xF) != 8);
  return nResult & ~0xF;
}


x86 assembly (clang, -O0):
<mbox_writeread>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x2000b8b8,%edi
call   1040 <GET32@plt>
and    $0x80000000,%eax
cmp    $0x0,%eax
je     1148 <mbox_writeread+0x28>
jmp    112b <mbox_writeread+0xb>
mov    -0x4(%rbp),%esi
or     $0x8,%esi
mov    $0x2000b8a0,%edi
call   1030 <PUT32@plt>
jmp    115d <mbox_writeread+0x3d>
mov    $0x2000b898,%edi
call   1040 <GET32@plt>
and    $0x40000000,%eax
cmp    $0x0,%eax
je     117a <mbox_writeread+0x5a>
jmp    115d <mbox_writeread+0x3d>
mov    $0x2000b880,%edi
call   1040 <GET32@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
and    $0xf,%eax
cmp    $0x8,%eax
jne    1158 <mbox_writeread+0x38>
mov    -0x8(%rbp),%eax
and    $0xfffffff0,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mbox_writeread>:
push   %rbx
mov    %edi,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    $0x2000b8b8,%edi
call   1040 <GET32@plt>
test   %eax,%eax
js     1130 <mbox_writeread+0x10>
or     $0x8,%ebx
mov    $0x2000b8a0,%edi
mov    %ebx,%esi
call   1030 <PUT32@plt>
nopl   (%rax)
mov    $0x2000b898,%edi
call   1040 <GET32@plt>
test   $0x40000000,%eax
jne    1150 <mbox_writeread+0x30>
mov    $0x2000b880,%edi
call   1040 <GET32@plt>
mov    %eax,%ecx
and    $0xf,%ecx
cmp    $0x8,%ecx
jne    1150 <mbox_writeread+0x30>
and    $0xfffffff0,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @mbox_writeread(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
br label %4
4: ; preds = %8, %1
%5 = call i32 @GET32(i32 536918200)
%6 = and i32 %5, -2147483648
%7 = icmp ne i32 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %4
br label %4
9: ; preds = %4
%10 = load i32, i32* %2
%11 = or i32 8, %10
%12 = call i32 @PUT32(i32 536918176, i32 %11)
br label %13
13: ; preds = %21, %9
br label %14
14: ; preds = %18, %13
%15 = call i32 @GET32(i32 536918168)
%16 = and i32 %15, 1073741824
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %14
br label %14
19: ; preds = %14
%20 = call i32 @GET32(i32 536918144)
store i32 %20, i32* %3
br label %21
21: ; preds = %19
%22 = load i32, i32* %3
%23 = and i32 %22, 15
%24 = icmp ne i32 %23, 8
br i1 %24, label %13, label %25
25: ; preds = %21
%26 = load i32, i32* %3
%27 = and i32 %26, -16
ret i32 %27
}

LLVM IR (-O2):
define i32 @mbox_writeread(i32 %0) {
br label %2
2: ; preds = %2, %1
%3 = tail call i32 @GET32(i32 536918200)
%4 = icmp sgt i32 %3, -1
br i1 %4, label %5, label %2
5: ; preds = %2
%6 = or i32 %0, 8
%7 = tail call i32 @PUT32(i32 536918176, i32 %6)
br label %8
8: ; preds = %12, %5
%9 = tail call i32 @GET32(i32 536918168)
%10 = and i32 %9, 1073741824
%11 = icmp eq i32 %10, 0
br i1 %11, label %13, label %12
12: ; preds = %8, %13
br label %8
13: ; preds = %8
%14 = tail call i32 @GET32(i32 536918144)
%15 = and i32 %14, 15
%16 = icmp eq i32 %15, 8
br i1 %16, label %17, label %12
17: ; preds = %13
%18 = and i32 %14, -16
ret i32 %18
}