#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 */

/* Variables and functions */
int /*<<< orphan*/ exit(int);
scalar_t__ malloc(int);
long numa_node_size(int, unsigned long *);
int /*<<< orphan*/ printf(char *, ...);
int *get_numa_nodes_to_use(int max_node, unsigned long memory_to_use) {
  unsigned long free_node_sizes;
  long node_size;
  int node_iterator, *nodes_to_use, got_nodes = 0;
  nodes_to_use = (int *)malloc(sizeof(int) * 2);
  for (node_iterator = 0; node_iterator < max_node; node_iterator++) {
    node_size = numa_node_size(node_iterator, &free_node_sizes);
    if (node_size > 0 && free_node_sizes > memory_to_use) {
      nodes_to_use[got_nodes++] = node_iterator;
      if (got_nodes == 2)
        break;
    }
  }
  if (got_nodes == 2) {
    printf("Nodes used in test %d %d \n", nodes_to_use[0], nodes_to_use[1]);
  } else {
    printf("memory is not found in 2 nodes\n");
    exit(255);
  }
  return nodes_to_use;
}


x86 assembly (clang, -O0):
<get_numa_nodes_to_use>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x34(%rbp)
mov    $0x8,%edi
call   1050 <malloc@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11df <get_numa_nodes_to_use+0x9f>
mov    -0x24(%rbp),%edi
lea    -0x18(%rbp),%rsi
call   1030 <numa_node_size@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jle    11cc <get_numa_nodes_to_use+0x8c>
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jbe    11cc <get_numa_nodes_to_use+0x8c>
mov    -0x24(%rbp),%edx
mov    -0x30(%rbp),%rax
mov    -0x34(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x34(%rbp)
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
cmpl   $0x2,-0x34(%rbp)
jne    11c7 <get_numa_nodes_to_use+0x87>
jmp    11df <get_numa_nodes_to_use+0x9f>
jmp    11cc <get_numa_nodes_to_use+0x8c>
jmp    11d1 <get_numa_nodes_to_use+0x91>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    116b <get_numa_nodes_to_use+0x2b>
cmpl   $0x2,-0x34(%rbp)
jne    1209 <get_numa_nodes_to_use+0xc9>
mov    -0x30(%rbp),%rax
mov    (%rax),%esi
mov    -0x30(%rbp),%rax
mov    0x4(%rax),%edx
lea    0xe03(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1221 <get_numa_nodes_to_use+0xe1>
lea    0xe0b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xff,%edi
call   1060 <exit@plt>
mov    -0x30(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_numa_nodes_to_use>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r12
mov    %edi,%r13d
mov    $0x8,%edi
call   1060 <malloc@plt>
test   %r13d,%r13d
jle    11d4 <get_numa_nodes_to_use+0x84>
mov    %rax,%r14
xor    %ebp,%ebp
mov    %rsp,%r15
xor    %ebx,%ebx
jmp    1188 <get_numa_nodes_to_use+0x38>
nopl   0x0(%rax)
add    $0x1,%ebx
cmp    %ebx,%r13d
je     11d4 <get_numa_nodes_to_use+0x84>
mov    %ebx,%edi
mov    %r15,%rsi
call   1030 <numa_node_size@plt>
test   %rax,%rax
jle    1180 <get_numa_nodes_to_use+0x30>
cmp    %r12,(%rsp)
jbe    1180 <get_numa_nodes_to_use+0x30>
mov    %ebp,%eax
mov    %ebx,(%r14,%rax,4)
cmp    $0x1,%ebp
mov    $0x1,%ebp
jne    1180 <get_numa_nodes_to_use+0x30>
mov    (%r14),%esi
mov    0x4(%r14),%edx
lea    0xe45(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe40(%rip),%rdi
call   1040 <puts@plt>
mov    $0xff,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [27 x i8] c"Nodes used in test %d %d \0A\00"
@.str.1 = [32 x i8] c"memory is not found in 2 nodes\0A\00"
define i32* @get_numa_nodes_to_use(i32 %0, i64 %1) {
%3 = alloca i32
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32
store i32 %0, i32* %3
store i64 %1, i64* %4
store i32 0, i32* %9
%10 = call i64 @malloc(i32 8)
%11 = inttoptr i64 %10 to i32*
store i32* %11, i32** %8
store i32 0, i32* %7
br label %12
12: ; preds = %37, %2
%13 = load i32, i32* %7
%14 = load i32, i32* %3
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %40
16: ; preds = %12
%17 = load i32, i32* %7
%18 = call i64 @numa_node_size(i32 %17, i64* %5)
store i64 %18, i64* %6
%19 = load i64, i64* %6
%20 = icmp sgt i64 %19, 0
br i1 %20, label %21, label %36
21: ; preds = %16
%22 = load i64, i64* %5
%23 = load i64, i64* %4
%24 = icmp ugt i64 %22, %23
br i1 %24, label %25, label %36
25: ; preds = %21
%26 = load i32, i32* %7
%27 = load i32*, i32** %8
%28 = load i32, i32* %9
%29 = add nsw i32 %28, 1
store i32 %29, i32* %9
%30 = sext i32 %28 to i64
%31 = getelementptr inbounds i32, i32* %27, i64 %30
store i32 %26, i32* %31
%32 = load i32, i32* %9
%33 = icmp eq i32 %32, 2
br i1 %33, label %34, label %35
34: ; preds = %25
br label %40
35: ; preds = %25
br label %36
36: ; preds = %35, %21, %16
br label %37
37: ; preds = %36
%38 = load i32, i32* %7
%39 = add nsw i32 %38, 1
store i32 %39, i32* %7
br label %12
40: ; preds = %34, %12
%41 = load i32, i32* %9
%42 = icmp eq i32 %41, 2
br i1 %42, label %43, label %51
43: ; preds = %40
%44 = load i32*, i32** %8
%45 = getelementptr inbounds i32, i32* %44, i64 0
%46 = load i32, i32* %45
%47 = load i32*, i32** %8
%48 = getelementptr inbounds i32, i32* %47, i64 1
%49 = load i32, i32* %48
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %46, i32 %49)
br label %54
51: ; preds = %40
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
%53 = call i32 @exit(i32 255)
unreachable
54: ; preds = %43
%55 = load i32*, i32** %8
ret i32* %55
}

LLVM IR (-O2):
@.str = [27 x i8] c"Nodes used in test %d %d \0A\00"
@str = [31 x i8] c"memory is not found in 2 nodes\00"
define i32* @get_numa_nodes_to_use(i32 %0, i64 %1) {
%3 = alloca i64
%4 = bitcast i64* %3 to i8*
%5 = tail call i64 @malloc(i32 8)
%6 = inttoptr i64 %5 to i32*
%7 = icmp sgt i32 %0, 0
br i1 %7, label %8, label %29
8: ; preds = %2, %20
%9 = phi i32 [ %21, %20 ], [ 0, %2 ]
%10 = phi i32 [ %22, %20 ], [ 0, %2 ]
%11 = call i64 @numa_node_size(i32 %10, i64* %3)
%12 = icmp sgt i64 %11, 0
%13 = load i64, i64* %3
%14 = icmp ugt i64 %13, %1
%15 = select i1 %12, i1 %14, i1 false
br i1 %15, label %16, label %20
16: ; preds = %8
%17 = zext i32 %9 to i64
%18 = getelementptr inbounds i32, i32* %6, i64 %17
store i32 %10, i32* %18
%19 = icmp eq i32 %9, 1
br i1 %19, label %24, label %20
20: ; preds = %8, %16
%21 = phi i32 [ 1, %16 ], [ %9, %8 ]
%22 = add nuw nsw i32 %10, 1
%23 = icmp eq i32 %22, %0
br i1 %23, label %29, label %8
24: ; preds = %16
%25 = load i32, i32* %6
%26 = getelementptr inbounds i32, i32* %6, i64 1
%27 = load i32, i32* %26
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %25, i32 %27)
ret i32* %6
29: ; preds = %20, %2
%30 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str, i64 0, i64 0))
%31 = call i32 @exit(i32 255)
unreachable
}