#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*/ err_msg_blink(int, int);
unsigned int mailbox_read(unsigned int channel) {
  volatile unsigned int *status_ptr = (unsigned int *)(0x2000B880 + 0x00000018);
  volatile unsigned int *read_ptr = (unsigned int *)(0x2000B880);
  unsigned int temp;
  if (channel >= 15) {
    err_msg_blink(2, 10);
    return 0;
  }
  while ((*status_ptr & 0x04000000) == 0x04000000)
    ;
  do {
    temp = *read_ptr;
  } while ((temp & 0x0000000F) != channel);
  return temp & 0xFFFFFFF0;
}


x86 assembly (clang, -O0):
<mailbox_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    $0x2000b898,%eax
mov    %rax,-0x10(%rbp)
mov    $0x2000b880,%eax
mov    %rax,-0x18(%rbp)
cmpl   $0xf,-0x8(%rbp)
jb     1152 <mailbox_read+0x42>
mov    $0x2,%edi
mov    $0xa,%esi
call   1030 <err_msg_blink@plt>
movl   $0x0,-0x4(%rbp)
jmp    1198 <mailbox_read+0x88>
jmp    1157 <mailbox_read+0x47>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
and    $0x4000000,%eax
cmp    $0x4000000,%eax
jne    1172 <mailbox_read+0x62>
jmp    1157 <mailbox_read+0x47>
jmp    1177 <mailbox_read+0x67>
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
and    $0xf,%eax
cmp    -0x8(%rbp),%eax
jne    1177 <mailbox_read+0x67>
mov    -0x1c(%rbp),%eax
and    $0xfffffff0,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mailbox_read>:
push   %rax
cmp    $0xe,%edi
jbe    1130 <mailbox_read+0x20>
mov    $0x2,%edi
mov    $0xa,%esi
call   1030 <err_msg_blink@plt>
xor    %eax,%eax
pop    %rcx
ret
nopl   0x0(%rax)
testl  $0x4000000,0x2000b898
jne    1130 <mailbox_read+0x20>
nopl   (%rax)
mov    0x2000b880,%eax
mov    %eax,%ecx
and    $0xf,%ecx
cmp    %edi,%ecx
jne    1140 <mailbox_read+0x30>
and    $0xfffffff0,%eax
pop    %rcx
ret

LLVM IR (-O0):
define i32 @mailbox_read(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32
store i32 %0, i32* %3
store i32* inttoptr (i64 536918168 to i32*), i32** %4
store i32* inttoptr (i64 536918144 to i32*), i32** %5
%7 = load i32, i32* %3
%8 = icmp uge i32 %7, 15
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = call i32 @err_msg_blink(i32 2, i32 10)
store i32 0, i32* %2
br label %30
11: ; preds = %1
br label %12
12: ; preds = %17, %11
%13 = load i32*, i32** %4
%14 = load volatile i32, i32* %13
%15 = and i32 %14, 67108864
%16 = icmp eq i32 %15, 67108864
br i1 %16, label %17, label %18
17: ; preds = %12
br label %12
18: ; preds = %12
br label %19
19: ; preds = %22, %18
%20 = load i32*, i32** %5
%21 = load volatile i32, i32* %20
store i32 %21, i32* %6
br label %22
22: ; preds = %19
%23 = load i32, i32* %6
%24 = and i32 %23, 15
%25 = load i32, i32* %3
%26 = icmp ne i32 %24, %25
br i1 %26, label %19, label %27
27: ; preds = %22
%28 = load i32, i32* %6
%29 = and i32 %28, -16
store i32 %29, i32* %2
br label %30
30: ; preds = %27, %9
%31 = load i32, i32* %2
ret i32 %31
}

LLVM IR (-O2):
define i32 @mailbox_read(i32 %0) {
%2 = icmp ugt i32 %0, 14
br i1 %2, label %3, label %5
3: ; preds = %1
%4 = tail call i32 @err_msg_blink(i32 2, i32 10)
br label %15
5: ; preds = %1, %5
%6 = load volatile i32, i32* inttoptr (i64 536918168 to i32*)
%7 = and i32 %6, 67108864
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %5
9: ; preds = %5, %9
%10 = load volatile i32, i32* inttoptr (i64 536918144 to i32*)
%11 = and i32 %10, 15
%12 = icmp eq i32 %11, %0
br i1 %12, label %13, label %9
13: ; preds = %9
%14 = and i32 %10, -16
br label %15
15: ; preds = %13, %3
%16 = phi i32 [ 0, %3 ], [ %14, %13 ]
ret i32 %16
}