#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 {
  unsigned long *maskp;
  int size;
};

/* Variables and functions */
int atoi(char const *);
unsigned long *calloc(int, int);
int /*<<< orphan*/ free(struct bitmask *);
struct bitmask *malloc(int);
struct bitmask *rt_numa_parse_cpustring(const char *s, int max_cpus) {
  int cpu;
  struct bitmask *mask = NULL;
  cpu = atoi(s);
  if (0 <= cpu && cpu < max_cpus) {
    mask = malloc(sizeof(*mask));
    if (mask) {
      int nlongs = (max_cpus + (8 * sizeof(long)) - 1) / (8 * sizeof(long));
      mask->maskp = calloc(nlongs, sizeof(long));
      if (mask->maskp) {
        mask->maskp[cpu / (8 * sizeof(long))] |=
            (1UL << (cpu % (8 * sizeof(long))));
        mask->size = max_cpus;
      } else {
        free(mask);
        mask = NULL;
      }
    }
  }
  return mask;
}


x86 assembly (clang, -O0):
<rt_numa_parse_cpustring>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x10(%rbp)
xor    %eax,%eax
cmp    -0x10(%rbp),%eax
jg     121c <rt_numa_parse_cpustring+0xdc>
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    121c <rt_numa_parse_cpustring+0xdc>
mov    $0x10,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1217 <rt_numa_parse_cpustring+0xd7>
movslq -0xc(%rbp),%rax
add    $0x40,%rax
sub    $0x1,%rax
shr    $0x6,%rax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
mov    $0x8,%esi
call   1040 <calloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
je     1201 <rt_numa_parse_cpustring+0xc1>
movslq -0x10(%rbp),%rcx
and    $0x3f,%rcx
mov    $0x1,%edx
shl    %cl,%rdx
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
movslq -0x10(%rbp),%rcx
shr    $0x6,%rcx
or     (%rax,%rcx,8),%rdx
mov    %rdx,(%rax,%rcx,8)
mov    -0xc(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x8(%rax)
jmp    1212 <rt_numa_parse_cpustring+0xd2>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x18(%rbp)
jmp    1217 <rt_numa_parse_cpustring+0xd7>
jmp    121c <rt_numa_parse_cpustring+0xdc>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rt_numa_parse_cpustring>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%r14d
call   1060 <atoi@plt>
xor    %ebx,%ebx
test   %eax,%eax
js     11ae <rt_numa_parse_cpustring+0x6e>
mov    %eax,%ebp
cmp    %r14d,%eax
jge    11ae <rt_numa_parse_cpustring+0x6e>
mov    $0x10,%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     11ac <rt_numa_parse_cpustring+0x6c>
mov    %rax,%rbx
movslq %r14d,%rdi
add    $0x3f,%rdi
shr    $0x6,%rdi
mov    $0x8,%esi
call   1040 <calloc@plt>
mov    %rax,(%rbx)
test   %rax,%rax
je     11a4 <rt_numa_parse_cpustring+0x64>
mov    %ebp,%edx
shr    $0x3,%edx
mov    $0x1,%esi
mov    %ebp,%ecx
shl    %cl,%rsi
and    $0xfffffff8,%edx
or     %rsi,(%rax,%rdx,1)
mov    %r14d,0x8(%rbx)
jmp    11ae <rt_numa_parse_cpustring+0x6e>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.bitmask = type { i64*, i32 }
define %struct.bitmask* @rt_numa_parse_cpustring(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.bitmask*
%7 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
store %struct.bitmask* null, %struct.bitmask** %6
%8 = load i8*, i8** %3
%9 = call i32 @atoi(i8* %8)
store i32 %9, i32* %5
%10 = load i32, i32* %5
%11 = icmp sle i32 0, %10
br i1 %11, label %12, label %57
12: ; preds = %2
%13 = load i32, i32* %5
%14 = load i32, i32* %4
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %57
16: ; preds = %12
%17 = call %struct.bitmask* @malloc(i32 16)
store %struct.bitmask* %17, %struct.bitmask** %6
%18 = load %struct.bitmask*, %struct.bitmask** %6
%19 = icmp ne %struct.bitmask* %18, null
br i1 %19, label %20, label %56
20: ; preds = %16
%21 = load i32, i32* %4
%22 = sext i32 %21 to i64
%23 = add i64 %22, 64
%24 = sub i64 %23, 1
%25 = udiv i64 %24, 64
%26 = trunc i64 %25 to i32
store i32 %26, i32* %7
%27 = load i32, i32* %7
%28 = call i64* @calloc(i32 %27, i32 8)
%29 = load %struct.bitmask*, %struct.bitmask** %6
%30 = getelementptr inbounds %struct.bitmask, %struct.bitmask* %29, i32 0, i32 0
store i64* %28, i64** %30
%31 = load %struct.bitmask*, %struct.bitmask** %6
%32 = getelementptr inbounds %struct.bitmask, %struct.bitmask* %31, i32 0, i32 0
%33 = load i64*, i64** %32
%34 = icmp ne i64* %33, null
br i1 %34, label %35, label %52
35: ; preds = %20
%36 = load i32, i32* %5
%37 = sext i32 %36 to i64
%38 = urem i64 %37, 64
%39 = shl i64 1, %38
%40 = load %struct.bitmask*, %struct.bitmask** %6
%41 = getelementptr inbounds %struct.bitmask, %struct.bitmask* %40, i32 0, i32 0
%42 = load i64*, i64** %41
%43 = load i32, i32* %5
%44 = sext i32 %43 to i64
%45 = udiv i64 %44, 64
%46 = getelementptr inbounds i64, i64* %42, i64 %45
%47 = load i64, i64* %46
%48 = or i64 %47, %39
store i64 %48, i64* %46
%49 = load i32, i32* %4
%50 = load %struct.bitmask*, %struct.bitmask** %6
%51 = getelementptr inbounds %struct.bitmask, %struct.bitmask* %50, i32 0, i32 1
store i32 %49, i32* %51
br label %55
52: ; preds = %20
%53 = load %struct.bitmask*, %struct.bitmask** %6
%54 = call i32 @free(%struct.bitmask* %53)
store %struct.bitmask* null, %struct.bitmask** %6
br label %55
55: ; preds = %52, %35
br label %56
56: ; preds = %55, %16
br label %57
57: ; preds = %56, %12, %2
%58 = load %struct.bitmask*, %struct.bitmask** %6
ret %struct.bitmask* %58
}

LLVM IR (-O2):
%struct.bitmask = type { i64*, i32 }
define noalias %struct.bitmask* @rt_numa_parse_cpustring(i8* nocapture %0, i32 %1) {
%3 = tail call i32 @atoi(i8* %0)
%4 = icmp sgt i32 %3, -1
%5 = icmp slt i32 %3, %1
%6 = and i1 %4, %5
br i1 %6, label %7, label %29
7: ; preds = %2
%8 = tail call %struct.bitmask* @malloc(i32 16)
%9 = icmp eq %struct.bitmask* %8, null
br i1 %9, label %29, label %10
10: ; preds = %7
%11 = sext i32 %1 to i64
%12 = add nsw i64 %11, 63
%13 = lshr i64 %12, 6
%14 = trunc i64 %13 to i32
%15 = tail call i64* @calloc(i32 %14, i32 8)
%16 = getelementptr inbounds %struct.bitmask, %struct.bitmask* %8, i64 0, i32 0
store i64* %15, i64** %16
%17 = icmp eq i64* %15, null
br i1 %17, label %27, label %18
18: ; preds = %10
%19 = zext i32 %3 to i64
%20 = and i64 %19, 63
%21 = shl nuw i64 1, %20
%22 = lshr i64 %19, 6
%23 = getelementptr inbounds i64, i64* %15, i64 %22
%24 = load i64, i64* %23
%25 = or i64 %24, %21
store i64 %25, i64* %23
%26 = getelementptr inbounds %struct.bitmask, %struct.bitmask* %8, i64 0, i32 1
store i32 %1, i32* %26
br label %29
27: ; preds = %10
%28 = tail call i32 @free(%struct.bitmask* %8)
br label %29
29: ; preds = %18, %27, %7, %2
%30 = phi %struct.bitmask* [ null, %7 ], [ null, %2 ], [ %8, %18 ], [ null, %27 ]
ret %struct.bitmask* %30
}