#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 mips_intr_disable();
int /*<<< orphan*/ mips_intr_restore(int);
int /*<<< orphan*/ udelay(int);
void nvm_operation(unsigned op, unsigned address, unsigned data) {
  int x;
  *(volatile unsigned *)(0xBF800000 + (0x0F420)) = address & 0x1fffffff;
  *(volatile unsigned *)(0xBF800000 + (0x0F430)) = data;
  x = mips_intr_disable();
  *(volatile unsigned *)(0xBF800000 + (0x0F400)) = 0x00004000 | op;
  udelay(7);
  *(volatile unsigned *)(0xBF800000 + (0x0F410)) = 0xAA996655;
  *(volatile unsigned *)(0xBF800000 + (0x0F410)) = 0x556699AA;
  *(volatile unsigned *)(0xBF800000 + (0x0F408)) = 0x00008000;
  while (*(volatile unsigned *)(0xBF800000 + (0x0F400)) & 0x00008000)
    continue;
  *(volatile unsigned *)(0xBF800000 + (0x0F404)) = 0x00004000;
  mips_intr_restore(x);
}


x86 assembly (clang, -O0):
<nvm_operation>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    -0x8(%rbp),%ecx
and    $0x1fffffff,%ecx
mov    $0xbf80f420,%eax
mov    %ecx,(%rax)
mov    -0xc(%rbp),%ecx
mov    $0xbf80f430,%eax
mov    %ecx,(%rax)
mov    $0x0,%al
call   1050 <mips_intr_disable@plt>
mov    %eax,-0x10(%rbp)
mov    -0x4(%rbp),%ecx
or     $0x4000,%ecx
mov    $0xbf80f400,%eax
mov    %ecx,(%rax)
mov    $0x7,%edi
call   1040 <udelay@plt>
mov    $0xbf80f410,%eax
movl   $0xaa996655,(%rax)
mov    $0xbf80f410,%eax
movl   $0x556699aa,(%rax)
mov    $0xbf80f408,%eax
movl   $0x8000,(%rax)
mov    $0xbf80f400,%eax
mov    (%rax),%eax
and    $0x8000,%eax
cmp    $0x0,%eax
je     11ba <nvm_operation+0x8a>
jmp    11a0 <nvm_operation+0x70>
mov    $0xbf80f404,%eax
movl   $0x4000,(%rax)
mov    -0x10(%rbp),%edi
call   1030 <mips_intr_restore@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nvm_operation>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%ebp
mov    $0xbf80f400,%ebx
and    $0x1fffffff,%esi
mov    %esi,0x20(%rbx)
mov    %edx,0x30(%rbx)
xor    %eax,%eax
call   1050 <mips_intr_disable@plt>
mov    %eax,%r14d
or     $0x4000,%ebp
mov    %ebp,(%rbx)
mov    $0x7,%edi
call   1040 <udelay@plt>
movl   $0xaa996655,0x10(%rbx)
movl   $0x556699aa,0x10(%rbx)
movl   $0x8000,0x8(%rbx)
nopl   0x0(%rax,%rax,1)
testl  $0x8000,(%rbx)
jne    1180 <nvm_operation+0x50>
movl   $0x4000,0x4(%rbx)
mov    %r14d,%edi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <mips_intr_restore@plt>

LLVM IR (-O0):
define void @nvm_operation(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%8 = load i32, i32* %5
%9 = and i32 %8, 536870911
store volatile i32 %9, i32* inttoptr (i64 3212899360 to i32*)
%10 = load i32, i32* %6
store volatile i32 %10, i32* inttoptr (i64 3212899376 to i32*)
%11 = call i32 (...) @mips_intr_disable()
store i32 %11, i32* %7
%12 = load i32, i32* %4
%13 = or i32 16384, %12
store volatile i32 %13, i32* inttoptr (i64 3212899328 to i32*)
%14 = call i32 @udelay(i32 7)
store volatile i32 -1432787371, i32* inttoptr (i64 3212899344 to i32*)
store volatile i32 1432787370, i32* inttoptr (i64 3212899344 to i32*)
store volatile i32 32768, i32* inttoptr (i64 3212899336 to i32*)
br label %15
15: ; preds = %19, %3
%16 = load volatile i32, i32* inttoptr (i64 3212899328 to i32*)
%17 = and i32 %16, 32768
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %15
br label %15
20: ; preds = %15
store volatile i32 16384, i32* inttoptr (i64 3212899332 to i32*)
%21 = load i32, i32* %7
%22 = call i32 @mips_intr_restore(i32 %21)
ret void
}

LLVM IR (-O2):
define void @nvm_operation(i32 %0, i32 %1, i32 %2) {
%4 = and i32 %1, 536870911
store volatile i32 %4, i32* inttoptr (i64 3212899360 to i32*)
store volatile i32 %2, i32* inttoptr (i64 3212899376 to i32*)
%5 = tail call i32 (...) @mips_intr_disable()
%6 = or i32 %0, 16384
store volatile i32 %6, i32* inttoptr (i64 3212899328 to i32*)
%7 = tail call i32 @udelay(i32 7)
store volatile i32 -1432787371, i32* inttoptr (i64 3212899344 to i32*)
store volatile i32 1432787370, i32* inttoptr (i64 3212899344 to i32*)
store volatile i32 32768, i32* inttoptr (i64 3212899336 to i32*)
br label %8
8: ; preds = %8, %3
%9 = load volatile i32, i32* inttoptr (i64 3212899328 to i32*)
%10 = and i32 %9, 32768
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %8
12: ; preds = %8
store volatile i32 16384, i32* inttoptr (i64 3212899332 to i32*)
%13 = tail call i32 @mips_intr_restore(i32 %5)
ret void
}