#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*/ cache_sync();
int /*<<< orphan*/ cache_wait(int, int);
int /*<<< orphan*/ l2x0_flush_line(unsigned long);
int /*<<< orphan*/ l2x0_inv_line(unsigned long);
void l2x0_invalid_range(unsigned long start, unsigned long end) {
  if (start & (32 - 1)) {
    start &= ~(32 - 1);
    l2x0_flush_line(start);
    start += 32;
  }
  if (end & (32 - 1)) {
    end &= ~(32 - 1);
    l2x0_flush_line(end);
  }
  while (start < end) {
    unsigned long blk_end =
        start + (end - start < 4096UL ? end - start : 4096UL);
    while (start < blk_end) {
      l2x0_inv_line(start);
      start += 32;
    }
    if (blk_end < end) {
    }
  }
  cache_wait((0xC4200000 + 0x770), 1);
  cache_sync();
}


x86 assembly (clang, -O0):
<l2x0_invalid_range>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
and    $0x1f,%rax
cmp    $0x0,%rax
je     1183 <l2x0_invalid_range+0x43>
mov    -0x8(%rbp),%rax
and    $0xffffffffffffffe0,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <l2x0_flush_line@plt>
mov    -0x8(%rbp),%rax
add    $0x20,%rax
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
and    $0x1f,%rax
cmp    $0x0,%rax
je     11aa <l2x0_invalid_range+0x6a>
mov    -0x10(%rbp),%rax
and    $0xffffffffffffffe0,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <l2x0_flush_line@plt>
jmp    11af <l2x0_invalid_range+0x6f>
mov    -0x8(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    1247 <l2x0_invalid_range+0x107>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
sub    -0x8(%rbp),%rax
cmp    $0x1000,%rax
jae    11ea <l2x0_invalid_range+0xaa>
mov    -0x10(%rbp),%rax
sub    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    11f8 <l2x0_invalid_range+0xb8>
mov    $0x1000,%eax
mov    %rax,-0x28(%rbp)
jmp    11f8 <l2x0_invalid_range+0xb8>
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    122f <l2x0_invalid_range+0xef>
mov    -0x8(%rbp),%rdi
call   1030 <l2x0_inv_line@plt>
mov    -0x8(%rbp),%rax
add    $0x20,%rax
mov    %rax,-0x8(%rbp)
jmp    1207 <l2x0_invalid_range+0xc7>
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    1242 <l2x0_invalid_range+0x102>
jmp    1242 <l2x0_invalid_range+0x102>
jmp    11af <l2x0_invalid_range+0x6f>
mov    $0xc4200770,%edi
mov    $0x1,%esi
call   1060 <cache_wait@plt>
mov    $0x0,%al
call   1050 <cache_sync@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<l2x0_invalid_range>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
test   $0x1f,%bl
je     1163 <l2x0_invalid_range+0x23>
and    $0xffffffffffffffe0,%rbx
mov    %rbx,%rdi
call   1040 <l2x0_flush_line@plt>
add    $0x20,%rbx
test   $0x1f,%r14b
je     1175 <l2x0_invalid_range+0x35>
and    $0xffffffffffffffe0,%r14
mov    %r14,%rdi
call   1040 <l2x0_flush_line@plt>
cmp    %rbx,%r14
jbe    11c3 <l2x0_invalid_range+0x83>
mov    $0x1000,%r15d
jmp    1195 <l2x0_invalid_range+0x55>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
cmp    %rbx,%r14
jbe    11c3 <l2x0_invalid_range+0x83>
mov    %r14,%r12
sub    %rbx,%r12
cmp    $0x1000,%r12
cmovae %r15,%r12
add    %rbx,%r12
cmp    %r12,%rbx
jae    1190 <l2x0_invalid_range+0x50>
xchg   %ax,%ax
mov    %rbx,%rdi
call   1030 <l2x0_inv_line@plt>
add    $0x20,%rbx
cmp    %r12,%rbx
jb     11b0 <l2x0_invalid_range+0x70>
jmp    1190 <l2x0_invalid_range+0x50>
mov    $0xc4200770,%edi
mov    $0x1,%esi
call   1060 <cache_wait@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1050 <cache_sync@plt>

LLVM IR (-O0):
define void @l2x0_invalid_range(i64 %0, i64 %1) {
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
store i64 %0, i64* %3
store i64 %1, i64* %4
%6 = load i64, i64* %3
%7 = and i64 %6, 31
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %16
9: ; preds = %2
%10 = load i64, i64* %3
%11 = and i64 %10, -32
store i64 %11, i64* %3
%12 = load i64, i64* %3
%13 = call i32 @l2x0_flush_line(i64 %12)
%14 = load i64, i64* %3
%15 = add i64 %14, 32
store i64 %15, i64* %3
br label %16
16: ; preds = %9, %2
%17 = load i64, i64* %4
%18 = and i64 %17, 31
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %25
20: ; preds = %16
%21 = load i64, i64* %4
%22 = and i64 %21, -32
store i64 %22, i64* %4
%23 = load i64, i64* %4
%24 = call i32 @l2x0_flush_line(i64 %23)
br label %25
25: ; preds = %20, %16
br label %26
26: ; preds = %58, %25
%27 = load i64, i64* %3
%28 = load i64, i64* %4
%29 = icmp ult i64 %27, %28
br i1 %29, label %30, label %59
30: ; preds = %26
%31 = load i64, i64* %3
%32 = load i64, i64* %4
%33 = load i64, i64* %3
%34 = sub i64 %32, %33
%35 = icmp ult i64 %34, 4096
br i1 %35, label %36, label %40
36: ; preds = %30
%37 = load i64, i64* %4
%38 = load i64, i64* %3
%39 = sub i64 %37, %38
br label %41
40: ; preds = %30
br label %41
41: ; preds = %40, %36
%42 = phi i64 [ %39, %36 ], [ 4096, %40 ]
%43 = add i64 %31, %42
store i64 %43, i64* %5
br label %44
44: ; preds = %48, %41
%45 = load i64, i64* %3
%46 = load i64, i64* %5
%47 = icmp ult i64 %45, %46
br i1 %47, label %48, label %53
48: ; preds = %44
%49 = load i64, i64* %3
%50 = call i32 @l2x0_inv_line(i64 %49)
%51 = load i64, i64* %3
%52 = add i64 %51, 32
store i64 %52, i64* %3
br label %44
53: ; preds = %44
%54 = load i64, i64* %5
%55 = load i64, i64* %4
%56 = icmp ult i64 %54, %55
br i1 %56, label %57, label %58
57: ; preds = %53
br label %58
58: ; preds = %57, %53
br label %26
59: ; preds = %26
%60 = call i32 @cache_wait(i32 -1004533904, i32 1)
%61 = call i32 (...) @cache_sync()
ret void
}

LLVM IR (-O2):
define void @l2x0_invalid_range(i64 %0, i64 %1) {
%3 = and i64 %0, 31
%4 = icmp eq i64 %3, 0
br i1 %4, label %9, label %5
5: ; preds = %2
%6 = and i64 %0, -32
%7 = tail call i32 @l2x0_flush_line(i64 %6)
%8 = add i64 %6, 32
br label %9
9: ; preds = %5, %2
%10 = phi i64 [ %8, %5 ], [ %0, %2 ]
%11 = and i64 %1, 31
%12 = icmp eq i64 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %9
%14 = and i64 %1, -32
%15 = tail call i32 @l2x0_flush_line(i64 %14)
br label %16
16: ; preds = %13, %9
%17 = phi i64 [ %14, %13 ], [ %1, %9 ]
%18 = icmp ugt i64 %17, %10
br i1 %18, label %22, label %34
19: ; preds = %29, %22
%20 = phi i64 [ %23, %22 ], [ %32, %29 ]
%21 = icmp ugt i64 %17, %20
br i1 %21, label %22, label %34
22: ; preds = %16, %19
%23 = phi i64 [ %20, %19 ], [ %10, %16 ]
%24 = sub i64 %17, %23
%25 = icmp ult i64 %24, 4096
%26 = select i1 %25, i64 %24, i64 4096
%27 = add i64 %26, %23
%28 = icmp ult i64 %23, %27
br i1 %28, label %29, label %19
29: ; preds = %22, %29
%30 = phi i64 [ %32, %29 ], [ %23, %22 ]
%31 = tail call i32 @l2x0_inv_line(i64 %30)
%32 = add i64 %30, 32
%33 = icmp ult i64 %32, %27
br i1 %33, label %29, label %19
34: ; preds = %19, %16
%35 = tail call i32 @cache_wait(i32 -1004533904, i32 1)
%36 = tail call i32 (...) @cache_sync()
ret void
}