#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();
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();
  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    $0x0,%al
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
xor    %eax,%eax
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 = call %struct.page** (...) @pcpu_get_pages()
store %struct.page** %8, %struct.page*** %7
%9 = load %struct.page**, %struct.page*** %7
%10 = icmp ne %struct.page** %9, null
%11 = xor i1 %10, true
%12 = zext i1 %11 to i32
%13 = call i32 @BUG_ON(i32 %12)
%14 = load %struct.pcpu_chunk*, %struct.pcpu_chunk** %4
%15 = load i32, i32* %5
%16 = load i32, i32* %6
%17 = call i32 @pcpu_pre_unmap_flush(%struct.pcpu_chunk* %14, i32 %15, i32 %16)
%18 = load %struct.pcpu_chunk*, %struct.pcpu_chunk** %4
%19 = load %struct.page**, %struct.page*** %7
%20 = load i32, i32* %5
%21 = load i32, i32* %6
%22 = call i32 @pcpu_unmap_pages(%struct.pcpu_chunk* %18, %struct.page** %19, i32 %20, i32 %21)
%23 = load %struct.pcpu_chunk*, %struct.pcpu_chunk** %4
%24 = load %struct.page**, %struct.page*** %7
%25 = load i32, i32* %5
%26 = load i32, i32* %6
%27 = call i32 @pcpu_free_pages(%struct.pcpu_chunk* %23, %struct.page** %24, i32 %25, i32 %26)
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()
%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
}