#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 */
unsigned int io_load_eflags();
int /*<<< orphan*/ io_store_eflags(unsigned int);
unsigned int load_cr0();
unsigned int memory_test_sub(unsigned int, unsigned int);
int /*<<< orphan*/ store_cr0(unsigned int);
unsigned int memory_test(unsigned int start, unsigned int end) {
  char flag486 = 0;
  unsigned int eflags, cr0, address;
  eflags = io_load_eflags();
  eflags |= (0x00040000);
  io_store_eflags(eflags);
  if (0 != (eflags & (0x00040000)))
    flag486 = 1;
  eflags &= ~(0x00040000);
  io_store_eflags(eflags);
  if (0 != flag486) {
    cr0 = load_cr0();
    cr0 |= (0x60000000);
    store_cr0(cr0);
  }
  address = memory_test_sub(start, end);
  if (0 != flag486) {
    cr0 = load_cr0();
    cr0 &= ~(0x60000000);
    store_cr0(cr0);
  }
  return address;
}


x86 assembly (clang, -O0):
<memory_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movb   $0x0,-0x9(%rbp)
mov    $0x0,%al
call   1040 <io_load_eflags@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
or     $0x40000,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%edi
call   1070 <io_store_eflags@plt>
mov    -0x10(%rbp),%ecx
and    $0x40000,%ecx
xor    %eax,%eax
cmp    %ecx,%eax
je     1196 <memory_test+0x46>
movb   $0x1,-0x9(%rbp)
mov    -0x10(%rbp),%eax
and    $0xfffbffff,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%edi
call   1070 <io_store_eflags@plt>
movsbl -0x9(%rbp),%ecx
xor    %eax,%eax
cmp    %ecx,%eax
je     11d4 <memory_test+0x84>
mov    $0x0,%al
call   1030 <load_cr0@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
or     $0x60000000,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1050 <store_cr0@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1060 <memory_test_sub@plt>
mov    %eax,-0x18(%rbp)
movsbl -0x9(%rbp),%ecx
xor    %eax,%eax
cmp    %ecx,%eax
je     120d <memory_test+0xbd>
mov    $0x0,%al
call   1030 <load_cr0@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
and    $0x9fffffff,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1050 <store_cr0@plt>
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<memory_test>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%r14d
mov    %edi,%ebp
xor    %eax,%eax
call   1040 <io_load_eflags@plt>
mov    %eax,%ebx
mov    %eax,%edi
or     $0x40000,%edi
call   1070 <io_store_eflags@plt>
and    $0xfffbffff,%ebx
mov    %ebx,%edi
call   1070 <io_store_eflags@plt>
xor    %eax,%eax
call   1030 <load_cr0@plt>
or     $0x60000000,%eax
mov    %eax,%edi
call   1050 <store_cr0@plt>
mov    %ebp,%edi
mov    %r14d,%esi
call   1060 <memory_test_sub@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1030 <load_cr0@plt>
and    $0x9fffffff,%eax
mov    %eax,%edi
call   1050 <store_cr0@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @memory_test(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
store i8 0, i8* %5
%9 = call i32 (...) @io_load_eflags()
store i32 %9, i32* %6
%10 = load i32, i32* %6
%11 = or i32 %10, 262144
store i32 %11, i32* %6
%12 = load i32, i32* %6
%13 = call i32 @io_store_eflags(i32 %12)
%14 = load i32, i32* %6
%15 = and i32 %14, 262144
%16 = icmp ne i32 0, %15
br i1 %16, label %17, label %18
17: ; preds = %2
store i8 1, i8* %5
br label %18
18: ; preds = %17, %2
%19 = load i32, i32* %6
%20 = and i32 %19, -262145
store i32 %20, i32* %6
%21 = load i32, i32* %6
%22 = call i32 @io_store_eflags(i32 %21)
%23 = load i8, i8* %5
%24 = sext i8 %23 to i32
%25 = icmp ne i32 0, %24
br i1 %25, label %26, label %32
26: ; preds = %18
%27 = call i32 (...) @load_cr0()
store i32 %27, i32* %7
%28 = load i32, i32* %7
%29 = or i32 %28, 1610612736
store i32 %29, i32* %7
%30 = load i32, i32* %7
%31 = call i32 @store_cr0(i32 %30)
br label %32
32: ; preds = %26, %18
%33 = load i32, i32* %3
%34 = load i32, i32* %4
%35 = call i32 @memory_test_sub(i32 %33, i32 %34)
store i32 %35, i32* %8
%36 = load i8, i8* %5
%37 = sext i8 %36 to i32
%38 = icmp ne i32 0, %37
br i1 %38, label %39, label %45
39: ; preds = %32
%40 = call i32 (...) @load_cr0()
store i32 %40, i32* %7
%41 = load i32, i32* %7
%42 = and i32 %41, -1610612737
store i32 %42, i32* %7
%43 = load i32, i32* %7
%44 = call i32 @store_cr0(i32 %43)
br label %45
45: ; preds = %39, %32
%46 = load i32, i32* %8
ret i32 %46
}

LLVM IR (-O2):
define i32 @memory_test(i32 %0, i32 %1) {
%3 = tail call i32 (...) @io_load_eflags()
%4 = or i32 %3, 262144
%5 = tail call i32 @io_store_eflags(i32 %4)
%6 = and i32 %3, -262145
%7 = tail call i32 @io_store_eflags(i32 %6)
%8 = tail call i32 (...) @load_cr0()
%9 = or i32 %8, 1610612736
%10 = tail call i32 @store_cr0(i32 %9)
%11 = tail call i32 @memory_test_sub(i32 %0, i32 %1)
%12 = tail call i32 (...) @load_cr0()
%13 = and i32 %12, -1610612737
%14 = tail call i32 @store_cr0(i32 %13)
ret i32 %11
}