#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 page_table {
  int dummy;
};

/* Variables and functions */
struct page_table *get_temp_page_table();
int page_table_init(struct page_table *);
int /*<<< orphan*/ pageframe_index(struct page_table *);
int pmem_claim_frames(int /*<<< orphan*/, int);
int /*<<< orphan*/ pmem_unref_frames(int /*<<< orphan*/, int);
struct page_table *claim_and_init_temp_page_table(void) {
  struct page_table *pt = get_temp_page_table();
  if (!pt) {
    return NULL;
  }
  int res = pmem_claim_frames(pageframe_index(pt), 1);
  if (res < 0) {
    goto err_pmem_claim_frames;
  }
  res = page_table_init(pt);
  if (res < 0) {
    goto err_page_table_init;
  }
  return pt;
err_page_table_init:
  pmem_unref_frames(pageframe_index(pt), 1);
err_pmem_claim_frames:
  return NULL;
}


x86 assembly (clang, -O0):
<claim_and_init_temp_page_table>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x0,%al
call   1040 <get_temp_page_table@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    117b <claim_and_init_temp_page_table+0x2b>
movq   $0x0,-0x8(%rbp)
jmp    11e7 <claim_and_init_temp_page_table+0x97>
mov    -0x10(%rbp),%rdi
call   1060 <pageframe_index@plt>
mov    %eax,%edi
mov    $0x1,%esi
call   1050 <pmem_claim_frames@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11a2 <claim_and_init_temp_page_table+0x52>
jmp    11df <claim_and_init_temp_page_table+0x8f>
mov    -0x10(%rbp),%rdi
call   1030 <page_table_init@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11bd <claim_and_init_temp_page_table+0x6d>
jmp    11ca <claim_and_init_temp_page_table+0x7a>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11e7 <claim_and_init_temp_page_table+0x97>
mov    -0x10(%rbp),%rdi
call   1060 <pageframe_index@plt>
mov    %eax,%edi
mov    $0x1,%esi
call   1070 <pmem_unref_frames@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<claim_and_init_temp_page_table>:
push   %rbx
xor    %eax,%eax
call   1040 <get_temp_page_table@plt>
test   %rax,%rax
je     1198 <claim_and_init_temp_page_table+0x48>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <pageframe_index@plt>
mov    %eax,%edi
mov    $0x1,%esi
call   1050 <pmem_claim_frames@plt>
test   %eax,%eax
js     1198 <claim_and_init_temp_page_table+0x48>
mov    %rbx,%rdi
call   1030 <page_table_init@plt>
test   %eax,%eax
jns    119a <claim_and_init_temp_page_table+0x4a>
mov    %rbx,%rdi
call   1060 <pageframe_index@plt>
mov    %eax,%edi
mov    $0x1,%esi
call   1070 <pmem_unref_frames@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
%struct.page_table = type { i32 }
define %struct.page_table* @claim_and_init_temp_page_table() {
%1 = alloca %struct.page_table*
%2 = alloca %struct.page_table*
%3 = alloca i32
%4 = call %struct.page_table* (...) @get_temp_page_table()
store %struct.page_table* %4, %struct.page_table** %2
%5 = load %struct.page_table*, %struct.page_table** %2
%6 = icmp ne %struct.page_table* %5, null
br i1 %6, label %8, label %7
7: ; preds = %0
store %struct.page_table* null, %struct.page_table** %1
br label %28
8: ; preds = %0
%9 = load %struct.page_table*, %struct.page_table** %2
%10 = call i32 @pageframe_index(%struct.page_table* %9)
%11 = call i32 @pmem_claim_frames(i32 %10, i32 1)
store i32 %11, i32* %3
%12 = load i32, i32* %3
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %8
br label %27
15: ; preds = %8
%16 = load %struct.page_table*, %struct.page_table** %2
%17 = call i32 @page_table_init(%struct.page_table* %16)
store i32 %17, i32* %3
%18 = load i32, i32* %3
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %15
br label %23
21: ; preds = %15
%22 = load %struct.page_table*, %struct.page_table** %2
store %struct.page_table* %22, %struct.page_table** %1
br label %28
23: ; preds = %20
%24 = load %struct.page_table*, %struct.page_table** %2
%25 = call i32 @pageframe_index(%struct.page_table* %24)
%26 = call i32 @pmem_unref_frames(i32 %25, i32 1)
br label %27
27: ; preds = %23, %14
store %struct.page_table* null, %struct.page_table** %1
br label %28
28: ; preds = %27, %21, %7
%29 = load %struct.page_table*, %struct.page_table** %1
ret %struct.page_table* %29
}

LLVM IR (-O2):
%struct.page_table = type { i32 }
define %struct.page_table* @claim_and_init_temp_page_table() {
%1 = tail call %struct.page_table* (...) @get_temp_page_table()
%2 = icmp eq %struct.page_table* %1, null
br i1 %2, label %13, label %3
3: ; preds = %0
%4 = tail call i32 @pageframe_index(%struct.page_table* %1)
%5 = tail call i32 @pmem_claim_frames(i32 %4, i32 1)
%6 = icmp slt i32 %5, 0
br i1 %6, label %13, label %7
7: ; preds = %3
%8 = tail call i32 @page_table_init(%struct.page_table* %1)
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %7
%11 = tail call i32 @pageframe_index(%struct.page_table* %1)
%12 = tail call i32 @pmem_unref_frames(i32 %11, i32 1)
br label %13
13: ; preds = %7, %3, %10, %0
%14 = phi %struct.page_table* [ null, %0 ], [ %1, %7 ], [ null, %3 ], [ null, %10 ]
ret %struct.page_table* %14
}