#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 */
unsigned long numa_max_node();
long numa_node_size(unsigned long, int /*<<< orphan*/ *);
unsigned long get_next_mem_node(unsigned long node) {
  long node_size;
  unsigned long i;
  unsigned long max_node = numa_max_node();
restart:
  for (i = node + 1; i <= max_node; i++) {
    node_size = numa_node_size(i, NULL);
    if (node_size > 0)
      return i;
  }
  if (node == -1)
    return 0;
  node = -1;
  goto restart;
}


x86 assembly (clang, -O0):
<get_next_mem_node>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x0,%al
call   1040 <numa_max_node@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x28(%rbp),%rax
ja     1190 <get_next_mem_node+0x70>
mov    -0x20(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <numa_node_size@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jle    117a <get_next_mem_node+0x5a>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11b5 <get_next_mem_node+0x95>
jmp    117f <get_next_mem_node+0x5f>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1143 <get_next_mem_node+0x23>
cmpq   $0xffffffffffffffff,-0x10(%rbp)
jne    11a8 <get_next_mem_node+0x88>
movq   $0x0,-0x8(%rbp)
jmp    11b5 <get_next_mem_node+0x95>
movq   $0xffffffffffffffff,-0x10(%rbp)
ff
jmp    1137 <get_next_mem_node+0x17>
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_next_mem_node>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
xor    %eax,%eax
call   1040 <numa_max_node@plt>
mov    %rax,%r15
mov    %r14,%rbx
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%rbx
cmp    %r15,%rbx
ja     1160 <get_next_mem_node+0x40>
mov    %rbx,%rdi
xor    %esi,%esi
call   1030 <numa_node_size@plt>
test   %rax,%rax
jle    1140 <get_next_mem_node+0x20>
jmp    116f <get_next_mem_node+0x4f>
nopw   0x0(%rax,%rax,1)
cmp    $0xffffffffffffffff,%r14
mov    $0xffffffffffffffff,%r14
jne    1132 <get_next_mem_node+0x12>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i64 @get_next_mem_node(i64 %0) {
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
store i64 %0, i64* %3
%7 = call i64 (...) @numa_max_node()
store i64 %7, i64* %6
br label %8
8: ; preds = %30, %1
%9 = load i64, i64* %3
%10 = add i64 %9, 1
store i64 %10, i64* %5
br label %11
11: ; preds = %23, %8
%12 = load i64, i64* %5
%13 = load i64, i64* %6
%14 = icmp ule i64 %12, %13
br i1 %14, label %15, label %26
15: ; preds = %11
%16 = load i64, i64* %5
%17 = call i64 @numa_node_size(i64 %16, i32* null)
store i64 %17, i64* %4
%18 = load i64, i64* %4
%19 = icmp sgt i64 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %15
%21 = load i64, i64* %5
store i64 %21, i64* %2
br label %31
22: ; preds = %15
br label %23
23: ; preds = %22
%24 = load i64, i64* %5
%25 = add i64 %24, 1
store i64 %25, i64* %5
br label %11
26: ; preds = %11
%27 = load i64, i64* %3
%28 = icmp eq i64 %27, -1
br i1 %28, label %29, label %30
29: ; preds = %26
store i64 0, i64* %2
br label %31
30: ; preds = %26
store i64 -1, i64* %3
br label %8
31: ; preds = %29, %20
%32 = load i64, i64* %2
ret i64 %32
}

LLVM IR (-O2):
define i64 @get_next_mem_node(i64 %0) {
%2 = tail call i64 (...) @numa_max_node()
br label %3
3: ; preds = %12, %1
%4 = phi i64 [ %0, %1 ], [ -1, %12 ]
br label %5
5: ; preds = %9, %3
%6 = phi i64 [ %4, %3 ], [ %7, %9 ]
%7 = add i64 %6, 1
%8 = icmp ugt i64 %7, %2
br i1 %8, label %12, label %9
9: ; preds = %5
%10 = tail call i64 @numa_node_size(i64 %7, i32* null)
%11 = icmp sgt i64 %10, 0
br i1 %11, label %14, label %5
12: ; preds = %5
%13 = icmp eq i64 %4, -1
br i1 %13, label %14, label %3
14: ; preds = %12, %9
%15 = phi i64 [ %7, %9 ], [ 0, %12 ]
ret i64 %15
}