#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 msr_count(char *env_cores) {
  unsigned int ncores = 0;
  char *saveptr;
  char *env_cores_tmp = strdup(env_cores);
  if (env_cores_tmp == NULL) {
    return 0;
  }
  char *tok = strtok_r(env_cores_tmp, ", :;|", &saveptr);
  while (tok) {
    ncores++;
    tok = strtok_r(NULL, ", :;|", &saveptr);
  }
  free(env_cores_tmp);
  return ncores;
}


x86 assembly (clang, -O0):
<msr_count>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strdup@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1167 <msr_count+0x37>
movl   $0x0,-0x4(%rbp)
jmp    11bf <msr_count+0x8f>
mov    -0x28(%rbp),%rdi
lea    0xe8e(%rip),%rsi
lea    -0x20(%rbp),%rdx
call   1040 <strtok_r@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     11b0 <msr_count+0x80>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xe62(%rip),%rsi
lea    -0x20(%rbp),%rdx
call   1040 <strtok_r@plt>
mov    %rax,-0x30(%rbp)
jmp    117f <msr_count+0x4f>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<msr_count>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
call   1050 <strdup@plt>
test   %rax,%rax
je     118f <msr_count+0x5f>
mov    %rax,%r14
lea    0xeb4(%rip),%rsi
mov    %rsp,%rdx
mov    %rax,%rdi
call   1040 <strtok_r@plt>
xor    %ebx,%ebx
test   %rax,%rax
je     1185 <msr_count+0x55>
lea    0xe9b(%rip),%r15
mov    %rsp,%r12
nopl   0x0(%rax,%rax,1)
add    $0x1,%ebx
xor    %edi,%edi
mov    %r15,%rsi
mov    %r12,%rdx
call   1040 <strtok_r@plt>
test   %rax,%rax
jne    1170 <msr_count+0x40>
mov    %r14,%rdi
call   1030 <free@plt>
jmp    1191 <msr_count+0x61>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [6 x i8] c", :;|\00"
define i32 @msr_count(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
store i8* %0, i8** %3
store i32 0, i32* %4
%8 = load i8*, i8** %3
%9 = call i8* @strdup(i8* %8)
store i8* %9, i8** %6
%10 = load i8*, i8** %6
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %13
12: ; preds = %1
store i32 0, i32* %2
br label %27
13: ; preds = %1
%14 = load i8*, i8** %6
%15 = call i8* @strtok_r(i8* %14, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8** %5)
store i8* %15, i8** %7
br label %16
16: ; preds = %19, %13
%17 = load i8*, i8** %7
%18 = icmp ne i8* %17, null
br i1 %18, label %19, label %23
19: ; preds = %16
%20 = load i32, i32* %4
%21 = add i32 %20, 1
store i32 %21, i32* %4
%22 = call i8* @strtok_r(i8* null, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8** %5)
store i8* %22, i8** %7
br label %16
23: ; preds = %16
%24 = load i8*, i8** %6
%25 = call i32 @free(i8* %24)
%26 = load i32, i32* %4
store i32 %26, i32* %2
br label %27
27: ; preds = %23, %12
%28 = load i32, i32* %2
ret i32 %28
}

LLVM IR (-O2):
@.str = [6 x i8] c", :;|\00"
define i32 @msr_count(i8* nocapture %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
%4 = tail call i8* @strdup(i8* %0)
%5 = icmp eq i8* %4, null
br i1 %5, label %17, label %6
6: ; preds = %1
%7 = call i8* @strtok_r(i8* %4, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8** %2)
%8 = icmp eq i8* %7, null
br i1 %8, label %14, label %9
9: ; preds = %6, %9
%10 = phi i32 [ %11, %9 ], [ 0, %6 ]
%11 = add i32 %10, 1
%12 = call i8* @strtok_r(i8* null, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8** %2)
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %9
14: ; preds = %9, %6
%15 = phi i32 [ 0, %6 ], [ %11, %9 ]
%16 = call i32 @free(i8* %4)
br label %17
17: ; preds = %1, %14
%18 = phi i32 [ %15, %14 ], [ 0, %1 ]
ret i32 %18
}