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

/* Variables and functions */
void driver_mfc_erase_sector(uint8_t space_control, uint32_t flash_address) {
  (*((volatile uint32_t *)(0x800000 + 0x10))) = 0XA5;
  (*((volatile uint32_t *)(0x800000 + 0x14))) = 0XC3;
  (*((volatile uint32_t *)(0x800000 + 0x8))) = (flash_address / 4);
  (*((volatile uint32_t *)(0x800000 + 0x0))) = 0x58a9;
  (*((volatile uint32_t *)(0x800000 + 0x0))) = 0xa958;
  (*((volatile uint32_t *)(0x800000 + 0x4))) = (2 << 2);
  (*((volatile uint32_t *)(0x800000 + 0x4))) |= (space_control << 5);
  (*((volatile uint32_t *)(0x800000 + 0x4))) |= (1 << 0);
  while ((*((volatile uint32_t *)(0x800000 + 0x4))) & 0x00000001)
    ;
}


x86 assembly (clang, -O0):
<driver_mfc_erase_sector>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    $0x800010,%eax
movl   $0xa5,(%rax)
mov    $0x800014,%eax
movl   $0xc3,(%rax)
mov    -0x8(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    $0x800008,%eax
mov    %ecx,(%rax)
mov    $0x800000,%eax
movl   $0x58a9,(%rax)
mov    $0x800000,%eax
movl   $0xa958,(%rax)
mov    $0x800004,%eax
movl   $0x8,(%rax)
mov    -0x4(%rbp),%eax
shl    $0x5,%eax
mov    $0x800004,%ecx
mov    (%rcx),%ecx
or     %eax,%ecx
mov    $0x800004,%eax
mov    %ecx,(%rax)
mov    $0x800004,%eax
mov    (%rax),%ecx
or     $0x1,%ecx
mov    $0x800004,%eax
mov    %ecx,(%rax)
mov    $0x800004,%eax
mov    (%rax),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     1194 <driver_mfc_erase_sector+0x94>
jmp    117c <driver_mfc_erase_sector+0x7c>
pop    %rbp
ret

x86 assembly (clang, -O2):
<driver_mfc_erase_sector>:
movl   $0xa5,0x800010
movl   $0xc3,0x800014
lea    0x3(%rsi),%eax
test   %esi,%esi
cmovns %esi,%eax
sar    $0x2,%eax
mov    %eax,0x800008
movl   $0x58a9,0x800000
movl   $0xa958,0x800000
movl   $0x8,0x800004
shl    $0x5,%edi
or     %edi,0x800004
orl    $0x1,0x800004
01
nopl   0x0(%rax,%rax,1)
mov    0x800004,%eax
test   $0x1,%al
jne    1160 <driver_mfc_erase_sector+0x60>
ret

LLVM IR (-O0):
define void @driver_mfc_erase_sector(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
store volatile i32 165, i32* inttoptr (i64 8388624 to i32*)
store volatile i32 195, i32* inttoptr (i64 8388628 to i32*)
%5 = load i32, i32* %4
%6 = sdiv i32 %5, 4
store volatile i32 %6, i32* inttoptr (i64 8388616 to i32*)
store volatile i32 22697, i32* inttoptr (i64 8388608 to i32*)
store volatile i32 43352, i32* inttoptr (i64 8388608 to i32*)
store volatile i32 8, i32* inttoptr (i64 8388612 to i32*)
%7 = load i32, i32* %3
%8 = shl i32 %7, 5
%9 = load volatile i32, i32* inttoptr (i64 8388612 to i32*)
%10 = or i32 %9, %8
store volatile i32 %10, i32* inttoptr (i64 8388612 to i32*)
%11 = load volatile i32, i32* inttoptr (i64 8388612 to i32*)
%12 = or i32 %11, 1
store volatile i32 %12, i32* inttoptr (i64 8388612 to i32*)
br label %13
13: ; preds = %17, %2
%14 = load volatile i32, i32* inttoptr (i64 8388612 to i32*)
%15 = and i32 %14, 1
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %13
br label %13
18: ; preds = %13
ret void
}

LLVM IR (-O2):
define void @driver_mfc_erase_sector(i32 %0, i32 %1) {
store volatile i32 165, i32* inttoptr (i64 8388624 to i32*)
store volatile i32 195, i32* inttoptr (i64 8388628 to i32*)
%3 = sdiv i32 %1, 4
store volatile i32 %3, i32* inttoptr (i64 8388616 to i32*)
store volatile i32 22697, i32* inttoptr (i64 8388608 to i32*)
store volatile i32 43352, i32* inttoptr (i64 8388608 to i32*)
store volatile i32 8, i32* inttoptr (i64 8388612 to i32*)
%4 = shl i32 %0, 5
%5 = load volatile i32, i32* inttoptr (i64 8388612 to i32*)
%6 = or i32 %5, %4
store volatile i32 %6, i32* inttoptr (i64 8388612 to i32*)
%7 = load volatile i32, i32* inttoptr (i64 8388612 to i32*)
%8 = or i32 %7, 1
store volatile i32 %8, i32* inttoptr (i64 8388612 to i32*)
br label %9
9: ; preds = %9, %2
%10 = load volatile i32, i32* inttoptr (i64 8388612 to i32*)
%11 = and i32 %10, 1
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %9
13: ; preds = %9
ret void
}