#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 */
typedef int /*<<< orphan*/ hwloc_topology_t;
typedef int /*<<< orphan*/ hwloc_bitmap_t;

/* Variables and functions */
int /*<<< orphan*/ HWLOC_MEMBIND_DEFAULT;
int /*<<< orphan*/ hwloc_alloc_membind_policy(int /*<<< orphan*/, int,
                                              int /*<<< orphan*/,
                                              int /*<<< orphan*/,
                                              int /*<<< orphan*/);
int /*<<< orphan*/ hwloc_bitmap_alloc_full();
int /*<<< orphan*/ hwloc_free(int /*<<< orphan*/, void *, int);
int hwloc_set_membind(int /*<<< orphan*/, int /*<<< orphan*/,
                      int /*<<< orphan*/, int /*<<< orphan*/);
int hwloc_topology_init(int /*<<< orphan*/ *);
int hwloc_topology_load(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int main(void) {
  hwloc_topology_t topology;
  if (hwloc_topology_init(&topology) == -1) {
    perror("failed to initialize topology");
    return -1;
  }
  if (hwloc_topology_load(topology) == -1) {
    perror("failed to load topology");
    return -1;
  }
  hwloc_bitmap_t set = hwloc_bitmap_alloc_full();
  void *mem =
      hwloc_alloc_membind_policy(topology, 1, set, HWLOC_MEMBIND_DEFAULT, 0);
  if (mem == -1 || mem == NULL) {
    perror("hwloc_alloc_membind_policy() failed");
    return -1;
  }
  hwloc_free(topology, mem, 1);
  if (hwloc_set_membind(topology, set, HWLOC_MEMBIND_DEFAULT, 0) == -1) {
    perror("hwloc_set_membind() failed");
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x8(%rbp),%rdi
call   1030 <hwloc_topology_init@plt>
cmp    $0xffffffff,%eax
jne    11a9 <main+0x39>
lea    0xe68(%rip),%rdi
call   1080 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1281 <main+0x111>
mov    -0x8(%rbp),%edi
call   1040 <hwloc_topology_load@plt>
cmp    $0xffffffff,%eax
jne    11d2 <main+0x62>
lea    0xe5d(%rip),%rdi
call   1080 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1281 <main+0x111>
mov    $0x0,%al
call   1070 <hwloc_bitmap_alloc_full@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%edx
mov    0x2df7(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%esi
xor    %r8d,%r8d
call   1050 <hwloc_alloc_membind_policy@plt>
cltq
mov    %rax,-0x18(%rbp)
mov    $0xffffffffffffffff,%rax
cmp    %rax,-0x18(%rbp)
je     121a <main+0xaa>
cmpq   $0x0,-0x18(%rbp)
jne    1232 <main+0xc2>
lea    0xe15(%rip),%rdi
call   1080 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1281 <main+0x111>
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    $0x1,%edx
call   1090 <hwloc_free@plt>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    0x2d90(%rip),%rax
mov    (%rax),%edx
xor    %ecx,%ecx
call   1060 <hwloc_set_membind@plt>
cmp    $0xffffffff,%eax
jne    127a <main+0x10a>
lea    0xdf1(%rip),%rdi
call   1080 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1281 <main+0x111>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
lea    0x4(%rsp),%rdi
call   1030 <hwloc_topology_init@plt>
cmp    $0xffffffff,%eax
je     11f8 <main+0x88>
mov    0x4(%rsp),%edi
call   1040 <hwloc_topology_load@plt>
cmp    $0xffffffff,%eax
je     1201 <main+0x91>
xor    %eax,%eax
call   1070 <hwloc_bitmap_alloc_full@plt>
mov    %eax,%ebx
mov    0x4(%rsp),%edi
mov    0x2e3c(%rip),%rbp
mov    0x0(%rbp),%ecx
mov    $0x1,%esi
mov    %eax,%edx
xor    %r8d,%r8d
call   1050 <hwloc_alloc_membind_policy@plt>
movslq %eax,%rsi
lea    0xe76(%rip),%rdi
cmp    $0xffffffffffffffff,%rsi
je     1208 <main+0x98>
test   %eax,%eax
je     1208 <main+0x98>
mov    0x4(%rsp),%edi
mov    $0x1,%edx
call   1090 <hwloc_free@plt>
mov    0x4(%rsp),%edi
mov    0x0(%rbp),%edx
xor    %ebp,%ebp
mov    %ebx,%esi
xor    %ecx,%ecx
call   1060 <hwloc_set_membind@plt>
cmp    $0xffffffff,%eax
jne    1212 <main+0xa2>
lea    0xe64(%rip),%rdi
jmp    1208 <main+0x98>
lea    0xe01(%rip),%rdi
jmp    1208 <main+0x98>
lea    0xe16(%rip),%rdi
call   1080 <perror@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [30 x i8] c"failed to initialize topology\00"
@.str.1 = [24 x i8] c"failed to load topology\00"
@HWLOC_MEMBIND_DEFAULT = global i32 0
@.str.2 = [36 x i8] c"hwloc_alloc_membind_policy() failed\00"
@.str.3 = [27 x i8] c"hwloc_set_membind() failed\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
store i32 0, i32* %1
%5 = call i32 @hwloc_topology_init(i32* %2)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %1
br label %42
9: ; preds = %0
%10 = load i32, i32* %2
%11 = call i32 @hwloc_topology_load(i32 %10)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %15
13: ; preds = %9
%14 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %1
br label %42
15: ; preds = %9
%16 = call i32 (...) @hwloc_bitmap_alloc_full()
store i32 %16, i32* %3
%17 = load i32, i32* %2
%18 = load i32, i32* %3
%19 = load i32, i32* @HWLOC_MEMBIND_DEFAULT
%20 = call i32 @hwloc_alloc_membind_policy(i32 %17, i32 1, i32 %18, i32 %19, i32 0)
%21 = sext i32 %20 to i64
%22 = inttoptr i64 %21 to i8*
store i8* %22, i8** %4
%23 = load i8*, i8** %4
%24 = icmp eq i8* %23, inttoptr (i64 -1 to i8*)
br i1 %24, label %28, label %25
25: ; preds = %15
%26 = load i8*, i8** %4
%27 = icmp eq i8* %26, null
br i1 %27, label %28, label %30
28: ; preds = %25, %15
%29 = call i32 @perror(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %1
br label %42
30: ; preds = %25
%31 = load i32, i32* %2
%32 = load i8*, i8** %4
%33 = call i32 @hwloc_free(i32 %31, i8* %32, i32 1)
%34 = load i32, i32* %2
%35 = load i32, i32* %3
%36 = load i32, i32* @HWLOC_MEMBIND_DEFAULT
%37 = call i32 @hwloc_set_membind(i32 %34, i32 %35, i32 %36, i32 0)
%38 = icmp eq i32 %37, -1
br i1 %38, label %39, label %41
39: ; preds = %30
%40 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %1
br label %42
41: ; preds = %30
store i32 0, i32* %1
br label %42
42: ; preds = %41, %39, %28, %13, %7
%43 = load i32, i32* %1
ret i32 %43
}

LLVM IR (-O2):
@.str = [30 x i8] c"failed to initialize topology\00"
@.str.1 = [24 x i8] c"failed to load topology\00"
@HWLOC_MEMBIND_DEFAULT = global i32 0
@.str.2 = [36 x i8] c"hwloc_alloc_membind_policy() failed\00"
@.str.3 = [27 x i8] c"hwloc_set_membind() failed\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = call i32 @hwloc_topology_init(i32* %1)
%4 = icmp eq i32 %3, -1
br i1 %4, label %26, label %5
5: ; preds = %0
%6 = load i32, i32* %1
%7 = call i32 @hwloc_topology_load(i32 %6)
%8 = icmp eq i32 %7, -1
br i1 %8, label %26, label %9
9: ; preds = %5
%10 = call i32 (...) @hwloc_bitmap_alloc_full()
%11 = load i32, i32* %1
%12 = load i32, i32* @HWLOC_MEMBIND_DEFAULT
%13 = call i32 @hwloc_alloc_membind_policy(i32 %11, i32 1, i32 %10, i32 %12, i32 0)
%14 = sext i32 %13 to i64
%15 = inttoptr i64 %14 to i8*
%16 = icmp eq i8* %15, inttoptr (i64 -1 to i8*)
%17 = icmp eq i32 %13, 0
%18 = select i1 %16, i1 true, i1 %17
br i1 %18, label %26, label %19
19: ; preds = %9
%20 = load i32, i32* %1
%21 = call i32 @hwloc_free(i32 %20, i8* %15, i32 1)
%22 = load i32, i32* %1
%23 = load i32, i32* @HWLOC_MEMBIND_DEFAULT
%24 = call i32 @hwloc_set_membind(i32 %22, i32 %10, i32 %23, i32 0)
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %29
26: ; preds = %19, %9, %5, %0
%27 = phi i8* [ getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), %0 ], [ getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), %5 ], [ getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), %9 ], [ getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), %19 ]
%28 = call i32 @perror(i8* %27)
br label %29
29: ; preds = %26, %19
%30 = phi i32 [ 0, %19 ], [ -1, %26 ]
ret i32 %30
}