#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*/ DCSMGrabRAMBlocks();
unsigned long DCSMGetFlashSectorZone(unsigned long sector) {
  unsigned long z1_status;
  unsigned long z2_status;
  unsigned long shift_value;
  ;
  DCSMGrabRAMBlocks();
  shift_value = (sector - 1) << 1;
  z1_status = ((*((volatile unsigned long *)(0x400FB400 + 0x00000090))) >>
               shift_value) &
              0x00000003;
  z2_status = ((*((volatile unsigned long *)(0x400FB400 + 0x00000098))) >>
               shift_value) &
              0x00000003;
  if ((z1_status & z2_status) == 0x3) {
    return (3);
  } else if ((z1_status == 0x3) && ((z2_status == 0x2) || (z2_status == 0x1))) {
    return (2);
  } else if ((z2_status == 0x3) && ((z1_status == 0x2) || (z1_status == 0x1))) {
    return (1);
  } else {
    return (0);
  }
}


x86 assembly (clang, -O0):
<DCSMGetFlashSectorZone>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x0,%al
call   1030 <DCSMGrabRAMBlocks@plt>
mov    -0x10(%rbp),%rax
sub    $0x1,%rax
shl    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    $0x400fb490,%eax
mov    (%rax),%rax
mov    -0x28(%rbp),%rcx
shr    %cl,%rax
and    $0x3,%rax
mov    %rax,-0x18(%rbp)
mov    $0x400fb498,%eax
mov    (%rax),%rax
mov    -0x28(%rbp),%rcx
shr    %cl,%rax
and    $0x3,%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
and    -0x20(%rbp),%rax
cmp    $0x3,%rax
jne    1180 <DCSMGetFlashSectorZone+0x70>
movq   $0x3,-0x8(%rbp)
jmp    11e4 <DCSMGetFlashSectorZone+0xd4>
cmpq   $0x3,-0x18(%rbp)
jne    11ae <DCSMGetFlashSectorZone+0x9e>
cmpq   $0x2,-0x20(%rbp)
je     11a1 <DCSMGetFlashSectorZone+0x91>
cmpq   $0x1,-0x20(%rbp)
jne    11ae <DCSMGetFlashSectorZone+0x9e>
movq   $0x2,-0x8(%rbp)
jmp    11e4 <DCSMGetFlashSectorZone+0xd4>
cmpq   $0x3,-0x20(%rbp)
jne    11dc <DCSMGetFlashSectorZone+0xcc>
cmpq   $0x2,-0x18(%rbp)
je     11cf <DCSMGetFlashSectorZone+0xbf>
cmpq   $0x1,-0x18(%rbp)
jne    11dc <DCSMGetFlashSectorZone+0xcc>
movq   $0x1,-0x8(%rbp)
jmp    11e4 <DCSMGetFlashSectorZone+0xd4>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<DCSMGetFlashSectorZone>:
push   %rbx
mov    %rdi,%rbx
xor    %eax,%eax
call   1030 <DCSMGrabRAMBlocks@plt>
add    %ebx,%ebx
mov    0x400fb490,%rdx
40
add    $0xfe,%bl
mov    %ebx,%ecx
shr    %cl,%rdx
mov    0x400fb498,%rsi
40
shr    %cl,%rsi
and    $0x3,%esi
mov    %esi,%ecx
and    %edx,%ecx
mov    $0x3,%eax
cmp    $0x3,%ecx
je     1160 <DCSMGetFlashSectorZone+0x50>
and    $0x3,%edx
cmp    $0x3,%edx
jne    1162 <DCSMGetFlashSectorZone+0x52>
lea    -0x1(%rsi),%rcx
mov    $0x2,%eax
cmp    $0x2,%rcx
jae    1162 <DCSMGetFlashSectorZone+0x52>
pop    %rbx
ret
cmp    $0x3,%esi
sete   %al
add    $0xffffffffffffffff,%rdx
cmp    $0x2,%rdx
setb   %cl
and    %al,%cl
movzbl %cl,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i64 @DCSMGetFlashSectorZone(i64 %0) {
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
store i64 %0, i64* %3
%7 = call i32 (...) @DCSMGrabRAMBlocks()
%8 = load i64, i64* %3
%9 = sub i64 %8, 1
%10 = shl i64 %9, 1
store i64 %10, i64* %6
%11 = load volatile i64, i64* inttoptr (i64 1074771088 to i64*)
%12 = load i64, i64* %6
%13 = lshr i64 %11, %12
%14 = and i64 %13, 3
store i64 %14, i64* %4
%15 = load volatile i64, i64* inttoptr (i64 1074771096 to i64*)
%16 = load i64, i64* %6
%17 = lshr i64 %15, %16
%18 = and i64 %17, 3
store i64 %18, i64* %5
%19 = load i64, i64* %4
%20 = load i64, i64* %5
%21 = and i64 %19, %20
%22 = icmp eq i64 %21, 3
br i1 %22, label %23, label %24
23: ; preds = %1
store i64 3, i64* %2
br label %45
24: ; preds = %1
%25 = load i64, i64* %4
%26 = icmp eq i64 %25, 3
br i1 %26, label %27, label %34
27: ; preds = %24
%28 = load i64, i64* %5
%29 = icmp eq i64 %28, 2
br i1 %29, label %33, label %30
30: ; preds = %27
%31 = load i64, i64* %5
%32 = icmp eq i64 %31, 1
br i1 %32, label %33, label %34
33: ; preds = %30, %27
store i64 2, i64* %2
br label %45
34: ; preds = %30, %24
%35 = load i64, i64* %5
%36 = icmp eq i64 %35, 3
br i1 %36, label %37, label %44
37: ; preds = %34
%38 = load i64, i64* %4
%39 = icmp eq i64 %38, 2
br i1 %39, label %43, label %40
40: ; preds = %37
%41 = load i64, i64* %4
%42 = icmp eq i64 %41, 1
br i1 %42, label %43, label %44
43: ; preds = %40, %37
store i64 1, i64* %2
br label %45
44: ; preds = %40, %34
store i64 0, i64* %2
br label %45
45: ; preds = %44, %43, %33, %23
%46 = load i64, i64* %2
ret i64 %46
}

LLVM IR (-O2):
define i64 @DCSMGetFlashSectorZone(i64 %0) {
%2 = tail call i32 (...) @DCSMGrabRAMBlocks()
%3 = shl i64 %0, 1
%4 = add i64 %3, -2
%5 = load volatile i64, i64* inttoptr (i64 1074771088 to i64*)
%6 = lshr i64 %5, %4
%7 = and i64 %6, 3
%8 = load volatile i64, i64* inttoptr (i64 1074771096 to i64*)
%9 = lshr i64 %8, %4
%10 = and i64 %9, 3
%11 = and i64 %10, %6
%12 = icmp eq i64 %11, 3
br i1 %12, label %24, label %13
13: ; preds = %1
%14 = icmp eq i64 %7, 3
%15 = add nsw i64 %10, -1
%16 = icmp ult i64 %15, 2
%17 = select i1 %14, i1 %16, i1 false
br i1 %17, label %24, label %18
18: ; preds = %13
%19 = icmp eq i64 %10, 3
%20 = add nsw i64 %7, -1
%21 = icmp ult i64 %20, 2
%22 = select i1 %19, i1 %21, i1 false
%23 = zext i1 %22 to i64
br label %24
24: ; preds = %18, %13, %1
%25 = phi i64 [ 3, %1 ], [ 2, %13 ], [ %23, %18 ]
ret i64 %25
}