#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*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(char *);
char *getenv(char *);
void *malloc(int);
int /*<<< orphan*/ memcpy(char *, char *, int);
scalar_t__ parse_int(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stderr;
unsigned int strlen(char *);
char *strtok(char *, char *);
void mt_get_options(unsigned int *nr_cpus, unsigned int **cpus) {
  unsigned int i;
  char *s, *e, *token;
  e = getenv("MT_CONF");
  if (!e) {
    printf("%s empty: setting default mt options: 0\n", "MT_CONF");
    *nr_cpus = 1;
    *cpus = malloc(sizeof(unsigned int) * (*nr_cpus));
    if (!*cpus) {
      fprintf(stderr, "mt_get_options: malloc failed\n");
      exit(1);
    }
    *cpus[0] = 0;
    return;
  }
  s = malloc(strlen(e) + 1);
  if (!s) {
    fprintf(stderr, "mt_get_options: malloc failed\n");
    exit(1);
  }
  memcpy(s, e, strlen(e) + 1);
  *nr_cpus = 1;
  for (i = 0; i < strlen(s); i++) {
    if (s[i] == ',') {
      *nr_cpus = *nr_cpus + 1;
    }
  }
  i = 0;
  *cpus = malloc(sizeof(unsigned int) * (*nr_cpus));
  if (!(*cpus)) {
    fprintf(stderr, "mt_get_options: malloc failed\n");
    exit(1);
  }
  token = strtok(s, ",");
  do {
    (*cpus)[i++] = (unsigned int)parse_int(token);
  } while ((token = strtok(NULL, ",")));
  free(s);
  return;
}


x86 assembly (clang, -O0):
<mt_get_options>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe49(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1242 <mt_get_options+0xa2>
lea    0xe36(%rip),%rdi
lea    0xe27(%rip),%rsi
call   1060 <printf@plt>
mov    -0x8(%rbp),%rax
movl   $0x1,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
shl    $0x2,%rax
mov    %eax,%edi
call   1090 <malloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1230 <mt_get_options+0x90>
mov    0x2dc8(%rip),%rax
mov    (%rax),%edi
lea    0xe10(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movl   $0x0,(%rax)
jmp    13bd <mt_get_options+0x21d>
mov    -0x28(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%edi
add    $0x1,%edi
call   1090 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1283 <mt_get_options+0xe3>
mov    0x2d75(%rip),%rax
mov    (%rax),%edi
lea    0xdbd(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    %eax,%edx
add    $0x1,%edx
call   1080 <memcpy@plt>
mov    -0x8(%rbp),%rax
movl   $0x1,(%rax)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x44(%rbp),%eax
cmp    %ecx,%eax
jae    1311 <mt_get_options+0x171>
mov    -0x20(%rbp),%rax
mov    -0x14(%rbp),%ecx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2c,%eax
jne    12fe <mt_get_options+0x15e>
mov    -0x8(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
jmp    1303 <mt_get_options+0x163>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    12bf <mt_get_options+0x11f>
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
shl    $0x2,%rax
mov    %eax,%edi
call   1090 <malloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1360 <mt_get_options+0x1c0>
mov    0x2c98(%rip),%rax
mov    (%rax),%edi
lea    0xce0(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x20(%rbp),%rdi
lea    0xce5(%rip),%rsi
call   10a0 <strtok@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
call   10c0 <parse_int@plt>
mov    %eax,%edx
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    -0x14(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x14(%rbp)
mov    %ecx,%ecx
mov    %edx,(%rax,%rcx,4)
xor    %eax,%eax
mov    %eax,%edi
lea    0xcaf(%rip),%rsi
call   10a0 <strtok@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    1374 <mt_get_options+0x1d4>
mov    -0x20(%rbp),%rdi
call   1040 <free@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mt_get_options>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xe4a(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1293 <mt_get_options+0xf3>
mov    %rax,%r12
mov    %rax,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%edi
call   1090 <malloc@plt>
test   %rax,%rax
je     12cf <mt_get_options+0x12f>
mov    %rax,%r13
mov    %r12,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%edx
mov    %r13,%rdi
mov    %r12,%rsi
call   1080 <memcpy@plt>
movl   $0x1,(%r15)
mov    %r13,%rdi
call   1050 <strlen@plt>
test   %eax,%eax
je     1231 <mt_get_options+0x91>
xor    %ebx,%ebx
jmp    1223 <mt_get_options+0x83>
add    $0x1,%rbx
mov    %r13,%rdi
call   1050 <strlen@plt>
mov    %eax,%eax
cmp    %rax,%rbx
jae    1231 <mt_get_options+0x91>
cmpb   $0x2c,0x0(%r13,%rbx,1)
jne    1210 <mt_get_options+0x70>
addl   $0x1,(%r15)
jmp    1210 <mt_get_options+0x70>
mov    (%r15),%edi
shl    $0x2,%edi
call   1090 <malloc@plt>
mov    %rax,(%r14)
test   %rax,%rax
je     12cf <mt_get_options+0x12f>
lea    0xe01(%rip),%r15
mov    %r13,%rdi
mov    %r15,%rsi
call   10a0 <strtok@plt>
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    %rax,%rdi
call   10c0 <parse_int@plt>
mov    (%r14),%rcx
mov    %ebx,%edx
add    $0x1,%ebx
mov    %eax,(%rcx,%rdx,4)
xor    %edi,%edi
mov    %r15,%rsi
call   10a0 <strtok@plt>
test   %rax,%rax
jne    1260 <mt_get_options+0xc0>
mov    %r13,%rdi
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1040 <free@plt>
lea    0xd6e(%rip),%rdi
lea    0xd5f(%rip),%rsi
call   1060 <printf@plt>
movl   $0x1,(%r15)
mov    $0x4,%edi
call   1090 <malloc@plt>
mov    %rax,(%r14)
test   %rax,%rax
je     12cf <mt_get_options+0x12f>
movl   $0x0,(%rax)
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
mov    0x2d0a(%rip),%rax
mov    (%rax),%edi
lea    0xd52(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"MT_CONF\00"
@.str.1 = [41 x i8] c"%s empty: setting default mt options: 0\0A\00"
@stderr = global i32 0
@.str.2 = [31 x i8] c"mt_get_options: malloc failed\0A\00"
@.str.3 = [2 x i8] c",\00"
define void @mt_get_options(i32* %0, i32** %1) {
%3 = alloca i32*
%4 = alloca i32**
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
store i32* %0, i32** %3
store i32** %1, i32*** %4
%9 = call i8* @getenv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
store i8* %9, i8** %7
%10 = load i8*, i8** %7
%11 = icmp ne i8* %10, null
br i1 %11, label %34, label %12
12: ; preds = %2
%13 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%14 = load i32*, i32** %3
store i32 1, i32* %14
%15 = load i32*, i32** %3
%16 = load i32, i32* %15
%17 = zext i32 %16 to i64
%18 = mul i64 4, %17
%19 = trunc i64 %18 to i32
%20 = call i8* @malloc(i32 %19)
%21 = bitcast i8* %20 to i32*
%22 = load i32**, i32*** %4
store i32* %21, i32** %22
%23 = load i32**, i32*** %4
%24 = load i32*, i32** %23
%25 = icmp ne i32* %24, null
br i1 %25, label %30, label %26
26: ; preds = %12
%27 = load i32, i32* @stderr
%28 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %12
%31 = load i32**, i32*** %4
%32 = getelementptr inbounds i32*, i32** %31, i64 0
%33 = load i32*, i32** %32
store i32 0, i32* %33
br label %110
34: ; preds = %2
%35 = load i8*, i8** %7
%36 = call i32 @strlen(i8* %35)
%37 = add i32 %36, 1
%38 = call i8* @malloc(i32 %37)
store i8* %38, i8** %6
%39 = load i8*, i8** %6
%40 = icmp ne i8* %39, null
br i1 %40, label %45, label %41
41: ; preds = %34
%42 = load i32, i32* @stderr
%43 = call i32 @fprintf(i32 %42, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
%44 = call i32 @exit(i32 1)
unreachable
45: ; preds = %34
%46 = load i8*, i8** %6
%47 = load i8*, i8** %7
%48 = load i8*, i8** %7
%49 = call i32 @strlen(i8* %48)
%50 = add i32 %49, 1
%51 = call i32 @memcpy(i8* %46, i8* %47, i32 %50)
%52 = load i32*, i32** %3
store i32 1, i32* %52
store i32 0, i32* %5
br label %53
53: ; preds = %72, %45
%54 = load i32, i32* %5
%55 = load i8*, i8** %6
%56 = call i32 @strlen(i8* %55)
%57 = icmp ult i32 %54, %56
br i1 %57, label %58, label %75
58: ; preds = %53
%59 = load i8*, i8** %6
%60 = load i32, i32* %5
%61 = zext i32 %60 to i64
%62 = getelementptr inbounds i8, i8* %59, i64 %61
%63 = load i8, i8* %62
%64 = sext i8 %63 to i32
%65 = icmp eq i32 %64, 44
br i1 %65, label %66, label %71
66: ; preds = %58
%67 = load i32*, i32** %3
%68 = load i32, i32* %67
%69 = add i32 %68, 1
%70 = load i32*, i32** %3
store i32 %69, i32* %70
br label %71
71: ; preds = %66, %58
br label %72
72: ; preds = %71
%73 = load i32, i32* %5
%74 = add i32 %73, 1
store i32 %74, i32* %5
br label %53
75: ; preds = %53
store i32 0, i32* %5
%76 = load i32*, i32** %3
%77 = load i32, i32* %76
%78 = zext i32 %77 to i64
%79 = mul i64 4, %78
%80 = trunc i64 %79 to i32
%81 = call i8* @malloc(i32 %80)
%82 = bitcast i8* %81 to i32*
%83 = load i32**, i32*** %4
store i32* %82, i32** %83
%84 = load i32**, i32*** %4
%85 = load i32*, i32** %84
%86 = icmp ne i32* %85, null
br i1 %86, label %91, label %87
87: ; preds = %75
%88 = load i32, i32* @stderr
%89 = call i32 @fprintf(i32 %88, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
%90 = call i32 @exit(i32 1)
unreachable
91: ; preds = %75
%92 = load i8*, i8** %6
%93 = call i8* @strtok(i8* %92, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i8* %93, i8** %8
br label %94
94: ; preds = %104, %91
%95 = load i8*, i8** %8
%96 = call i64 @parse_int(i8* %95)
%97 = trunc i64 %96 to i32
%98 = load i32**, i32*** %4
%99 = load i32*, i32** %98
%100 = load i32, i32* %5
%101 = add i32 %100, 1
store i32 %101, i32* %5
%102 = zext i32 %100 to i64
%103 = getelementptr inbounds i32, i32* %99, i64 %102
store i32 %97, i32* %103
br label %104
104: ; preds = %94
%105 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i8* %105, i8** %8
%106 = icmp ne i8* %105, null
br i1 %106, label %94, label %107
107: ; preds = %104
%108 = load i8*, i8** %6
%109 = call i32 @free(i8* %108)
br label %110
110: ; preds = %107, %30
ret void
}

LLVM IR (-O2):
@.str = [8 x i8] c"MT_CONF\00"
@.str.1 = [41 x i8] c"%s empty: setting default mt options: 0\0A\00"
@stderr = global i32 0
@.str.2 = [31 x i8] c"mt_get_options: malloc failed\0A\00"
@.str.3 = [2 x i8] c",\00"
define void @mt_get_options(i32* nocapture %0, i32** nocapture %1) {
%3 = tail call i8* @getenv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i8* %3, null
br i1 %4, label %5, label %16
5: ; preds = %2
%6 = tail call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %0
%7 = tail call dereferenceable_or_null(4) i8* @malloc(i32 4)
%8 = bitcast i32** %1 to i8**
store i8* %7, i8** %8
%9 = icmp eq i8* %7, null
br i1 %9, label %10, label %14
10: ; preds = %5
%11 = load i32, i32* @stderr
%12 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %5
%15 = bitcast i8* %7 to i32*
store i32 0, i32* %15
br label %69
16: ; preds = %2
%17 = tail call i32 @strlen(i8* %3)
%18 = add i32 %17, 1
%19 = tail call i8* @malloc(i32 %18)
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %25
21: ; preds = %16
%22 = load i32, i32* @stderr
%23 = tail call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
%24 = tail call i32 @exit(i32 1)
unreachable
25: ; preds = %16
%26 = tail call i32 @strlen(i8* %3)
%27 = add i32 %26, 1
%28 = tail call i32 @memcpy(i8* %19, i8* %3, i32 %27)
store i32 1, i32* %0
%29 = tail call i32 @strlen(i8* %19)
%30 = icmp eq i32 %29, 0
br i1 %30, label %44, label %31
31: ; preds = %25, %39
%32 = phi i64 [ %40, %39 ], [ 0, %25 ]
%33 = getelementptr inbounds i8, i8* %19, i64 %32
%34 = load i8, i8* %33
%35 = icmp eq i8 %34, 44
br i1 %35, label %36, label %39
36: ; preds = %31
%37 = load i32, i32* %0
%38 = add i32 %37, 1
store i32 %38, i32* %0
br label %39
39: ; preds = %31, %36
%40 = add nuw nsw i64 %32, 1
%41 = tail call i32 @strlen(i8* %19)
%42 = zext i32 %41 to i64
%43 = icmp ult i64 %40, %42
br i1 %43, label %31, label %44
44: ; preds = %39, %25
%45 = load i32, i32* %0
%46 = shl i32 %45, 2
%47 = tail call i8* @malloc(i32 %46)
%48 = bitcast i32** %1 to i8**
store i8* %47, i8** %48
%49 = icmp eq i8* %47, null
br i1 %49, label %50, label %54
50: ; preds = %44
%51 = load i32, i32* @stderr
%52 = tail call i32 @fprintf(i32 %51, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
%53 = tail call i32 @exit(i32 1)
unreachable
54: ; preds = %44
%55 = tail call i8* @strtok(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %56
56: ; preds = %56, %54
%57 = phi i32 [ 0, %54 ], [ %62, %56 ]
%58 = phi i8* [ %55, %54 ], [ %65, %56 ]
%59 = tail call i64 @parse_int(i8* %58)
%60 = trunc i64 %59 to i32
%61 = load i32*, i32** %1
%62 = add i32 %57, 1
%63 = zext i32 %57 to i64
%64 = getelementptr inbounds i32, i32* %61, i64 %63
store i32 %60, i32* %64
%65 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%66 = icmp eq i8* %65, null
br i1 %66, label %67, label %56
67: ; preds = %56
%68 = tail call i32 @free(i8* %19)
br label %69
69: ; preds = %67, %14
ret void
}