#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 */
typedef int uint32_t;

/* Variables and functions */
int /*<<< orphan*/ mbox_read(int);
int /*<<< orphan*/ mbox_write(int, int);
int /*<<< orphan*/ printf(char *);
int bcm_2708_power_off() {
  uint32_t mb_addr = 0x40005000;
  volatile uint32_t *mailbuffer = (uint32_t *)mb_addr;
  mailbuffer[0] = 8 * 4;
  mailbuffer[1] = 0;
  mailbuffer[2] = 0x00028001;
  mailbuffer[3] = 0x8;
  mailbuffer[4] = 0x8;
  mailbuffer[5] = 0x0;
  mailbuffer[6] = 0x2;
  mailbuffer[7] = 0;
  mbox_write(8, mb_addr);
  mbox_read(8);
  if (mailbuffer[1] != 0x80000000) {
    printf("EMMC: bcm_2708_power_off(): property mailbox did not return a "
           "valid response.\n");
    return -1;
  }
  if (mailbuffer[5] != 0x0) {
    printf("EMMC: property mailbox did not return a valid device id.\n");
    return -1;
  }
  if ((mailbuffer[6] & 0x3) != 0) {
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<bcm_2708_power_off>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x40005000,-0x8(%rbp)
movslq -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movl   $0x20,(%rax)
mov    -0x10(%rbp),%rax
movl   $0x0,0x4(%rax)
mov    -0x10(%rbp),%rax
movl   $0x28001,0x8(%rax)
mov    -0x10(%rbp),%rax
movl   $0x8,0xc(%rax)
mov    -0x10(%rbp),%rax
movl   $0x8,0x10(%rax)
mov    -0x10(%rbp),%rax
movl   $0x0,0x14(%rax)
mov    -0x10(%rbp),%rax
movl   $0x2,0x18(%rax)
mov    -0x10(%rbp),%rax
movl   $0x0,0x1c(%rax)
mov    -0x8(%rbp),%esi
mov    $0x8,%edi
call   1050 <mbox_write@plt>
mov    $0x8,%edi
call   1030 <mbox_read@plt>
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%eax
cmp    $0x80000000,%eax
je     11df <bcm_2708_power_off+0xaf>
lea    0xe32(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    122d <bcm_2708_power_off+0xfd>
mov    -0x10(%rbp),%rax
mov    0x14(%rax),%eax
cmp    $0x0,%eax
je     1207 <bcm_2708_power_off+0xd7>
lea    0xe59(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    122d <bcm_2708_power_off+0xfd>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%eax
and    $0x3,%eax
cmp    $0x0,%eax
je     1226 <bcm_2708_power_off+0xf6>
movl   $0x1,-0x4(%rbp)
jmp    122d <bcm_2708_power_off+0xfd>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bcm_2708_power_off>:
push   %rax
movl   $0x20,0x40005000
movl   $0x0,0x40005004
movl   $0x28001,0x40005008
movl   $0x8,0x4000500c
movl   $0x8,0x40005010
movl   $0x0,0x40005014
movl   $0x2,0x40005018
movl   $0x0,0x4000501c
mov    $0x8,%edi
mov    $0x40005000,%esi
call   1050 <mbox_write@plt>
mov    $0x8,%edi
call   1040 <mbox_read@plt>
mov    0x40005004,%eax
cmp    $0x80000000,%eax
jne    11c3 <bcm_2708_power_off+0x93>
cmpl   $0x0,0x40005014
je     11d6 <bcm_2708_power_off+0xa6>
lea    0xe3f(%rip),%rdi
jmp    11ca <bcm_2708_power_off+0x9a>
lea    0xe6f(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
pop    %rcx
ret
xor    %eax,%eax
testl  $0x3,0x40005018
setne  %al
pop    %rcx
ret

LLVM IR (-O0):
@.str = [79 x i8] c"EMMC: bcm_2708_power_off(): property mailbox did not return a valid response.\0A\00"
@.str.1 = [58 x i8] c"EMMC: property mailbox did not return a valid device id.\0A\00"
define i32 @bcm_2708_power_off() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32*
store i32 1073762304, i32* %2
%4 = load i32, i32* %2
%5 = sext i32 %4 to i64
%6 = inttoptr i64 %5 to i32*
store i32* %6, i32** %3
%7 = load i32*, i32** %3
%8 = getelementptr inbounds i32, i32* %7, i64 0
store volatile i32 32, i32* %8
%9 = load i32*, i32** %3
%10 = getelementptr inbounds i32, i32* %9, i64 1
store volatile i32 0, i32* %10
%11 = load i32*, i32** %3
%12 = getelementptr inbounds i32, i32* %11, i64 2
store volatile i32 163841, i32* %12
%13 = load i32*, i32** %3
%14 = getelementptr inbounds i32, i32* %13, i64 3
store volatile i32 8, i32* %14
%15 = load i32*, i32** %3
%16 = getelementptr inbounds i32, i32* %15, i64 4
store volatile i32 8, i32* %16
%17 = load i32*, i32** %3
%18 = getelementptr inbounds i32, i32* %17, i64 5
store volatile i32 0, i32* %18
%19 = load i32*, i32** %3
%20 = getelementptr inbounds i32, i32* %19, i64 6
store volatile i32 2, i32* %20
%21 = load i32*, i32** %3
%22 = getelementptr inbounds i32, i32* %21, i64 7
store volatile i32 0, i32* %22
%23 = load i32, i32* %2
%24 = call i32 @mbox_write(i32 8, i32 %23)
%25 = call i32 @mbox_read(i32 8)
%26 = load i32*, i32** %3
%27 = getelementptr inbounds i32, i32* %26, i64 1
%28 = load volatile i32, i32* %27
%29 = icmp ne i32 %28, -2147483648
br i1 %29, label %30, label %32
30: ; preds = %0
%31 = call i32 @printf(i8* getelementptr inbounds ([79 x i8], [79 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %1
br label %47
32: ; preds = %0
%33 = load i32*, i32** %3
%34 = getelementptr inbounds i32, i32* %33, i64 5
%35 = load volatile i32, i32* %34
%36 = icmp ne i32 %35, 0
br i1 %36, label %37, label %39
37: ; preds = %32
%38 = call i32 @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %1
br label %47
39: ; preds = %32
%40 = load i32*, i32** %3
%41 = getelementptr inbounds i32, i32* %40, i64 6
%42 = load volatile i32, i32* %41
%43 = and i32 %42, 3
%44 = icmp ne i32 %43, 0
br i1 %44, label %45, label %46
45: ; preds = %39
store i32 1, i32* %1
br label %47
46: ; preds = %39
store i32 0, i32* %1
br label %47
47: ; preds = %46, %45, %37, %30
%48 = load i32, i32* %1
ret i32 %48
}

LLVM IR (-O2):
@str = [57 x i8] c"EMMC: property mailbox did not return a valid device id.\00"
@str.2 = [78 x i8] c"EMMC: bcm_2708_power_off(): property mailbox did not return a valid response.\00"
define i32 @bcm_2708_power_off() {
store volatile i32 32, i32* inttoptr (i64 1073762304 to i32*)
store volatile i32 0, i32* inttoptr (i64 1073762308 to i32*)
store volatile i32 163841, i32* inttoptr (i64 1073762312 to i32*)
store volatile i32 8, i32* inttoptr (i64 1073762316 to i32*)
store volatile i32 8, i32* inttoptr (i64 1073762320 to i32*)
store volatile i32 0, i32* inttoptr (i64 1073762324 to i32*)
store volatile i32 2, i32* inttoptr (i64 1073762328 to i32*)
store volatile i32 0, i32* inttoptr (i64 1073762332 to i32*)
%1 = tail call i32 @mbox_write(i32 8, i32 1073762304)
%2 = tail call i32 @mbox_read(i32 8)
%3 = load volatile i32, i32* inttoptr (i64 1073762308 to i32*)
%4 = icmp eq i32 %3, -2147483648
br i1 %4, label %7, label %5
5: ; preds = %0
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([78 x i8], [78 x i8]* @str.2, i64 0, i64 0))
br label %17
7: ; preds = %0
%8 = load volatile i32, i32* inttoptr (i64 1073762324 to i32*)
%9 = icmp eq i32 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %7
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([57 x i8], [57 x i8]* @str, i64 0, i64 0))
br label %17
12: ; preds = %7
%13 = load volatile i32, i32* inttoptr (i64 1073762328 to i32*)
%14 = and i32 %13, 3
%15 = icmp ne i32 %14, 0
%16 = zext i1 %15 to i32
br label %17
17: ; preds = %12, %10, %5
%18 = phi i32 [ -1, %5 ], [ -1, %10 ], [ %16, %12 ]
ret i32 %18
}