#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*/ fprintf(int /*<<< orphan*/, char *, int, int);
char *getenv(char *);
int reverse_bits(int);
int sched_ncpus();
int /*<<< orphan*/ stderr;
scalar_t__ strcasecmp(char *, char *);
int handle_scheduler(int childno, int benchproc, int nbenchprocs) {
  int cpu = 0;
  char *sched = getenv("LMBENCH_SCHED");
  if (!sched || strcasecmp(sched, "DEFAULT") == 0) {
    return 0;
  } else if (strcasecmp(sched, "SINGLE") == 0) {
    cpu = 0;
  } else if (strcasecmp(sched, "BALANCED") == 0) {
    cpu = childno;
  } else if (strcasecmp(sched, "BALANCED_SPREAD") == 0) {
    cpu = reverse_bits(childno);
  } else if (strcasecmp(sched, "UNIQUE") == 0) {
    cpu = childno * (nbenchprocs + 1) + benchproc;
  } else if (strcasecmp(sched, "UNIQUE_SPREAD") == 0) {
    cpu = reverse_bits(childno * (nbenchprocs + 1) + benchproc);
  } else {
    return 0;
  }
  (void)fprintf(stderr,
                "cpu = %d, sched_ncpus() = %d"
                "\n",
                cpu, sched_ncpus());
  return 0;
}


x86 assembly (clang, -O0):
<handle_scheduler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
lea    0xe91(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     119d <handle_scheduler+0x4d>
mov    -0x20(%rbp),%rdi
lea    0xe80(%rip),%rsi
call   1040 <strcasecmp@plt>
cmp    $0x0,%rax
jne    11a9 <handle_scheduler+0x59>
movl   $0x0,-0x4(%rbp)
jmp    12de <handle_scheduler+0x18e>
mov    -0x20(%rbp),%rdi
lea    0xe62(%rip),%rsi
call   1040 <strcasecmp@plt>
cmp    $0x0,%rax
jne    11cf <handle_scheduler+0x7f>
movl   $0x0,-0x14(%rbp)
jmp    12a5 <handle_scheduler+0x155>
mov    -0x20(%rbp),%rdi
lea    0xe43(%rip),%rsi
call   1040 <strcasecmp@plt>
cmp    $0x0,%rax
jne    11f4 <handle_scheduler+0xa4>
mov    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    12a0 <handle_scheduler+0x150>
mov    -0x20(%rbp),%rdi
lea    0xe27(%rip),%rsi
call   1040 <strcasecmp@plt>
cmp    $0x0,%rax
jne    121e <handle_scheduler+0xce>
mov    -0x8(%rbp),%edi
call   1050 <reverse_bits@plt>
mov    %eax,-0x14(%rbp)
jmp    129b <handle_scheduler+0x14b>
mov    -0x20(%rbp),%rdi
lea    0xe0d(%rip),%rsi
call   1040 <strcasecmp@plt>
cmp    $0x0,%rax
jne    124f <handle_scheduler+0xff>
mov    -0x8(%rbp),%eax
mov    -0x10(%rbp),%ecx
add    $0x1,%ecx
imul   %ecx,%eax
add    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    1296 <handle_scheduler+0x146>
mov    -0x20(%rbp),%rdi
lea    0xde3(%rip),%rsi
call   1040 <strcasecmp@plt>
cmp    $0x0,%rax
jne    1285 <handle_scheduler+0x135>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%eax
add    $0x1,%eax
imul   %eax,%edi
add    -0xc(%rbp),%edi
call   1050 <reverse_bits@plt>
mov    %eax,-0x14(%rbp)
jmp    1291 <handle_scheduler+0x141>
movl   $0x0,-0x4(%rbp)
jmp    12de <handle_scheduler+0x18e>
jmp    1296 <handle_scheduler+0x146>
jmp    129b <handle_scheduler+0x14b>
jmp    12a0 <handle_scheduler+0x150>
jmp    12a5 <handle_scheduler+0x155>
jmp    12aa <handle_scheduler+0x15a>
mov    0x2d2f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    $0x0,%al
call   1070 <sched_ncpus@plt>
mov    -0x28(%rbp),%edi
mov    -0x24(%rbp),%edx
mov    %eax,%ecx
lea    0xd79(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handle_scheduler>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r15d
mov    %esi,%r14d
mov    %edi,%ebx
lea    0xe9a(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1242 <handle_scheduler+0xf2>
mov    %rax,%rbp
lea    0xe90(%rip),%rsi
mov    %rax,%rdi
call   1040 <strcasecmp@plt>
test   %rax,%rax
je     1242 <handle_scheduler+0xf2>
lea    0xe80(%rip),%rsi
mov    %rbp,%rdi
call   1040 <strcasecmp@plt>
test   %rax,%rax
je     1203 <handle_scheduler+0xb3>
lea    0xe73(%rip),%rsi
mov    %rbp,%rdi
call   1040 <strcasecmp@plt>
test   %rax,%rax
je     1220 <handle_scheduler+0xd0>
lea    0xe68(%rip),%rsi
mov    %rbp,%rdi
call   1040 <strcasecmp@plt>
test   %rax,%rax
je     1207 <handle_scheduler+0xb7>
lea    0xe64(%rip),%rsi
mov    %rbp,%rdi
call   1040 <strcasecmp@plt>
test   %rax,%rax
je     1212 <handle_scheduler+0xc2>
lea    0xe57(%rip),%rsi
mov    %rbp,%rdi
call   1040 <strcasecmp@plt>
test   %rax,%rax
jne    1242 <handle_scheduler+0xf2>
add    $0x1,%r15d
imul   %ebx,%r15d
add    %r14d,%r15d
mov    %r15d,%edi
jmp    1209 <handle_scheduler+0xb9>
xor    %ebx,%ebx
jmp    1220 <handle_scheduler+0xd0>
mov    %ebx,%edi
call   1050 <reverse_bits@plt>
mov    %eax,%ebx
jmp    1220 <handle_scheduler+0xd0>
add    $0x1,%r15d
imul   %ebx,%r15d
add    %r14d,%r15d
mov    %r15d,%ebx
mov    0x2db9(%rip),%rax
mov    (%rax),%ebp
xor    %eax,%eax
call   1070 <sched_ncpus@plt>
lea    0xe14(%rip),%rsi
mov    %ebp,%edi
mov    %ebx,%edx
mov    %eax,%ecx
call   1060 <fprintf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"LMBENCH_SCHED\00"
@.str.1 = [8 x i8] c"DEFAULT\00"
@.str.2 = [7 x i8] c"SINGLE\00"
@.str.3 = [9 x i8] c"BALANCED\00"
@.str.4 = [16 x i8] c"BALANCED_SPREAD\00"
@.str.5 = [7 x i8] c"UNIQUE\00"
@.str.6 = [14 x i8] c"UNIQUE_SPREAD\00"
@stderr = global i32 0
@.str.7 = [30 x i8] c"cpu = %d, sched_ncpus() = %d\0A\00"
define i32 @handle_scheduler(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 0, i32* %8
%10 = call i8* @getenv(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
store i8* %10, i8** %9
%11 = load i8*, i8** %9
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %17
13: ; preds = %3
%14 = load i8*, i8** %9
%15 = call i64 @strcasecmp(i8* %14, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %13, %3
store i32 0, i32* %4
br label %70
18: ; preds = %13
%19 = load i8*, i8** %9
%20 = call i64 @strcasecmp(i8* %19, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %18
store i32 0, i32* %8
br label %64
23: ; preds = %18
%24 = load i8*, i8** %9
%25 = call i64 @strcasecmp(i8* %24, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %23
%28 = load i32, i32* %5
store i32 %28, i32* %8
br label %63
29: ; preds = %23
%30 = load i8*, i8** %9
%31 = call i64 @strcasecmp(i8* %30, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %29
%34 = load i32, i32* %5
%35 = call i32 @reverse_bits(i32 %34)
store i32 %35, i32* %8
br label %62
36: ; preds = %29
%37 = load i8*, i8** %9
%38 = call i64 @strcasecmp(i8* %37, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %47
40: ; preds = %36
%41 = load i32, i32* %5
%42 = load i32, i32* %7
%43 = add nsw i32 %42, 1
%44 = mul nsw i32 %41, %43
%45 = load i32, i32* %6
%46 = add nsw i32 %44, %45
store i32 %46, i32* %8
br label %61
47: ; preds = %36
%48 = load i8*, i8** %9
%49 = call i64 @strcasecmp(i8* %48, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0))
%50 = icmp eq i64 %49, 0
br i1 %50, label %51, label %59
51: ; preds = %47
%52 = load i32, i32* %5
%53 = load i32, i32* %7
%54 = add nsw i32 %53, 1
%55 = mul nsw i32 %52, %54
%56 = load i32, i32* %6
%57 = add nsw i32 %55, %56
%58 = call i32 @reverse_bits(i32 %57)
store i32 %58, i32* %8
br label %60
59: ; preds = %47
store i32 0, i32* %4
br label %70
60: ; preds = %51
br label %61
61: ; preds = %60, %40
br label %62
62: ; preds = %61, %33
br label %63
63: ; preds = %62, %27
br label %64
64: ; preds = %63, %22
br label %65
65: ; preds = %64
%66 = load i32, i32* @stderr
%67 = load i32, i32* %8
%68 = call i32 (...) @sched_ncpus()
%69 = call i32 @fprintf(i32 %66, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.7, i64 0, i64 0), i32 %67, i32 %68)
store i32 0, i32* %4
br label %70
70: ; preds = %65, %59, %17
%71 = load i32, i32* %4
ret i32 %71
}

LLVM IR (-O2):
@.str = [14 x i8] c"LMBENCH_SCHED\00"
@.str.1 = [8 x i8] c"DEFAULT\00"
@.str.2 = [7 x i8] c"SINGLE\00"
@.str.3 = [9 x i8] c"BALANCED\00"
@.str.4 = [16 x i8] c"BALANCED_SPREAD\00"
@.str.5 = [7 x i8] c"UNIQUE\00"
@.str.6 = [14 x i8] c"UNIQUE_SPREAD\00"
@stderr = global i32 0
@.str.7 = [30 x i8] c"cpu = %d, sched_ncpus() = %d\0A\00"
define i32 @handle_scheduler(i32 %0, i32 %1, i32 %2) {
%4 = tail call i8* @getenv(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i8* %4, null
br i1 %5, label %40, label %6
6: ; preds = %3
%7 = tail call i64 @strcasecmp(i8* %4, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i64 %7, 0
br i1 %8, label %40, label %9
9: ; preds = %6
%10 = tail call i64 @strcasecmp(i8* %4, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%11 = icmp eq i64 %10, 0
br i1 %11, label %35, label %12
12: ; preds = %9
%13 = tail call i64 @strcasecmp(i8* %4, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
br i1 %14, label %35, label %15
15: ; preds = %12
%16 = tail call i64 @strcasecmp(i8* %4, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %15
%19 = tail call i32 @reverse_bits(i32 %0)
br label %35
20: ; preds = %15
%21 = tail call i64 @strcasecmp(i8* %4, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %27
23: ; preds = %20
%24 = add nsw i32 %2, 1
%25 = mul nsw i32 %24, %0
%26 = add nsw i32 %25, %1
br label %35
27: ; preds = %20
%28 = tail call i64 @strcasecmp(i8* %4, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0))
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %40
30: ; preds = %27
%31 = add nsw i32 %2, 1
%32 = mul nsw i32 %31, %0
%33 = add nsw i32 %32, %1
%34 = tail call i32 @reverse_bits(i32 %33)
br label %35
35: ; preds = %12, %9, %18, %30, %23
%36 = phi i32 [ %19, %18 ], [ %26, %23 ], [ %34, %30 ], [ 0, %9 ], [ %0, %12 ]
%37 = load i32, i32* @stderr
%38 = tail call i32 (...) @sched_ncpus()
%39 = tail call i32 @fprintf(i32 %37, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.7, i64 0, i64 0), i32 %36, i32 %38)
br label %40
40: ; preds = %27, %3, %6, %35
ret i32 0
}