#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 bitmask {
  int dummy;
};
typedef int /*<<< orphan*/ buf;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
scalar_t__ bitmask_parselist(char *, struct bitmask *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int strlen(char *);
int online_memmask(struct bitmask *memmask) {
  FILE *fp = NULL;
  char buf[512];
  if (memmask == NULL)
    return -1;
  if ((fp = fopen("/sys/devices/system/node/online", "r")) == NULL)
    return -1;
  if (fgets(buf, sizeof(buf), fp) == NULL) {
    fclose(fp);
    return -1;
  }
  fclose(fp);
  buf[strlen(buf) - 1] = '\0';
  if (bitmask_parselist(buf, memmask) != 0)
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<online_memmask>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    117e <online_memmask+0x2e>
movl   $0xffffffff,-0x4(%rbp)
jmp    122e <online_memmask+0xde>
lea    0xe7b(%rip),%rdi
lea    0xe94(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11ab <online_memmask+0x5b>
movl   $0xffffffff,-0x4(%rbp)
jmp    122e <online_memmask+0xde>
lea    -0x220(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x200,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
jne    11df <online_memmask+0x8f>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    122e <online_memmask+0xde>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
lea    -0x220(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
cltq
movb   $0x0,-0x220(%rbp,%rax,1)
lea    -0x220(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <bitmask_parselist@plt>
cmp    $0x0,%rax
je     1227 <online_memmask+0xd7>
movl   $0xffffffff,-0x4(%rbp)
jmp    122e <online_memmask+0xde>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<online_memmask>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x200,%rsp
mov    $0xffffffff,%ebp
test   %rdi,%rdi
je     11ca <online_memmask+0x7a>
mov    %rdi,%r15
lea    0xe8d(%rip),%rdi
lea    0xea6(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11ca <online_memmask+0x7a>
mov    %rax,%rbx
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x200,%esi
mov    %rax,%rdx
call   1060 <fgets@plt>
mov    %rax,%r12
mov    %rbx,%rdi
call   1030 <fclose@plt>
test   %r12,%r12
je     11ca <online_memmask+0x7a>
mov    %r14,%rdi
call   1040 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%r14,1)
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <bitmask_parselist@plt>
neg    %rax
sbb    %ebp,%ebp
mov    %ebp,%eax
add    $0x200,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.bitmask = type { i32 }
@.str = [32 x i8] c"/sys/devices/system/node/online\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @online_memmask(%struct.bitmask* %0) {
%2 = alloca i32
%3 = alloca %struct.bitmask*
%4 = alloca i32*
%5 = alloca [512 x i8]
store %struct.bitmask* %0, %struct.bitmask** %3
store i32* null, i32** %4
%6 = load %struct.bitmask*, %struct.bitmask** %3
%7 = icmp eq %struct.bitmask* %6, null
br i1 %7, label %8, label %9
8: ; preds = %1
store i32 -1, i32* %2
br label %35
9: ; preds = %1
%10 = call i32* @fopen(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %10, i32** %4
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %13
12: ; preds = %9
store i32 -1, i32* %2
br label %35
13: ; preds = %9
%14 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%15 = load i32*, i32** %4
%16 = call i32* @fgets(i8* %14, i32 512, i32* %15)
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %21
18: ; preds = %13
%19 = load i32*, i32** %4
%20 = call i32 @fclose(i32* %19)
store i32 -1, i32* %2
br label %35
21: ; preds = %13
%22 = load i32*, i32** %4
%23 = call i32 @fclose(i32* %22)
%24 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%25 = call i32 @strlen(i8* %24)
%26 = sub nsw i32 %25, 1
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 %27
store i8 0, i8* %28
%29 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%30 = load %struct.bitmask*, %struct.bitmask** %3
%31 = call i64 @bitmask_parselist(i8* %29, %struct.bitmask* %30)
%32 = icmp ne i64 %31, 0
br i1 %32, label %33, label %34
33: ; preds = %21
store i32 -1, i32* %2
br label %35
34: ; preds = %21
store i32 0, i32* %2
br label %35
35: ; preds = %34, %33, %18, %12, %8
%36 = load i32, i32* %2
ret i32 %36
}

LLVM IR (-O2):
%struct.bitmask = type { i32 }
@.str = [32 x i8] c"/sys/devices/system/node/online\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @online_memmask(%struct.bitmask* %0) {
%2 = alloca [512 x i8]
%3 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%4 = icmp eq %struct.bitmask* %0, null
br i1 %4, label %20, label %5
5: ; preds = %1
%6 = tail call i32* @fopen(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %20, label %8
8: ; preds = %5
%9 = call i32* @fgets(i8* %3, i32 512, i32* %6)
%10 = icmp eq i32* %9, null
%11 = call i32 @fclose(i32* %6)
br i1 %10, label %20, label %12
12: ; preds = %8
%13 = call i32 @strlen(i8* %3)
%14 = add nsw i32 %13, -1
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 %15
store i8 0, i8* %16
%17 = call i64 @bitmask_parselist(i8* %3, %struct.bitmask* %0)
%18 = icmp ne i64 %17, 0
%19 = sext i1 %18 to i32
br label %20
20: ; preds = %8, %12, %5, %1
%21 = phi i32 [ -1, %1 ], [ -1, %5 ], [ %19, %12 ], [ -1, %8 ]
ret i32 %21
}