#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 */
struct pcpu_chunk {
  int dummy;
};
struct page {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ BUG_ON(int);
int /*<<< orphan*/ pcpu_free_pages(struct pcpu_chunk *, struct page **, int,
                                   int);
struct page **pcpu_get_pages(struct pcpu_chunk *);
int /*<<< orphan*/ pcpu_pre_unmap_flush(struct pcpu_chunk *, int, int);
int /*<<< orphan*/ pcpu_unmap_pages(struct pcpu_chunk *, struct page **, int,
                                    int);
void pcpu_depopulate_chunk(struct pcpu_chunk *chunk, int page_start,
                           int page_end) {
  struct page **pages;
  pages = pcpu_get_pages(chunk);
  BUG_ON(!pages);
  pcpu_pre_unmap_flush(chunk, page_start, page_end);
  pcpu_unmap_pages(chunk, pages, page_start, page_end);
  pcpu_free_pages(chunk, pages, page_start, page_end);
}


x86 assembly (clang, -O0):
<pcpu_depopulate_chunk>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <pcpu_get_pages@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%edi
call   1040 <BUG_ON@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1030 <pcpu_pre_unmap_flush@plt>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%ecx
call   1070 <pcpu_unmap_pages@plt>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%ecx
call   1050 <pcpu_free_pages@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pcpu_depopulate_chunk>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %esi,%r15d
mov    %rdi,%rbx
call   1060 <pcpu_get_pages@plt>
mov    %rax,%rbp
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1040 <BUG_ON@plt>
mov    %rbx,%rdi
mov    %r15d,%esi
mov    %r14d,%edx
call   1030 <pcpu_pre_unmap_flush@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %r15d,%edx
mov    %r14d,%ecx
call   1070 <pcpu_unmap_pages@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %r15d,%edx
mov    %r14d,%ecx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <pcpu_free_pages@plt>

LLVM IR (-O0):
%struct.pcpu_chunk = type { i32 }
%struct.page = type { i32 }
define void @pcpu_depopulate_chunk(%struct.pcpu_chunk* %0, i32 %1, i32 %2) {
%4 = alloca %struct.pcpu_chunk*
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.page**
store %struct.pcpu_chunk* %0, %struct.pcpu_chunk** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%8 = load %struct.pcpu_chunk*, %struct.pcpu_chunk** %4
%9 = call %struct.page** @pcpu_get_pages(%struct.pcpu_chunk* %8)
store %struct.page** %9, %struct.page*** %7
%10 = load %struct.page**, %struct.page*** %7
%11 = icmp ne %struct.page** %10, null
%12 = xor i1 %11, true
%13 = zext i1 %12 to i32
%14 = call i32 @BUG_ON(i32 %13)
%15 = load %struct.pcpu_chunk*, %struct.pcpu_chunk** %4
%16 = load i32, i32* %5
%17 = load i32, i32* %6
%18 = call i32 @pcpu_pre_unmap_flush(%struct.pcpu_chunk* %15, i32 %16, i32 %17)
%19 = load %struct.pcpu_chunk*, %struct.pcpu_chunk** %4
%20 = load %struct.page**, %struct.page*** %7
%21 = load i32, i32* %5
%22 = load i32, i32* %6
%23 = call i32 @pcpu_unmap_pages(%struct.pcpu_chunk* %19, %struct.page** %20, i32 %21, i32 %22)
%24 = load %struct.pcpu_chunk*, %struct.pcpu_chunk** %4
%25 = load %struct.page**, %struct.page*** %7
%26 = load i32, i32* %5
%27 = load i32, i32* %6
%28 = call i32 @pcpu_free_pages(%struct.pcpu_chunk* %24, %struct.page** %25, i32 %26, i32 %27)
ret void
}

LLVM IR (-O2):
%struct.pcpu_chunk = type { i32 }
%struct.page = type { i32 }
define void @pcpu_depopulate_chunk(%struct.pcpu_chunk* %0, i32 %1, i32 %2) {
%4 = tail call %struct.page** @pcpu_get_pages(%struct.pcpu_chunk* %0)
%5 = icmp eq %struct.page** %4, null
%6 = zext i1 %5 to i32
%7 = tail call i32 @BUG_ON(i32 %6)
%8 = tail call i32 @pcpu_pre_unmap_flush(%struct.pcpu_chunk* %0, i32 %1, i32 %2)
%9 = tail call i32 @pcpu_unmap_pages(%struct.pcpu_chunk* %0, %struct.page** %4, i32 %1, i32 %2)
%10 = tail call i32 @pcpu_free_pages(%struct.pcpu_chunk* %0, %struct.page** %4, i32 %1, i32 %2)
ret void
}