#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*/ free(char *);
char *strdup(char *);
char *strtok_r(char *, char *, char **);
unsigned int strtoul(char *, int /*<<< orphan*/ *, int /*<<< orphan*/);
int msr_core_ids(char *env_cores, unsigned int *core_ids, unsigned int ncores) {
  unsigned int i;
  char *saveptr;
  char *env_cores_tmp = strdup(env_cores);
  if (env_cores_tmp == NULL) {
    return -1;
  }
  char *tok = strtok_r(env_cores_tmp, ", :;|", &saveptr);
  for (i = 0; tok != NULL && i < ncores; i++) {
    core_ids[i] = strtoul(tok, NULL, 0);
    tok = strtok_r(NULL, ", :;|", &saveptr);
  }
  free(env_cores_tmp);
  return 0;
}


x86 assembly (clang, -O0):
<msr_core_ids>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <strdup@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1177 <msr_core_ids+0x37>
movl   $0xffffffff,-0x4(%rbp)
jmp    1213 <msr_core_ids+0xd3>
mov    -0x30(%rbp),%rdi
lea    0xe7e(%rip),%rsi
lea    -0x28(%rbp),%rdx
call   1040 <strtok_r@plt>
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x20(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x38(%rbp)
mov    %al,-0x39(%rbp)
je     11b2 <msr_core_ids+0x72>
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
setb   %al
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
test   $0x1,%al
jne    11c2 <msr_core_ids+0x82>
jmp    1203 <msr_core_ids+0xc3>
mov    -0x38(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1050 <strtoul@plt>
mov    %eax,%edx
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%ecx
mov    %edx,(%rax,%rcx,4)
xor    %eax,%eax
mov    %eax,%edi
lea    0xe18(%rip),%rsi
lea    -0x28(%rbp),%rdx
call   1040 <strtok_r@plt>
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1196 <msr_core_ids+0x56>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<msr_core_ids>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %rsi,%r13
call   1060 <strdup@plt>
test   %rax,%rax
je     11cb <msr_core_ids+0x8b>
mov    %rax,%r14
lea    0xe9c(%rip),%rsi
mov    %rsp,%rdx
mov    %rax,%rdi
call   1040 <strtok_r@plt>
test   %rax,%rax
je     11bf <msr_core_ids+0x7f>
test   %ebp,%ebp
je     11bf <msr_core_ids+0x7f>
mov    %ebp,%ebp
mov    $0x1,%ebx
lea    0xe7a(%rip),%r15
mov    %rsp,%r12
nopl   0x0(%rax)
mov    %rax,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1050 <strtoul@plt>
mov    %eax,-0x4(%r13,%rbx,4)
xor    %edi,%edi
mov    %r15,%rsi
mov    %r12,%rdx
call   1040 <strtok_r@plt>
test   %rax,%rax
je     11bf <msr_core_ids+0x7f>
lea    0x1(%rbx),%rcx
cmp    %rbp,%rbx
mov    %rcx,%rbx
jb     1190 <msr_core_ids+0x50>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
jmp    11d0 <msr_core_ids+0x90>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c", :;|\00"
define i32 @msr_core_ids(i8* %0, i32* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
store i8* %0, i8** %5
store i32* %1, i32** %6
store i32 %2, i32* %7
%12 = load i8*, i8** %5
%13 = call i8* @strdup(i8* %12)
store i8* %13, i8** %10
%14 = load i8*, i8** %10
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %17
16: ; preds = %3
store i32 -1, i32* %4
br label %43
17: ; preds = %3
%18 = load i8*, i8** %10
%19 = call i8* @strtok_r(i8* %18, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8** %9)
store i8* %19, i8** %11
store i32 0, i32* %8
br label %20
20: ; preds = %37, %17
%21 = load i8*, i8** %11
%22 = icmp ne i8* %21, null
br i1 %22, label %23, label %27
23: ; preds = %20
%24 = load i32, i32* %8
%25 = load i32, i32* %7
%26 = icmp ult i32 %24, %25
br label %27
27: ; preds = %23, %20
%28 = phi i1 [ false, %20 ], [ %26, %23 ]
br i1 %28, label %29, label %40
29: ; preds = %27
%30 = load i8*, i8** %11
%31 = call i32 @strtoul(i8* %30, i32* null, i32 0)
%32 = load i32*, i32** %6
%33 = load i32, i32* %8
%34 = zext i32 %33 to i64
%35 = getelementptr inbounds i32, i32* %32, i64 %34
store i32 %31, i32* %35
%36 = call i8* @strtok_r(i8* null, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8** %9)
store i8* %36, i8** %11
br label %37
37: ; preds = %29
%38 = load i32, i32* %8
%39 = add i32 %38, 1
store i32 %39, i32* %8
br label %20
40: ; preds = %27
%41 = load i8*, i8** %10
%42 = call i32 @free(i8* %41)
store i32 0, i32* %4
br label %43
43: ; preds = %40, %16
%44 = load i32, i32* %4
ret i32 %44
}

LLVM IR (-O2):
@.str = [6 x i8] c", :;|\00"
define i32 @msr_core_ids(i8* nocapture %0, i32* nocapture writeonly %1, i32 %2) {
%4 = alloca i8*
%5 = bitcast i8** %4 to i8*
%6 = tail call i8* @strdup(i8* %0)
%7 = icmp eq i8* %6, null
br i1 %7, label %27, label %8
8: ; preds = %3
%9 = call i8* @strtok_r(i8* %6, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8** %4)
%10 = icmp ne i8* %9, null
%11 = icmp ne i32 %2, 0
%12 = and i1 %10, %11
br i1 %12, label %13, label %25
13: ; preds = %8
%14 = zext i32 %2 to i64
br label %15
15: ; preds = %13, %15
%16 = phi i64 [ 0, %13 ], [ %21, %15 ]
%17 = phi i8* [ %9, %13 ], [ %20, %15 ]
%18 = call i32 @strtoul(i8* nocapture %17, i32* null, i32 0)
%19 = getelementptr inbounds i32, i32* %1, i64 %16
store i32 %18, i32* %19
%20 = call i8* @strtok_r(i8* null, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8** %4)
%21 = add nuw nsw i64 %16, 1
%22 = icmp ne i8* %20, null
%23 = icmp ult i64 %21, %14
%24 = select i1 %22, i1 %23, i1 false
br i1 %24, label %15, label %25
25: ; preds = %15, %8
%26 = call i32 @free(i8* %6)
br label %27
27: ; preds = %3, %25
%28 = phi i32 [ 0, %25 ], [ -1, %3 ]
ret i32 %28
}