LLM4Binary/decompile-bench-makefile huggingface dataset:
// File: /workspace/github_c_makefile_star2_O0/krinkinmu[P]64bit/kmem_cache.c
// Function: kmem_small_cache_create
static struct kmem_cache *kmem_small_cache_create(size_t size, size_t align)
{
	struct kmem_small_cache *cache =
		kmem_cache_alloc((struct kmem_cache *)&kmem_small_cache_cache);

	if (!cache)
		return 0;

	kmem_small_cache_init(cache, size, align);

	return (struct kmem_cache *)cache;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
leaq 0x32af39(%rip), %rdi    # 0xffffffff80432340
callq 0xffffffff80106fd0
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0xffffffff80107421
movq $0x0, -0x8(%rbp)
jmp 0xffffffff8010743a
movq -0x20(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0xffffffff80107800
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/krinkinmu[P]64bit/kmem_cache.c
// Function: kmem_large_cache_create
static struct kmem_cache *kmem_large_cache_create(size_t size, size_t align)
{
	struct kmem_large_cache *cache =
		kmem_cache_alloc((struct kmem_cache *)&kmem_large_cache_cache);

	if (!cache)
		return 0;

	kmem_large_cache_init(cache, size, align);

	return (struct kmem_cache *)cache;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
leaq 0x32af39(%rip), %rdi    # 0xffffffff804323a0
callq 0xffffffff80106fd0
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0xffffffff80107481
movq $0x0, -0x8(%rbp)
jmp 0xffffffff8010749a
movq -0x20(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0xffffffff80107b20
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/krinkinmu[P]64bit/kmem_cache.c
// Function: kmem_cache_destroy
void kmem_cache_destroy(struct kmem_cache *cache)
{
	kmem_cache_reap(cache);

	if (!list_empty(&cache->part_list))
		return;

	if (!list_empty(&cache->full_list))
		return;

	kmem_cache_free(kmem_get_slab(cache)->cache, cache);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x10, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
callq 0xffffffff80106ec0
movq -0x8(%rbp), %rdi
addq $0x8, %rdi
callq 0xffffffff801012f0
testb $0x1, %al
jne 0xffffffff801074d8
jmp 0xffffffff80107501
movq -0x8(%rbp), %rdi
addq $0x28, %rdi
callq 0xffffffff801012f0
testb $0x1, %al
jne 0xffffffff801074eb
jmp 0xffffffff80107501
movq -0x8(%rbp), %rdi
callq 0xffffffff80107340
movq 0x18(%rax), %rdi
movq -0x8(%rbp), %rsi
callq 0xffffffff80107260
addq $0x10, %rsp
popq %rbp
retq
nopw (%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/krinkinmu[P]64bit/kmem_cache.c
// Function: kmem_alloc
void *kmem_alloc(size_t size)
{
	const int i = kmem_cache_index(size);

	if (i == -1)
		return 0;

	return kmem_cache_alloc(kmem_pool[i]);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rdi
callq 0xffffffff80107560
movl %eax, -0x14(%rbp)
cmpl $-0x1, -0x14(%rbp)
jne 0xffffffff80107538
movq $0x0, -0x8(%rbp)
jmp 0xffffffff80107550
movslq -0x14(%rbp), %rcx
leaq 0x32aced(%rip), %rax    # 0xffffffff80432230
movq (%rax,%rcx,8), %rdi
callq 0xffffffff80106fd0
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x20, %rsp
popq %rbp
retq
nopw (%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/krinkinmu[P]64bit/kmem_cache.c
// Function: kmem_cache_index
static int kmem_cache_index(size_t size)
{
	for (int i = 0; i != KMEM_POOLS; ++i) {
		if (size <= kmem_size[i])
			return i;
	}
	return -1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x10(%rbp)
movl $0x0, -0x14(%rbp)
movslq -0x14(%rbp), %rax
cmpq $0x22, %rax
je 0xffffffff801075a3
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rdx
leaq 0xaaa8(%rip), %rcx      # 0xffffffff80112030
cmpq (%rcx,%rdx,8), %rax
ja 0xffffffff80107596
movl -0x14(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0xffffffff801075aa
jmp 0xffffffff80107598
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0xffffffff8010756f
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
popq %rbp
retq
nop
// File: /workspace/github_c_makefile_star2_O0/krinkinmu[P]64bit/kmem_cache.c
// Function: kmem_free
void kmem_free(void *ptr)
{
	if (!ptr)
		return;

	struct kmem_slab *slab = kmem_get_slab(ptr);

	if (!slab)
		return;

	kmem_cache_free(slab->cache, ptr);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x10, %rsp
movq %rdi, -0x8(%rbp)
cmpq $0x0, -0x8(%rbp)
jne 0xffffffff801075c5
jmp 0xffffffff801075ec
movq -0x8(%rbp), %rdi
callq 0xffffffff80107340
movq %rax, -0x10(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0xffffffff801075db
jmp 0xffffffff801075ec
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x8(%rbp), %rsi
callq 0xffffffff80107260
addq $0x10, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/krinkinmu[P]64bit/kmem_cache.c
// Function: setup_alloc
void setup_alloc(void)
{
	kmem_small_cache_setup();
	kmem_large_cache_setup();

	for (int i = 0; i != KMEM_POOLS; ++i) {
		kmem_pool[i] = kmem_cache_create(kmem_size[i], sizeof(void *));
		DBG_ASSERT(kmem_pool[i] != 0);
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x10, %rsp
callq 0xffffffff801076b0
callq 0xffffffff801076d0
movl $0x0, -0x4(%rbp)
movslq -0x4(%rbp), %rax
cmpq $0x22, %rax
je 0xffffffff801076a1
movslq -0x4(%rbp), %rcx
leaq 0xaa02(%rip), %rax      # 0xffffffff80112030
movq (%rax,%rcx,8), %rdi
movl $0x8, %esi
callq 0xffffffff80107380
movq %rax, %rdx
movslq -0x4(%rbp), %rcx
leaq 0x32abe6(%rip), %rax    # 0xffffffff80432230
movq %rdx, (%rax,%rcx,8)
movslq -0x4(%rbp), %rcx
leaq 0x32abd7(%rip), %rax    # 0xffffffff80432230
cmpq $0x0, (%rax,%rcx,8)
jne 0xffffffff8010768f
leaq 0xab12(%rip), %rdi      # 0xffffffff80112179
leaq 0xb062(%rip), %rsi      # 0xffffffff801126d0
movl $0x214, %edx            # imm = 0x214
leaq 0xab03(%rip), %rcx      # 0xffffffff8011217d
leaq 0xb05c(%rip), %r8       # 0xffffffff801126dd
movb $0x0, %al
callq 0xffffffff80101e60
callq 0xffffffff80111cd0
jmp 0xffffffff8010768d
jmp 0xffffffff80107691
jmp 0xffffffff80107693
movl -0x4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4(%rbp)
jmp 0xffffffff80107619
addq $0x10, %rsp
popq %rbp
retq
nopw (%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/krinkinmu[P]64bit/kmem_cache.c
// Function: kmem_small_cache_init
static void kmem_small_cache_init(struct kmem_small_cache *cache,
			size_t size, size_t align)
{
	const size_t sz = sizeof(struct kmem_border_tag);
	const size_t al = ALIGN_OF(struct kmem_border_tag);

	size = ALIGN(size, al);
	align = MAXU(align, al);

	cache->common.ops = &small_cache_ops;
	cache->common.object_size = size;
	cache->common.order = 0;

	cache->padded_size = ALIGN(size + sz, align);

	kmem_cache_init(&cache->common);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq $0x8, -0x20(%rbp)
movq $0x8, -0x28(%rbp)
movq -0x10(%rbp), %rdi
movl $0x8, %esi
callq 0xffffffff801078a0
movq %rax, -0x10(%rbp)
movq -0x18(%rbp), %rdi
movl $0x8, %esi
callq 0xffffffff801078d0
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rax
leaq 0x1075d(%rip), %rcx     # 0xffffffff80117fb0
movq %rcx, (%rax)
movq -0x10(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x48(%rax)
movq -0x8(%rbp), %rax
movl $0x0, 0x50(%rax)
movq -0x10(%rbp), %rdi
addq $0x8, %rdi
movq -0x18(%rbp), %rsi
callq 0xffffffff801078a0
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x58(%rax)
movq -0x8(%rbp), %rdi
callq 0xffffffff80107900
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/krinkinmu[P]64bit/kmem_cache.c
// Function: kmem_cache_init
static void kmem_cache_init(struct kmem_cache *cache)
{
	list_init(&cache->free_list);
	list_init(&cache->part_list);
	list_init(&cache->full_list);
	spinlock_init(&cache->lock);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x10, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
addq $0x18, %rdi
callq 0xffffffff80101190
movq -0x8(%rbp), %rdi
addq $0x8, %rdi
callq 0xffffffff80101190
movq -0x8(%rbp), %rdi
addq $0x28, %rdi
callq 0xffffffff80101190
movq -0x8(%rbp), %rdi
addq $0x38, %rdi
callq 0xffffffff80107b00
addq $0x10, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/krinkinmu[P]64bit/kmem_cache.c
// Function: kmem_small_slab_create
static struct kmem_slab *kmem_small_slab_create(struct kmem_cache *cache,
			struct page *page)
{
	struct kmem_small_cache *small = (struct kmem_small_cache *)cache;

	const pfn_t pages = (pfn_t)1 << cache->order;
	const size_t size = PAGE_SIZE * pages;
	const size_t off = size - sizeof(struct kmem_small_slab);

	char *vaddr = VA(page2pfn(page) << PAGE_BITS);
	struct kmem_small_slab *slab = (struct kmem_small_slab *)(vaddr + off);

	slab->common.ops = &small_slab_ops;
	slab->common.total = 0;
	slab->common.free = 0;
	slab->free_list = 0;

	const size_t sz = small->padded_size;

	for (char *ptr = vaddr; ptr + sz <= (char *)slab; ptr += sz) {
		kmem_small_slab_free(cache, &slab->common, ptr);
		++slab->common.total;
		++slab->common.free;
	}

	return (struct kmem_slab *)slab;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rax
movl 0x50(%rax), %eax
movl %eax, %ecx
movl $0x1, %eax
shlq %cl, %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
shlq $0xc, %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
subq $0x40, %rax
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rdi
callq 0xffffffff80103dd0
shlq $0xc, %rax
movabsq $-0x800000000000, %rcx # imm = 0xFFFF800000000000
addq %rcx, %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
addq -0x30(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
leaq 0x105f6(%rip), %rcx     # 0xffffffff80117fc0
movq %rcx, 0x10(%rax)
movq -0x40(%rbp), %rax
movq $0x0, 0x30(%rax)
movq -0x40(%rbp), %rax
movq $0x0, 0x28(%rax)
movq -0x40(%rbp), %rax
movq $0x0, 0x38(%rax)
movq -0x18(%rbp), %rax
movq 0x58(%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
addq -0x48(%rbp), %rax
cmpq -0x40(%rbp), %rax
ja 0xffffffff80107a53
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq -0x50(%rbp), %rdx
callq 0xffffffff80107a60
movq -0x40(%rbp), %rax
movq 0x30(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x30(%rax)
movq -0x40(%rbp), %rax
movq 0x28(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x28(%rax)
movq -0x48(%rbp), %rax
addq -0x50(%rbp), %rax
movq %rax, -0x50(%rbp)
jmp 0xffffffff80107a06
movq -0x40(%rbp), %rax
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)
// File: /workspace/github_c_makefile_star2_O0/krinkinmu[P]64bit/kmem_cache.c
// Function: kmem_small_slab_free
static void kmem_small_slab_free(struct kmem_cache *c,
			struct kmem_slab *s, void *ptr)
{
	struct kmem_small_slab *slab = (struct kmem_small_slab *)s;
	struct kmem_border_tag *tag = (void *)((char *)ptr + c->object_size);

	(void) c;

	tag->next = slab->free_list;
	slab->free_list = tag;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rax
movq -0x8(%rbp), %rcx
addq 0x48(%rcx), %rax
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rax
movq 0x38(%rax), %rcx
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
movq -0x28(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x38(%rax)
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/krinkinmu[P]64bit/kmem_cache.c
// Function: kmem_small_slab_alloc
static void *kmem_small_slab_alloc(struct kmem_cache *c, struct kmem_slab *p)
{
	struct kmem_small_slab *slab = (struct kmem_small_slab *)p;
	struct kmem_border_tag *tag = slab->free_list;

	(void) c;

	slab->free_list = tag->next;

	return ((char *)tag) - c->object_size;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq (%rax), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x38(%rax)
movq -0x20(%rbp), %rax
movq -0x8(%rbp), %rdx
xorl %ecx, %ecx
subq 0x48(%rdx), %rcx
addq %rcx, %rax
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/krinkinmu[P]64bit/kmem_cache.c
// Function: kmem_large_cache_init
static void kmem_large_cache_init(struct kmem_large_cache *cache,
			size_t size, size_t align)
{
	const size_t object_size = ALIGN(size, align);

	int order = 0;

	for (; order != BUDDY_ORDERS; ++order) {
		const size_t bytes = (PAGE_SIZE << order);

		if (bytes / object_size >= 8)
			break;
	}

	cache->common.object_size = object_size;
	cache->common.order = order;
	cache->common.ops = &large_cache_ops;

	cache->slab_cache = (struct kmem_cache *)&kmem_large_slab_cache;
	cache->tag_cache = (struct kmem_cache *)&kmem_large_tag_cache;

	kmem_cache_init(&cache->common);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0xffffffff801078a0
movq %rax, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
cmpl $0xc, -0x24(%rbp)
je 0xffffffff80107b84
movl -0x24(%rbp), %eax
movl %eax, %ecx
movl $0x1000, %eax           # imm = 0x1000
shlq %cl, %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
xorl %ecx, %ecx
movl %ecx, %edx
divq -0x20(%rbp)
cmpq $0x8, %rax
jb 0xffffffff80107b77
jmp 0xffffffff80107b84
jmp 0xffffffff80107b79
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0xffffffff80107b4c
movq -0x20(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x48(%rax)
movl -0x24(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x50(%rax)
movq -0x8(%rbp), %rax
leaq 0x1042b(%rip), %rcx     # 0xffffffff80117fd0
movq %rcx, (%rax)
movq -0x8(%rbp), %rax
leaq 0x32a84d(%rip), %rcx    # 0xffffffff80432400
movq %rcx, 0x58(%rax)
movq -0x8(%rbp), %rax
leaq 0x32a89e(%rip), %rcx    # 0xffffffff80432460
movq %rcx, 0x60(%rax)
movq -0x8(%rbp), %rdi
callq 0xffffffff80107900
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/krinkinmu[P]64bit/kmem_cache.c
// Function: kmem_large_slab_create
static struct kmem_slab *kmem_large_slab_create(struct kmem_cache *c,
			struct page *page)
{
	struct kmem_large_cache *cache = (struct kmem_large_cache *)c;
	struct kmem_large_slab *slab = kmem_cache_alloc(cache->slab_cache);

	if (!slab)
		return 0;

	const pfn_t pfs = (pfn_t)1 << c->order;
	const size_t count = (pfs << PAGE_BITS) / c->object_size;
	char *ptr = VA(page2pfn(page) << PAGE_BITS);

	slab->common.ops = &large_slab_ops;
	slab->common.total = count;
	slab->common.free = count;

	for (size_t i = 0; i != count; ++i, ptr += c->object_size) {
		struct kmem_tag *tag = kmem_cache_alloc(cache->tag_cache);

		if (!tag) {
			kmem_large_slab_release(cache, slab);
			return 0;
		}

		tag->next = slab->free;
		tag->ptr = ptr;
		slab->free = tag;
	}

	return (struct kmem_slab *)slab;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq 0x58(%rax), %rdi
callq 0xffffffff80106fd0
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0xffffffff80107c1d
movq $0x0, -0x8(%rbp)
jmp 0xffffffff80107d1b
movq -0x10(%rbp), %rax
movl 0x50(%rax), %eax
movl %eax, %ecx
movl $0x1, %eax
shlq %cl, %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
shlq $0xc, %rax
movq -0x10(%rbp), %rcx
xorl %edx, %edx
divq 0x48(%rcx)
movq %rax, -0x38(%rbp)
movq -0x18(%rbp), %rdi
callq 0xffffffff80103dd0
shlq $0xc, %rax
movabsq $-0x800000000000, %rcx # imm = 0xFFFF800000000000
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x28(%rbp), %rax
leaq 0x1036f(%rip), %rcx     # 0xffffffff80117fe0
movq %rcx, 0x10(%rax)
movq -0x38(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x30(%rax)
movq -0x38(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x28(%rax)
movq $0x0, -0x48(%rbp)
movq -0x48(%rbp), %rax
cmpq -0x38(%rbp), %rax
je 0xffffffff80107d13
movq -0x20(%rbp), %rax
movq 0x60(%rax), %rdi
callq 0xffffffff80106fd0
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
jne 0xffffffff80107cce
movq -0x20(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0xffffffff80107d70
movq $0x0, -0x8(%rbp)
jmp 0xffffffff80107d1b
movq -0x28(%rbp), %rax
movq 0x38(%rax), %rcx
movq -0x50(%rbp), %rax
movq %rcx, (%rax)
movq -0x40(%rbp), %rcx
movq -0x50(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x50(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x38(%rax)
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
addq -0x40(%rbp), %rax
movq %rax, -0x40(%rbp)
jmp 0xffffffff80107c95
movq -0x28(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/krinkinmu[P]64bit/kmem_cache.c
// Function: kmem_large_slab_release
static void kmem_large_slab_release(struct kmem_large_cache *cache,
			struct kmem_large_slab *slab)
{	
	while (slab->free) {
		struct kmem_tag *tag = slab->free;

		slab->free = tag->next;
		kmem_cache_free(cache->tag_cache, tag);
	}
	kmem_cache_free(cache->slab_cache, slab);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x38(%rax)
je 0xffffffff80107db9
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x38(%rax)
movq -0x8(%rbp), %rax
movq 0x60(%rax), %rdi
movq -0x18(%rbp), %rsi
callq 0xffffffff80107260
jmp 0xffffffff80107d80
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rdi
movq -0x10(%rbp), %rsi
callq 0xffffffff80107260
addq $0x20, %rsp
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O0/krinkinmu[P]64bit/kmem_cache.c
// Function: kmem_large_slab_alloc
static void *kmem_large_slab_alloc(struct kmem_cache *c, struct kmem_slab *s)
{
	struct kmem_large_slab *slab = (struct kmem_large_slab *)s;

	(void) c;

	struct kmem_tag *tag = slab->free;
	void *ptr = tag->ptr;

	slab->free = tag->next;
	tag->next = slab->busy;
	slab->busy = tag;

	return ptr;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rax
movq (%rax), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x38(%rax)
movq -0x18(%rbp), %rax
movq 0x40(%rax), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movq -0x20(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x40(%rax)
movq -0x28(%rbp), %rax
popq %rbp
retq
nopl (%rax)
// File: /workspace/github_c_makefile_star2_O0/krinkinmu[P]64bit/kmem_cache.c
// Function: kmem_large_slab_free
static void kmem_large_slab_free(struct kmem_cache *c, struct kmem_slab *s,
			void *ptr)
{
	struct kmem_large_slab *slab = (struct kmem_large_slab *)s;

	(void) c;

	struct kmem_tag *tag = slab->busy;

	slab->busy = tag->next;
	tag->next = slab->free;
	tag->ptr = ptr;
	slab->free = tag;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq 0x40(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq (%rax), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x40(%rax)
movq -0x20(%rbp), %rax
movq 0x38(%rax), %rcx
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
movq -0x18(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x28(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x38(%rax)
popq %rbp
retq
nopl (%rax)
// File: /workspace/github_c_makefile_star2_O0/krinkinmu[P]64bit/threads.c
// Function: schedule
void schedule(void)
{
	const bool enabled = local_preempt_save();
	struct thread *thread = next_thread();

	if (thread == current_thread) {
		local_preempt_restore(enabled);
		return;
	}
	
	const bool force = (current_thread->state != THREAD_ACTIVE);

	if (!force && !thread) {
		local_preempt_restore(enabled);
		return;
	}

	switch_to(thread ? thread : &bootstrap);
	local_preempt_restore(enabled);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
callq 0xffffffff801089a0
andb $0x1, %al
movb %al, -0x1(%rbp)
callq 0xffffffff801089d0
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rax
cmpq 0x32b1a2(%rip), %rax    # 0xffffffff80433068
jne 0xffffffff80107ed7
movb -0x1(%rbp), %al
andb $0x1, %al
movzbl %al, %edi
callq 0xffffffff801089e0
jmp 0xffffffff80107f3a
movq 0x32b18a(%rip), %rax    # 0xffffffff80433068
cmpl $0x1, 0x30(%rax)
setne %al
andb $0x1, %al
movb %al, -0x11(%rbp)
testb $0x1, -0x11(%rbp)
jne 0xffffffff80107f06
cmpq $0x0, -0x10(%rbp)
jne 0xffffffff80107f06
movb -0x1(%rbp), %al
andb $0x1, %al
movzbl %al, %edi
callq 0xffffffff801089e0
jmp 0xffffffff80107f3a
cmpq $0x0, -0x10(%rbp)
je 0xffffffff80107f17
movq -0x10(%rbp), %rax
movq %rax, -0x20(%rbp)
jmp 0xffffffff80107f24
leaq 0x32b0e2(%rip), %rax    # 0xffffffff80433000
movq %rax, -0x20(%rbp)
jmp 0xffffffff80107f24
movq -0x20(%rbp), %rdi
callq 0xffffffff80108a10
movb -0x1(%rbp), %al
andb $0x1, %al
movzbl %al, %edi
callq 0xffffffff801089e0
addq $0x20, %rsp
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O0/krinkinmu[P]64bit/threads.c
// Function: thread_entry
int thread_entry(struct thread *thread, int (*fptr)(void *),
			void *arg)
{
	place_thread(thread);
	local_preempt_enable();

	if (fptr)
		return fptr(arg);
	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x10(%rbp), %rdi
callq 0xffffffff80108070
callq 0xffffffff80108130
cmpq $0x0, -0x18(%rbp)
je 0xffffffff80108058
movq -0x18(%rbp), %rax
movq -0x20(%rbp), %rdi
callq *%rax
movl %eax, -0x4(%rbp)
jmp 0xffffffff8010805f
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x20, %rsp
popq %rbp
retq
nopl (%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/krinkinmu[P]64bit/threads.c
// Function: place_thread
static void place_thread(struct thread *thread)
{
	struct thread *prev = current_thread;

	if (prev != &bootstrap)
		check_stack(prev);

	current_thread = thread;

	store_pml4(page_paddr(current_thread->mm->pt));
	tss.rsp[0] = (uint64_t)thread_stack_end(current_thread);

	if (prev->state == THREAD_FINISHED)
		prev->state = THREAD_DEAD;

	if (thread == &bootstrap)
		return;

	if (scheduler->place)
		scheduler->place(thread);

	thread->time = jiffies();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x10, %rsp
movq %rdi, -0x8(%rbp)
movq 0x32afe5(%rip), %rax    # 0xffffffff80433068
movq %rax, -0x10(%rbp)
leaq 0x32af72(%rip), %rax    # 0xffffffff80433000
cmpq %rax, -0x10(%rbp)
je 0xffffffff8010809d
movq -0x10(%rbp), %rdi
callq 0xffffffff80108c10
movq -0x8(%rbp), %rax
movq %rax, 0x32afc0(%rip)    # 0xffffffff80433068
movq 0x32afb9(%rip), %rax    # 0xffffffff80433068
movq 0x40(%rax), %rax
movq 0x8(%rax), %rdi
callq 0xffffffff80108bf0
movq %rax, %rdi
callq 0xffffffff80108d00
movq 0x32af9d(%rip), %rdi    # 0xffffffff80433068
callq 0xffffffff80107fc0
movq %rax, 0x32bf2d(%rip)    # 0xffffffff80434004
movq -0x10(%rbp), %rax
cmpl $0x3, 0x30(%rax)
jne 0xffffffff801080ec
movq -0x10(%rbp), %rax
movl $0x4, 0x30(%rax)
leaq 0x32af0d(%rip), %rax    # 0xffffffff80433000
cmpq %rax, -0x8(%rbp)
jne 0xffffffff801080fb
jmp 0xffffffff8010812a
movq 0x32af5e(%rip), %rax    # 0xffffffff80433060
cmpq $0x0, 0x30(%rax)
je 0xffffffff8010811a
movq 0x32af50(%rip), %rax    # 0xffffffff80433060
movq 0x30(%rax), %rax
movq -0x8(%rbp), %rdi
callq *%rax
callq 0xffffffff801090d0
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x28(%rax)
addq $0x10, %rsp
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O0/krinkinmu[P]64bit/threads.c
// Function: lookup_thread
struct thread *lookup_thread(pid_t pid)
{
	struct thread_iter iter;
	const bool enabled = spin_lock_irqsave(&threads_lock);

	if (__lookup_thread(&iter, pid))
		get_thread(iter.thread);
	spin_unlock_irqrestore(&threads_lock, enabled);

	return iter.thread;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
leaq 0x32af05(%rip), %rdi    # 0xffffffff80433058
callq 0xffffffff801081a0
andb $0x1, %al
movb %al, -0x21(%rbp)
movq -0x8(%rbp), %rsi
leaq -0x20(%rbp), %rdi
callq 0xffffffff801081c0
cmpl $0x0, %eax
je 0xffffffff80108178
movq -0x10(%rbp), %rdi
callq 0xffffffff801082a0
movb -0x21(%rbp), %al
leaq 0x32aed6(%rip), %rdi    # 0xffffffff80433058
andb $0x1, %al
movzbl %al, %esi
callq 0xffffffff801082f0
movq -0x10(%rbp), %rax
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/krinkinmu[P]64bit/threads.c
// Function: _lookup_thread
static int __lookup_thread(struct thread_iter *iter, pid_t pid)
{
	struct rb_node **plink = &threads.root;
	struct rb_node *parent = 0;

	while (*plink) {
		struct thread *t = TREE_ENTRY(*plink, struct thread, node);
		const pid_t p = thread_pid(t);

		if (p == pid) {
			iter->parent = parent;
			iter->plink = plink;
			iter->thread = t;
			return 1;
		}

		parent = *plink;
		if (p < pid)
			plink = &parent->right;
		else
			plink = &parent->left;
	}

	iter->parent = parent;
	iter->plink = plink;
	iter->thread = 0;
	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
leaq 0x33be99(%rip), %rax    # 0xffffffff80444070
movq %rax, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movq -0x20(%rbp), %rax
cmpq $0x0, (%rax)
je 0xffffffff8010826b
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
callq 0xffffffff80108d30
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpq -0x18(%rbp), %rax
jne 0xffffffff8010823b
movq -0x28(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, (%rax)
movq -0x20(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x30(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x10(%rax)
movl $0x1, -0x4(%rbp)
jmp 0xffffffff80108295
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x38(%rbp), %rax
cmpq -0x18(%rbp), %rax
jge 0xffffffff8010825e
movq -0x28(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x20(%rbp)
jmp 0xffffffff80108266
movq -0x28(%rbp), %rax
movq %rax, -0x20(%rbp)
jmp 0xffffffff801081e3
movq -0x28(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, (%rax)
movq -0x20(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x10(%rbp), %rax
movq $0x0, 0x10(%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nop
// File: /workspace/github_c_makefile_star2_O0/krinkinmu[P]64bit/threads.c
// Function: create_kthread
pid_t create_kthread(int (*fptr)(void *), void *arg)
{
	const pid_t pid = __create_thread(fptr, arg);

	if (pid < 0)
		return pid;

	struct thread *thread = lookup_thread(pid);

	DBG_ASSERT(thread != 0);

	activate_thread(thread);
	put_thread(thread);
	return pid;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0xffffffff801083c0
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jge 0xffffffff80108352
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0xffffffff801083b1
movq -0x20(%rbp), %rdi
callq 0xffffffff80108140
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0xffffffff80108395
leaq 0x9e0c(%rip), %rdi      # 0xffffffff80112179
leaq 0xa37b(%rip), %rsi      # 0xffffffff801126ef
movl $0x122, %edx            # imm = 0x122
leaq 0x9dfd(%rip), %rcx      # 0xffffffff8011217d
leaq 0xa372(%rip), %r8       # 0xffffffff801126f9
movb $0x0, %al
callq 0xffffffff80101e60
callq 0xffffffff80111cd0
jmp 0xffffffff80108393
jmp 0xffffffff80108397
movq -0x28(%rbp), %rdi
callq 0xffffffff801084b0
movq -0x28(%rbp), %rdi
callq 0xffffffff80108550
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/krinkinmu[P]64bit/threads.c
// Function: _create_thread
static pid_t __create_thread(int (*fptr)(void *), void *arg)
{
	const size_t frame_size = sizeof(struct thread_start_frame);
	extern void __thread_entry(void);

	struct thread *thread = alloc_thread();

	if (!thread)
		return -ENOMEM;

	struct thread_start_frame *frame =
		(void *)((char *)thread_stack_end(thread) - frame_size);

	/* all kernel threads start in kernel_thread_entry */
	frame->frame.entry = (uint64_t)&__thread_entry;

	/* kernel_thread_entry arguments */
	frame->frame.r15 = (uint64_t)thread;
	frame->frame.r14 = (uint64_t)fptr;
	frame->frame.r13 = (uint64_t)arg;

	/*
	 * after thread_entry finished we stil have thread_regs on the stack,
	 * initialize it to iret to exit. Thread function can overwrite it to
	 * jump in userspace.
	 */
	frame->regs.ss = (uint64_t)KERNEL_DS;
	frame->regs.cs = (uint64_t)KERNEL_CS;
	frame->regs.rsp = (uint64_t)(thread_stack_end(thread));
	frame->regs.rip = (uint64_t)&exit; // finish thread on exit

	thread->stack_pointer = frame;
	register_thread(thread);

	return thread_pid(thread);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq $0xe8, -0x20(%rbp)
callq 0xffffffff80108d50
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0xffffffff801083f5
movq $-0x1, -0x8(%rbp)
jmp 0xffffffff801084a3
movq -0x28(%rbp), %rdi
callq 0xffffffff80107fc0
addq $-0xe8, %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq $-0x7feff7cd, %rcx      # imm = 0x80100833
movq %rcx, 0x30(%rax)
movq -0x28(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, (%rax)
movq -0x10(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x18(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x30(%rbp), %rax
movq $0x10, 0xe0(%rax)
movq -0x30(%rbp), %rax
movq $0x8, 0xc8(%rax)
movq -0x28(%rbp), %rdi
callq 0xffffffff80107fc0
movq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0xd8(%rax)
movq -0x30(%rbp), %rax
leaq 0x466(%rip), %rcx       # 0xffffffff801088e0
movq %rcx, 0xc0(%rax)
movq -0x30(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x28(%rbp), %rdi
callq 0xffffffff80108e80
movq -0x28(%rbp), %rdi
callq 0xffffffff80108d30
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax)
// File: /workspace/github_c_makefile_star2_O0/krinkinmu[P]64bit/threads.c
// Function: activate_thread
void activate_thread(struct thread *thread)
{
	const bool locked = spin_lock_irqsave(&thread->lock);

	DBG_ASSERT(thread != &bootstrap);

	if (thread->state == THREAD_BLOCKED) {
		thread->state = THREAD_ACTIVE;
		scheduler->activate(thread);
	}
	spin_unlock_irqrestore(&thread->lock, locked);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x10, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
addq $0x48, %rdi
callq 0xffffffff801081a0
andb $0x1, %al
movb %al, -0x9(%rbp)
leaq 0x32ab2b(%rip), %rax    # 0xffffffff80433000
cmpq %rax, -0x8(%rbp)
jne 0xffffffff8010850a
leaq 0x9c97(%rip), %rdi      # 0xffffffff80112179
leaq 0xa206(%rip), %rsi      # 0xffffffff801126ef
movl $0x196, %edx            # imm = 0x196
leaq 0x9c88(%rip), %rcx      # 0xffffffff8011217d
leaq 0xa209(%rip), %r8       # 0xffffffff80112705
movb $0x0, %al
callq 0xffffffff80101e60
callq 0xffffffff80111cd0
jmp 0xffffffff80108508
jmp 0xffffffff8010850c
movq -0x8(%rbp), %rax
cmpl $0x2, 0x30(%rax)
jne 0xffffffff80108532
movq -0x8(%rbp), %rax
movl $0x1, 0x30(%rax)
movq 0x32ab38(%rip), %rax    # 0xffffffff80433060
movq 0x10(%rax), %rax
movq -0x8(%rbp), %rdi
callq *%rax
movq -0x8(%rbp), %rdi
addq $0x48, %rdi
movb -0x9(%rbp), %al
andb $0x1, %al
movzbl %al, %esi
callq 0xffffffff801082f0
addq $0x10, %rsp
popq %rbp
retq
nopl (%rax)
// File: /workspace/github_c_makefile_star2_O0/krinkinmu[P]64bit/threads.c
// Function: put_thread
void put_thread(struct thread *thread)
{
	const bool locked = spin_lock_irqsave(&thread->lock);
	const int refcount = --thread->refcount;

	spin_unlock_irqrestore(&thread->lock, locked);

	if (!refcount)
		release_thread(thread);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x10, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
addq $0x48, %rdi
callq 0xffffffff801081a0
andb $0x1, %al
movb %al, -0x9(%rbp)
movq -0x8(%rbp), %rcx
movl 0x50(%rcx), %eax
addl $-0x1, %eax
movl %eax, 0x50(%rcx)
movl %eax, -0x10(%rbp)
movq -0x8(%rbp), %rdi
addq $0x48, %rdi
movb -0x9(%rbp), %al
andb $0x1, %al
movzbl %al, %esi
callq 0xffffffff801082f0
cmpl $0x0, -0x10(%rbp)
jne 0xffffffff801085a2
movq -0x8(%rbp), %rdi
callq 0xffffffff80108950
addq $0x10, %rsp
popq %rbp
retq
nopl (%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/krinkinmu[P]64bit/threads.c
// Function: fork
pid_t fork(void)
{
	pid_t pid = __fork();

	if (pid < 0)
		return pid;

	struct thread *thread = lookup_thread(pid);

	DBG_ASSERT(thread != 0);

	activate_thread(thread);
	put_thread(thread);
	return pid;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
callq 0xffffffff80108640
movq %rax, -0x10(%rbp)
cmpq $0x0, -0x10(%rbp)
jge 0xffffffff801085d2
movq -0x10(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0xffffffff80108631
movq -0x10(%rbp), %rdi
callq 0xffffffff80108140
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0xffffffff80108615
leaq 0x9b8c(%rip), %rdi      # 0xffffffff80112179
leaq 0xa0fb(%rip), %rsi      # 0xffffffff801126ef
movl $0x155, %edx            # imm = 0x155
leaq 0x9b7d(%rip), %rcx      # 0xffffffff8011217d
leaq 0xa0f2(%rip), %r8       # 0xffffffff801126f9
movb $0x0, %al
callq 0xffffffff80101e60
callq 0xffffffff80111cd0
jmp 0xffffffff80108613
jmp 0xffffffff80108617
movq -0x18(%rbp), %rdi
callq 0xffffffff801084b0
movq -0x18(%rbp), %rdi
callq 0xffffffff80108550
movq -0x10(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x20, %rsp
popq %rbp
retq
nopl (%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/krinkinmu[P]64bit/threads.c
// Function: _fork
static pid_t __fork(void)
{
	const size_t frame_size = sizeof(struct thread_start_frame);
	extern void __jump_to_userspace(void);
	extern void __thread_entry(void);

	struct thread *thread = alloc_thread();

	if (!thread)
		return -ENOMEM;

	const int rc = copy_mm(thread->mm, current()->mm);

	if (rc)	{
		put_thread(thread);
		return rc;
	}

	struct thread_start_frame *frame =
		(void *)((char *)thread_stack_end(thread) - frame_size);

	frame->frame.entry = (uint64_t)&__thread_entry;
	frame->frame.r15 = (uint64_t)thread;
	frame->frame.r14 = 0;
	frame->frame.r13 = 0;

	frame->regs = *thread_regs(current());
	frame->regs.rax = 0; // syscall return value for child process

	thread->stack_pointer = frame;
	register_thread(thread);

	return thread_pid(thread);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq $0xe8, -0x10(%rbp)
callq 0xffffffff80108d50
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0xffffffff8010866d
movq $-0x1, -0x8(%rbp)
jmp 0xffffffff8010874a
movq -0x18(%rbp), %rax
movq 0x40(%rax), %rax
movq %rax, -0x30(%rbp)
callq 0xffffffff80108940
movq -0x30(%rbp), %rdi
movq 0x40(%rax), %rsi
callq 0xffffffff80110600
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
je 0xffffffff801086aa
movq -0x18(%rbp), %rdi
callq 0xffffffff80108550
movslq -0x1c(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0xffffffff8010874a
movq -0x18(%rbp), %rdi
callq 0xffffffff80107fc0
addq $-0xe8, %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq $-0x7feff7cd, %rcx      # imm = 0x80100833
movq %rcx, 0x30(%rax)
movq -0x18(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
movq -0x28(%rbp), %rax
movq $0x0, 0x8(%rax)
movq -0x28(%rbp), %rax
movq $0x0, 0x10(%rax)
movq -0x28(%rbp), %rax
addq $0x38, %rax
movq %rax, -0x38(%rbp)
callq 0xffffffff80108940
movq %rax, %rdi
callq 0xffffffff80108760
movq -0x38(%rbp), %rdi
movq %rax, %rsi
movl $0xb0, %edx
callq 0xffffffff801016a0
movq -0x28(%rbp), %rax
movq $0x0, 0x88(%rax)
movq -0x28(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x18(%rbp), %rdi
callq 0xffffffff80108e80
movq -0x18(%rbp), %rdi
callq 0xffffffff80108d30
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/krinkinmu[P]64bit/threads.c
// Function: wait
int wait(pid_t pid)
{
	struct thread *thread = lookup_thread(pid);

	if (!thread)
		return -ENOENT;

	__wait_thread(thread);

	const int rc = reap_thread(thread) ? 0 : -ENOENT;

	put_thread(thread);

	return rc;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rdi
callq 0xffffffff80108140
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0xffffffff801087b9
movl $0xfffffffe, -0x4(%rbp) # imm = 0xFFFFFFFE
jmp 0xffffffff801087ec
movq -0x18(%rbp), %rdi
callq 0xffffffff80108800
movq -0x18(%rbp), %rdi
callq 0xffffffff80108830
movl %eax, %edx
movl $0xfffffffe, %eax       # imm = 0xFFFFFFFE
xorl %ecx, %ecx
cmpl $0x0, %edx
cmovnel %ecx, %eax
movl %eax, -0x1c(%rbp)
movq -0x18(%rbp), %rdi
callq 0xffffffff80108550
movl -0x1c(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/krinkinmu[P]64bit/threads.c
// Function: reap_thread
static int reap_thread(struct thread *thread)
{
	bool locked = spin_lock_irqsave(&thread->lock);
	const int state = thread->state;

	thread->state = THREAD_REAPED;
	spin_unlock_irqrestore(&thread->lock, locked);

	if (state == THREAD_REAPED)
		return 0;

	locked = spin_lock_irqsave(&threads_lock);
	rb_erase(&thread->node, &threads);
	spin_unlock_irqrestore(&threads_lock, locked);	
	put_thread(thread);

	return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rdi
addq $0x48, %rdi
callq 0xffffffff801081a0
andb $0x1, %al
movb %al, -0x11(%rbp)
movq -0x10(%rbp), %rax
movl 0x30(%rax), %eax
movl %eax, -0x18(%rbp)
movq -0x10(%rbp), %rax
movl $0x5, 0x30(%rax)
movq -0x10(%rbp), %rdi
addq $0x48, %rdi
movb -0x11(%rbp), %al
andb $0x1, %al
movzbl %al, %esi
callq 0xffffffff801082f0
cmpl $0x5, -0x18(%rbp)
jne 0xffffffff80108887
movl $0x0, -0x4(%rbp)
jmp 0xffffffff801088cc
leaq 0x32a7ca(%rip), %rdi    # 0xffffffff80433058
callq 0xffffffff801081a0
andb $0x1, %al
movb %al, -0x11(%rbp)
movq -0x10(%rbp), %rdi
leaq 0x33b7cd(%rip), %rsi    # 0xffffffff80444070
callq 0xffffffff8010b960
movb -0x11(%rbp), %al
leaq 0x32a7a6(%rip), %rdi    # 0xffffffff80433058
andb $0x1, %al
movzbl %al, %esi
callq 0xffffffff801082f0
movq -0x10(%rbp), %rdi
callq 0xffffffff80108550
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/krinkinmu[P]64bit/threads.c
// Function: exit
void exit(void)
{
	local_preempt_disable();
	current_thread->state = THREAD_FINISHED;
	schedule();
	DBG_ASSERT(0 && "Unreachable");
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
callq 0xffffffff80108930
movq 0x32a778(%rip), %rax    # 0xffffffff80433068
movl $0x3, 0x30(%rax)
callq 0xffffffff80107ea0
leaq 0x9876(%rip), %rdi      # 0xffffffff80112179
leaq 0x9de5(%rip), %rsi      # 0xffffffff801126ef
movl $0x1a4, %edx            # imm = 0x1A4
leaq 0x9867(%rip), %rcx      # 0xffffffff8011217d
leaq 0x9dfd(%rip), %r8       # 0xffffffff8011271a
movb $0x0, %al
callq 0xffffffff80101e60
callq 0xffffffff80111cd0
jmp 0xffffffff80108929
nopl (%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/krinkinmu[P]64bit/threads.c
// Function: switch_to
static void switch_to(struct thread *next)
{
	struct thread *prev = current_thread;

	void switch_threads(void **prev, void *next);

	preempt_thread(prev);
	switch_threads(&prev->stack_pointer, next->stack_pointer);
	place_thread(prev);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x10, %rsp
movq %rdi, -0x8(%rbp)
movq 0x32a645(%rip), %rax    # 0xffffffff80433068
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rdi
callq 0xffffffff80108fe0
movq -0x10(%rbp), %rdi
addq $0x20, %rdi
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rsi
callq 0xffffffff80100d20
movq -0x10(%rbp), %rdi
callq 0xffffffff80108070
addq $0x10, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/krinkinmu[P]64bit/threads.c
// Function: setup_threading
void setup_threading(void)
{
	extern struct scheduler round_robin;
	void setup_round_robin(void);

	setup_round_robin();
	scheduler = &round_robin;

	setup_mm();
	setup_tss();

	static struct mm mm;

	bootstrap.state = THREAD_ACTIVE;
	bootstrap.mm = &mm;
	mm.pt = pfn2page(load_pml4() >> PAGE_BITS);
	current_thread = &bootstrap;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
callq 0xffffffff80109460
movq $-0x7fee8390, %rax      # imm = 0x80117C70
movq %rax, 0x32a599(%rip)    # 0xffffffff80433060
callq 0xffffffff80110bf0
callq 0xffffffff80108b20
movl $0x1, 0x32a555(%rip) # 0xffffffff80433030
leaq 0x32a58e(%rip), %rax    # 0xffffffff80433070
movq %rax, 0x32a557(%rip)    # 0xffffffff80433040
callq 0xffffffff80108bb0
movq %rax, %rdi
shrq $0xc, %rdi
callq 0xffffffff80103ce0
movq %rax, 0x32a577(%rip)    # 0xffffffff80433078
leaq 0x32a4f8(%rip), %rax    # 0xffffffff80433000
movq %rax, 0x32a559(%rip)    # 0xffffffff80433068
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/krinkinmu[P]64bit/threads.c
// Function: setup_tss
static void setup_tss(void)
{
	extern char init_stack_top[];
	const int tss_sel = TSS;
	const int tss_entry = TSS >> 3;
	struct tss_desc desc;
	uint64_t *gdt = get_gdt_ptr();

	tss.iomap_base = offsetof(struct tss, iomap);
	tss.rsp[0] = (uint64_t)init_stack_top;
	memset(tss.iomap, 0xff, sizeof(tss.iomap));
	setup_tss_desc(&desc, &tss);
	memcpy(gdt + tss_entry, &desc, sizeof(desc));
	load_tr(tss_sel);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movl $0x28, -0x4(%rbp)
movl $0x5, -0x8(%rbp)
callq 0xffffffff80109020
movq %rax, -0x20(%rbp)
movw $0x68, 0x32b51e(%rip) # 0xffffffff80434066
movq $-0x7fee0000, %rax      # imm = 0x80120000
movq %rax, 0x32b4ae(%rip)    # 0xffffffff80434004
leaq 0x32b4a3(%rip), %rdi    # 0xffffffff80434000
addq $0x68, %rdi
movl $0xff, %esi
movl $0x10008, %edx          # imm = 0x10008
callq 0xffffffff801017e0
leaq -0x18(%rbp), %rdi
leaq 0x32b485(%rip), %rsi    # 0xffffffff80434000
callq 0xffffffff80109030
movq -0x20(%rbp), %rax
movq -0x18(%rbp), %rcx
movq %rcx, 0x28(%rax)
movq -0x10(%rbp), %rcx
movq %rcx, 0x30(%rax)
movl $0x28, %edi
callq 0xffffffff801090b0
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/krinkinmu[P]64bit/threads.c
// Function: check_stack
__attribute__((aligned (PAGE_SIZE)));

static void check_stack(struct thread *thread)
{
	const size_t stack_order = KERNEL_STACK_ORDER;
	const size_t stack_pages = 1ul << stack_order;
	const size_t stack_size = PAGE_SIZE * stack_pages;
	const char *begin = page_addr(thread->stack);

	if (((char *)thread->stack_pointer < begin) ||
			((char *)thread->stack_pointer >= begin + stack_size)) {
		DBG_ERR("thread %p out of stack", thread);
		DBG_ERR("\tstack_pointer %p", thread->stack_pointer);
		DBG_ERR("\tstack [%p-%p]", begin, begin + stack_size);
		while (1);
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq $0x1, -0x10(%rbp)
movq $0x2, -0x18(%rbp)
movq $0x2000, -0x20(%rbp) # imm = 0x2000
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rdi
callq 0xffffffff80107f90
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
cmpq -0x28(%rbp), %rax
jb 0xffffffff80108c6f
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x28(%rbp), %rcx
addq $0x2000, %rcx           # imm = 0x2000
cmpq %rcx, %rax
jb 0xffffffff80108cef
movq -0x8(%rbp), %r8
leaq 0x94ff(%rip), %rdi      # 0xffffffff80112179
leaq 0x9a6e(%rip), %rsi      # 0xffffffff801126ef
movl $0x48, %edx
leaq 0x9aa0(%rip), %rcx      # 0xffffffff8011272d
movb $0x0, %al
callq 0xffffffff80101e60
movq -0x8(%rbp), %rax
movq 0x20(%rax), %r8
leaq 0x94d6(%rip), %rdi      # 0xffffffff80112179
leaq 0x9a45(%rip), %rsi      # 0xffffffff801126ef
movl $0x49, %edx
leaq 0x9a8e(%rip), %rcx      # 0xffffffff80112744
movb $0x0, %al
callq 0xffffffff80101e60
movq -0x28(%rbp), %r8
movq -0x28(%rbp), %r9
addq $0x2000, %r9            # imm = 0x2000
leaq 0x94a6(%rip), %rdi      # 0xffffffff80112179
leaq 0x9a15(%rip), %rsi      # 0xffffffff801126ef
movl $0x4a, %edx
leaq 0x9a70(%rip), %rcx      # 0xffffffff80112756
movb $0x0, %al
callq 0xffffffff80101e60
jmp 0xffffffff80108ced
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/krinkinmu[P]64bit/threads.c
// Function: alloc_thread
static struct thread *alloc_thread(void)
{
	const size_t stack_order = KERNEL_STACK_ORDER;
	const size_t stack_pages = (size_t)1 << stack_order;
	const size_t stack_size = stack_pages << PAGE_BITS;

	struct page *stack = alloc_pages(stack_order);

	if (!stack)
		return 0;

	struct thread *thread = scheduler->alloc();

	if (!thread) {
		free_pages(stack, stack_order);
		return 0;
	}

	thread->mm = create_mm();
	if (!thread->mm) {
		scheduler->free(thread);
		free_pages(stack, stack_order);
		return 0;
	}

	spinlock_init(&thread->lock);
	thread->refcount = 1; // one for wait
	thread->stack = stack;
	thread->state = THREAD_BLOCKED;
	thread->pid = -1;

	memset(thread_stack_begin(thread), 0, stack_size);
	thread->stack_pointer = thread_stack_end(thread);

	return thread;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq $0x1, -0x10(%rbp)
movq $0x2, -0x18(%rbp)
movq $0x2000, -0x20(%rbp) # imm = 0x2000
movl $0x1, %edi
callq 0xffffffff801043b0
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0xffffffff80108d92
movq $0x0, -0x8(%rbp)
jmp 0xffffffff80108e74
movq 0x32a2c7(%rip), %rax    # 0xffffffff80433060
callq *(%rax)
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0xffffffff80108dc1
movq -0x28(%rbp), %rdi
movl $0x1, %esi
callq 0xffffffff801043d0
movq $0x0, -0x8(%rbp)
jmp 0xffffffff80108e74
callq 0xffffffff80110430
movq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x40(%rax)
movq -0x30(%rbp), %rax
cmpq $0x0, 0x40(%rax)
jne 0xffffffff80108e05
movq 0x32a27d(%rip), %rax    # 0xffffffff80433060
movq 0x8(%rax), %rax
movq -0x30(%rbp), %rdi
callq *%rax
movq -0x28(%rbp), %rdi
movl $0x1, %esi
callq 0xffffffff801043d0
movq $0x0, -0x8(%rbp)
jmp 0xffffffff80108e74
movq -0x30(%rbp), %rdi
addq $0x48, %rdi
callq 0xffffffff80108f30
movq -0x30(%rbp), %rax
movl $0x1, 0x50(%rax)
movq -0x28(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x38(%rax)
movq -0x30(%rbp), %rax
movl $0x2, 0x30(%rax)
movq -0x30(%rbp), %rax
movq $-0x1, 0x18(%rax)
movq -0x30(%rbp), %rdi
callq 0xffffffff80107f40
movq %rax, %rdi
xorl %esi, %esi
movl $0x2000, %edx           # imm = 0x2000
callq 0xffffffff801017e0
movq -0x30(%rbp), %rdi
callq 0xffffffff80107fc0
movq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x30(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x30, %rsp
popq %rbp
retq
nop
// File: /workspace/github_c_makefile_star2_O0/krinkinmu[P]64bit/threads.c
// Function: register_thread
static void register_thread(struct thread *thread)
{
	static pid_t next_pid;
	struct thread_iter iter;

	const bool enabled = spin_lock_irqsave(&threads_lock);

	thread->pid = next_pid++;

	while (__lookup_thread(&iter, thread_pid(thread)))
		thread->pid = next_pid++;

	rb_link(&thread->node, iter.parent, iter.plink);
	rb_insert(&thread->node, &threads);
	spin_unlock_irqrestore(&threads_lock, enabled);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
leaq 0x32a1c5(%rip), %rdi    # 0xffffffff80433058
callq 0xffffffff801081a0
andb $0x1, %al
movb %al, -0x21(%rbp)
movq 0x33b1d4(%rip), %rcx    # 0xffffffff80444078
movq %rcx, %rax
addq $0x1, %rax
movq %rax, 0x33b1c6(%rip)    # 0xffffffff80444078
movq -0x8(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x8(%rbp), %rdi
callq 0xffffffff80108d30
movq %rax, %rsi
leaq -0x20(%rbp), %rdi
callq 0xffffffff801081c0
cmpl $0x0, %eax
je 0xffffffff80108ef3
movq 0x33b19d(%rip), %rcx    # 0xffffffff80444078
movq %rcx, %rax
addq $0x1, %rax
movq %rax, 0x33b18f(%rip)    # 0xffffffff80444078
movq -0x8(%rbp), %rax
movq %rcx, 0x18(%rax)
jmp 0xffffffff80108eba
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0xffffffff80108f50
movq -0x8(%rbp), %rdi
leaq 0x33b161(%rip), %rsi    # 0xffffffff80444070
callq 0xffffffff8010b5d0
movb -0x21(%rbp), %al
leaq 0x32a13a(%rip), %rdi    # 0xffffffff80433058
andb $0x1, %al
movzbl %al, %esi
callq 0xffffffff801082f0
addq $0x30, %rsp
popq %rbp
retq
nop