#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*/ MPOL_MF_MOVE;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ move_pages(int /*<<< orphan*/, int, void **,
                              int /*<<< orphan*/ *, int *, int /*<<< orphan*/);
int /*<<< orphan*/ numakind_free(char *);
char *numakind_malloc(int);
int omp_get_thread_num();
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int main(int argc, char **argv) {
  int err = 0;
#pragma omp parallel shared(err)
  {
    char *data;
    int status;
    data = numakind_malloc(1024);
    if (!data) {
      fprintf(stderr, "ERROR: numakind_malloc()\n");
      err = 1;
    } else {
      data[0] = '\0';
      move_pages(0, 1, (void **)&data, NULL, &status, MPOL_MF_MOVE);
      fprintf(stdout, "omp_thread: %.4d numa_node: %.4d\n",
              omp_get_thread_num(), status);
    }
    numakind_free(data);
  }
  return err;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    $0x400,%edi
call   1030 <numakind_malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11a9 <main+0x59>
mov    0x2e4b(%rip),%rax
mov    (%rax),%edi
lea    0xe6a(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x14(%rbp)
jmp    11fb <main+0xab>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    0x2e39(%rip),%rax
mov    (%rax),%r9d
xor    %edi,%edi
mov    $0x1,%esi
lea    -0x20(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x24(%rbp),%r8
call   1050 <move_pages@plt>
mov    0x2df7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    $0x0,%al
call   1040 <omp_get_thread_num@plt>
mov    -0x28(%rbp),%edi
mov    %eax,%edx
mov    -0x24(%rbp),%ecx
lea    0xe26(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1070 <numakind_free@plt>
mov    -0x14(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    $0x400,%edi
call   1030 <numakind_malloc@plt>
mov    %rax,0x10(%rsp)
test   %rax,%rax
je     11c0 <main+0x70>
movb   $0x0,(%rax)
mov    0x2e7b(%rip),%rax
mov    (%rax),%r9d
xor    %r14d,%r14d
lea    0x10(%rsp),%rdx
lea    0xc(%rsp),%r8
xor    %edi,%edi
mov    $0x1,%esi
xor    %ecx,%ecx
call   1050 <move_pages@plt>
mov    0x2e36(%rip),%rax
mov    (%rax),%ebx
xor    %eax,%eax
call   1040 <omp_get_thread_num@plt>
mov    0xc(%rsp),%ecx
lea    0xe6c(%rip),%rsi
mov    %ebx,%edi
mov    %eax,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x10(%rsp),%rbx
jmp    11df <main+0x8f>
mov    0x2e11(%rip),%rax
mov    (%rax),%edi
lea    0xe30(%rip),%rsi
xor    %ebx,%ebx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%r14d
mov    %rbx,%rdi
call   1070 <numakind_free@plt>
mov    %r14d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [26 x i8] c"ERROR: numakind_malloc()\0A\00"
@MPOL_MF_MOVE = global i32 0
@stdout = global i32 0
@.str.1 = [34 x i8] c"omp_thread: %.4d numa_node: %.4d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
%9 = call i8* @numakind_malloc(i32 1024)
store i8* %9, i8** %7
%10 = load i8*, i8** %7
%11 = icmp ne i8* %10, null
br i1 %11, label %15, label %12
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %6
br label %24
15: ; preds = %2
%16 = load i8*, i8** %7
%17 = getelementptr inbounds i8, i8* %16, i64 0
store i8 0, i8* %17
%18 = load i32, i32* @MPOL_MF_MOVE
%19 = call i32 @move_pages(i32 0, i32 1, i8** %7, i32* null, i32* %8, i32 %18)
%20 = load i32, i32* @stdout
%21 = call i32 (...) @omp_get_thread_num()
%22 = load i32, i32* %8
%23 = call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i32 %21, i32 %22)
br label %24
24: ; preds = %15, %12
%25 = load i8*, i8** %7
%26 = call i32 @numakind_free(i8* %25)
%27 = load i32, i32* %6
ret i32 %27
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [26 x i8] c"ERROR: numakind_malloc()\0A\00"
@MPOL_MF_MOVE = global i32 0
@stdout = global i32 0
@.str.1 = [34 x i8] c"omp_thread: %.4d numa_node: %.4d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = bitcast i8** %3 to i8*
%6 = bitcast i32* %4 to i8*
%7 = tail call i8* @numakind_malloc(i32 1024)
store i8* %7, i8** %3
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = tail call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %20
12: ; preds = %2
store i8 0, i8* %7
%13 = load i32, i32* @MPOL_MF_MOVE
%14 = call i32 @move_pages(i32 0, i32 1, i8** %3, i32* null, i32* %4, i32 %13)
%15 = load i32, i32* @stdout
%16 = call i32 (...) @omp_get_thread_num()
%17 = load i32, i32* %4
%18 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i32 %16, i32 %17)
%19 = load i8*, i8** %3
br label %20
20: ; preds = %12, %9
%21 = phi i8* [ %19, %12 ], [ null, %9 ]
%22 = phi i32 [ 0, %12 ], [ 1, %9 ]
%23 = call i32 @numakind_free(i8* %21)
ret i32 %22
}