#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_write(unsigned int *message_ptr, unsigned int channel) {
  volatile unsigned int *status_ptr = (unsigned int *)(0x2000B880 + 0x00000018);
  volatile unsigned int *write_ptr = (unsigned int *)(0x2000B880 + 0x00000020);
  unsigned int temp = (unsigned int)message_ptr;
  if (temp & 0x0000000F) {
    err_msg_blink(1, 10);
    return 0;
  }
  if (channel >= 15) {
    err_msg_blink(2, 10);
    return 0;
  }
  while ((*status_ptr & 0x80000000) == 0x80000000)
    ;
  temp += channel;
  *write_ptr = temp;
  return 1;
}


x86 assembly (clang, -O0):
<mailbox_write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    $0x2000b898,%eax
mov    %rax,-0x20(%rbp)
mov    $0x2000b8a0,%eax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
and    $0xf,%eax
cmp    $0x0,%eax
je     1162 <mailbox_write+0x52>
mov    $0x1,%edi
mov    $0xa,%esi
call   1030 <err_msg_blink@plt>
movl   $0x0,-0x4(%rbp)
jmp    11c0 <mailbox_write+0xb0>
cmpl   $0xf,-0x14(%rbp)
jb     1187 <mailbox_write+0x77>
mov    $0x2,%edi
mov    $0xa,%esi
call   1030 <err_msg_blink@plt>
movl   $0x0,-0x4(%rbp)
jmp    11c0 <mailbox_write+0xb0>
jmp    118c <mailbox_write+0x7c>
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
and    $0x80000000,%eax
cmp    $0x80000000,%eax
jne    11a7 <mailbox_write+0x97>
jmp    118c <mailbox_write+0x7c>
mov    -0x14(%rbp),%eax
add    -0x2c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mailbox_write>:
push   %rax
test   $0xf,%dil
je     111e <mailbox_write+0xe>
mov    $0x1,%edi
jmp    1128 <mailbox_write+0x18>
cmp    $0xe,%esi
jbe    1140 <mailbox_write+0x30>
mov    $0x2,%edi
mov    $0xa,%esi
call   1030 <err_msg_blink@plt>
xor    %eax,%eax
pop    %rcx
ret
cs nopw 0x0(%rax,%rax,1)
cmpl   $0x0,0x2000b898
js     1140 <mailbox_write+0x30>
add    %esi,%edi
mov    %edi,0x2000b8a0
mov    $0x1,%eax
pop    %rcx
ret

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

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