#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 */
typedef int /*<<< orphan*/ cpu_set_t;

/* Variables and functions */
int /*<<< orphan*/ CPU_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ CPU_ZERO(int /*<<< orphan*/ *);
int atoi(char *);
int /*<<< orphan*/ decode_error(char *, char *);
int /*<<< orphan*/ exit(int);
scalar_t__ isdigit(int);
int /*<<< orphan*/ str_to_cpuset(int /*<<< orphan*/ *, char *);
char *strsep(char **, char *);
size_t strspn(char *, char *);
int parse_affinity(cpu_set_t *mask, char *arg) {
  cpu_set_t tmp_aff;
  char *tmp_arg;
  size_t valid_len;
  CPU_ZERO(&tmp_aff);
  if (*arg == '0' && *(arg + 1) == 'x') {
    str_to_cpuset(&tmp_aff, arg);
  } else if ((valid_len = strspn(arg, "0123456789,."))) {
    while ((tmp_arg = strsep(&arg, ",."))) {
      int tmp_cpu;
      if (isdigit((int)*tmp_arg)) {
        tmp_cpu = atoi(tmp_arg);
        CPU_SET(tmp_cpu, &tmp_aff);
      }
    }
  } else {
    decode_error("affinity %s is not parseable", arg);
    exit(1);
  }
  *mask = tmp_aff;
  return 0;
}


x86 assembly (clang, -O0):
<parse_affinity>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x14(%rbp),%rdi
call   1070 <CPU_ZERO@plt>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x30,%eax
jne    11dc <parse_affinity+0x4c>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x78,%eax
jne    11dc <parse_affinity+0x4c>
mov    -0x10(%rbp),%rsi
lea    -0x14(%rbp),%rdi
call   1080 <str_to_cpuset@plt>
jmp    1274 <parse_affinity+0xe4>
mov    -0x10(%rbp),%rdi
lea    0xe19(%rip),%rsi
call   1040 <strspn@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     1255 <parse_affinity+0xc5>
jmp    11ff <parse_affinity+0x6f>
lea    -0x10(%rbp),%rdi
lea    0xe00(%rip),%rsi
call   1060 <strsep@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     1250 <parse_affinity+0xc0>
mov    -0x20(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     124b <parse_affinity+0xbb>
mov    -0x20(%rbp),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%edi
lea    -0x14(%rbp),%rsi
call   10b0 <CPU_SET@plt>
jmp    11ff <parse_affinity+0x6f>
jmp    126f <parse_affinity+0xdf>
mov    -0x10(%rbp),%rsi
lea    0xdad(%rip),%rdi
call   1050 <decode_error@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
jmp    1274 <parse_affinity+0xe4>
mov    -0x14(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_affinity>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,0x8(%rsp)
lea    0x4(%rsp),%rdi
call   1070 <CPU_ZERO@plt>
cmpb   $0x30,(%rbx)
jne    11cc <parse_affinity+0x3c>
cmpb   $0x78,0x1(%rbx)
jne    11cc <parse_affinity+0x3c>
lea    0x4(%rsp),%rdi
mov    %rbx,%rsi
call   1080 <str_to_cpuset@plt>
jmp    1244 <parse_affinity+0xb4>
lea    0xe2d(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strspn@plt>
test   %rax,%rax
je     125b <parse_affinity+0xcb>
lea    0xe23(%rip),%rsi
lea    0x8(%rsp),%rdi
call   1060 <strsep@plt>
test   %rax,%rax
je     1244 <parse_affinity+0xb4>
mov    %rax,%rbx
lea    0xe0a(%rip),%r15
lea    0x8(%rsp),%r13
lea    0x4(%rsp),%r12
jmp    1223 <parse_affinity+0x93>
nopl   0x0(%rax)
mov    %r13,%rdi
mov    %r15,%rsi
call   1060 <strsep@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1244 <parse_affinity+0xb4>
movsbl (%rbx),%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     1210 <parse_affinity+0x80>
mov    %rbx,%rdi
call   1090 <atoi@plt>
mov    %eax,%edi
mov    %r12,%rsi
call   10b0 <CPU_SET@plt>
jmp    1210 <parse_affinity+0x80>
mov    0x4(%rsp),%eax
mov    %eax,(%r14)
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
lea    0xdab(%rip),%rdi
mov    %rbx,%rsi
call   1050 <decode_error@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [13 x i8] c"0123456789,.\00"
@.str.1 = [3 x i8] c",.\00"
@.str.2 = [29 x i8] c"affinity %s is not parseable\00"
define i32 @parse_affinity(i32* %0, i8* %1) {
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
store i32* %0, i32** %3
store i8* %1, i8** %4
%9 = call i32 @CPU_ZERO(i32* %5)
%10 = load i8*, i8** %4
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp eq i32 %12, 48
br i1 %13, label %14, label %23
14: ; preds = %2
%15 = load i8*, i8** %4
%16 = getelementptr inbounds i8, i8* %15, i64 1
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp eq i32 %18, 120
br i1 %19, label %20, label %23
20: ; preds = %14
%21 = load i8*, i8** %4
%22 = call i32 @str_to_cpuset(i32* %5, i8* %21)
br label %49
23: ; preds = %14, %2
%24 = load i8*, i8** %4
%25 = call i64 @strspn(i8* %24, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
store i64 %25, i64* %7
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %44
27: ; preds = %23
br label %28
28: ; preds = %42, %27
%29 = call i8* @strsep(i8** %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i8* %29, i8** %6
%30 = icmp ne i8* %29, null
br i1 %30, label %31, label %43
31: ; preds = %28
%32 = load i8*, i8** %6
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = call i64 @isdigit(i32 %34)
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %42
37: ; preds = %31
%38 = load i8*, i8** %6
%39 = call i32 @atoi(i8* %38)
store i32 %39, i32* %8
%40 = load i32, i32* %8
%41 = call i32 @CPU_SET(i32 %40, i32* %5)
br label %42
42: ; preds = %37, %31
br label %28
43: ; preds = %28
br label %48
44: ; preds = %23
%45 = load i8*, i8** %4
%46 = call i32 @decode_error(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8* %45)
%47 = call i32 @exit(i32 1)
unreachable
48: ; preds = %43
br label %49
49: ; preds = %48, %20
%50 = load i32, i32* %5
%51 = load i32*, i32** %3
store i32 %50, i32* %51
ret i32 0
}

LLVM IR (-O2):
@.str = [13 x i8] c"0123456789,.\00"
@.str.1 = [3 x i8] c",.\00"
@.str.2 = [29 x i8] c"affinity %s is not parseable\00"
define i32 @parse_affinity(i32* nocapture writeonly %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i32
store i8* %1, i8** %3
%5 = bitcast i32* %4 to i8*
%6 = call i32 @CPU_ZERO(i32* %4)
%7 = load i8, i8* %1
%8 = icmp eq i8 %7, 48
br i1 %8, label %9, label %15
9: ; preds = %2
%10 = getelementptr inbounds i8, i8* %1, i64 1
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 120
br i1 %12, label %13, label %15
13: ; preds = %9
%14 = call i32 @str_to_cpuset(i32* %4, i8* %1)
br label %36
15: ; preds = %9, %2
%16 = call i64 @strspn(i8* %1, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%17 = icmp eq i64 %16, 0
br i1 %17, label %33, label %18
18: ; preds = %15
%19 = call i8* @strsep(i8** %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%20 = icmp eq i8* %19, null
br i1 %20, label %36, label %21
21: ; preds = %18, %30
%22 = phi i8* [ %31, %30 ], [ %19, %18 ]
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = call i64 @isdigit(i32 %24)
%26 = icmp eq i64 %25, 0
br i1 %26, label %30, label %27
27: ; preds = %21
%28 = call i32 @atoi(i8* %22)
%29 = call i32 @CPU_SET(i32 %28, i32* %4)
br label %30
30: ; preds = %27, %21
%31 = call i8* @strsep(i8** %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%32 = icmp eq i8* %31, null
br i1 %32, label %36, label %21
33: ; preds = %15
%34 = call i32 @decode_error(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8* %1)
%35 = call i32 @exit(i32 1)
unreachable
36: ; preds = %30, %18, %13
%37 = load i32, i32* %4
store i32 %37, i32* %0
ret i32 0
}