#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*/ deallocate_frame(int /*<<< orphan*/);
int /*<<< orphan*/ get_physical_address(void *);
int /*<<< orphan*/ unmap_page(void *);
void deallocate_contiguous_vframe(void *vframe, unsigned int size) {
  unsigned int num_of_frames = (size / 0x1000);
  if (size % 0x1000) {
    num_of_frames++;
  }
  for (int i = 0; i < num_of_frames; i++) {
    deallocate_frame(get_physical_address(vframe + 0x1000 * i));
    unmap_page(vframe + 0x1000 * i);
  }
}


x86 assembly (clang, -O0):
<deallocate_contiguous_vframe>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
shr    $0xc,%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
and    $0xfff,%eax
cmp    $0x0,%eax
je     1162 <deallocate_contiguous_vframe+0x32>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
jae    11b2 <deallocate_contiguous_vframe+0x82>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%eax
shl    $0xc,%eax
cltq
add    %rax,%rdi
call   1050 <get_physical_address@plt>
mov    %eax,%edi
call   1040 <deallocate_frame@plt>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%eax
shl    $0xc,%eax
cltq
add    %rax,%rdi
call   1030 <unmap_page@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1169 <deallocate_contiguous_vframe+0x39>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<deallocate_contiguous_vframe>:
push   %r14
push   %rbx
push   %rax
mov    %esi,%ecx
shr    $0xc,%ecx
xor    %eax,%eax
test   $0xfff,%esi
setne  %al
add    %ecx,%eax
je     1174 <deallocate_contiguous_vframe+0x44>
mov    %rdi,%rbx
mov    %eax,%r14d
xchg   %ax,%ax
mov    %rbx,%rdi
call   1050 <get_physical_address@plt>
mov    %eax,%edi
call   1040 <deallocate_frame@plt>
mov    %rbx,%rdi
call   1030 <unmap_page@plt>
add    $0x1000,%rbx
add    $0xffffffffffffffff,%r14
jne    1150 <deallocate_contiguous_vframe+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @deallocate_contiguous_vframe(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%7 = load i32, i32* %4
%8 = udiv i32 %7, 4096
store i32 %8, i32* %5
%9 = load i32, i32* %4
%10 = urem i32 %9, 4096
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = load i32, i32* %5
%14 = add i32 %13, 1
store i32 %14, i32* %5
br label %15
15: ; preds = %12, %2
store i32 0, i32* %6
br label %16
16: ; preds = %34, %15
%17 = load i32, i32* %6
%18 = load i32, i32* %5
%19 = icmp ult i32 %17, %18
br i1 %19, label %20, label %37
20: ; preds = %16
%21 = load i8*, i8** %3
%22 = load i32, i32* %6
%23 = mul nsw i32 4096, %22
%24 = sext i32 %23 to i64
%25 = getelementptr i8, i8* %21, i64 %24
%26 = call i32 @get_physical_address(i8* %25)
%27 = call i32 @deallocate_frame(i32 %26)
%28 = load i8*, i8** %3
%29 = load i32, i32* %6
%30 = mul nsw i32 4096, %29
%31 = sext i32 %30 to i64
%32 = getelementptr i8, i8* %28, i64 %31
%33 = call i32 @unmap_page(i8* %32)
br label %34
34: ; preds = %20
%35 = load i32, i32* %6
%36 = add nsw i32 %35, 1
store i32 %36, i32* %6
br label %16
37: ; preds = %16
ret void
}

LLVM IR (-O2):
define void @deallocate_contiguous_vframe(i8* %0, i32 %1) {
%3 = lshr i32 %1, 12
%4 = and i32 %1, 4095
%5 = icmp ne i32 %4, 0
%6 = zext i1 %5 to i32
%7 = add nuw nsw i32 %3, %6
%8 = icmp eq i32 %7, 0
br i1 %8, label %11, label %9
9: ; preds = %2
%10 = zext i32 %7 to i64
br label %12
11: ; preds = %12, %2
ret void
12: ; preds = %9, %12
%13 = phi i64 [ 0, %9 ], [ %19, %12 ]
%14 = shl nsw i64 %13, 12
%15 = getelementptr i8, i8* %0, i64 %14
%16 = tail call i32 @get_physical_address(i8* %15)
%17 = tail call i32 @deallocate_frame(i32 %16)
%18 = tail call i32 @unmap_page(i8* %15)
%19 = add nuw nsw i64 %13, 1
%20 = icmp eq i64 %19, %10
br i1 %20, label %11, label %12
}