#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*/ _SC_NPROCESSORS_CONF;
int atoi(int /*<<< orphan*/);
int /*<<< orphan*/ do_cpu_stress(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int getopt(int, char **, char *);
int /*<<< orphan*/ isprint(int);
int /*<<< orphan*/ optarg;
int optopt;
int /*<<< orphan*/ printf(char *, int, ...);
int /*<<< orphan*/ stderr;
int sysconf(int /*<<< orphan*/);
int /*<<< orphan*/ usage(char *);
int main(int argc, char **argv) {
  int return_code = 0;
  int NUM_PROCS = sysconf(_SC_NPROCESSORS_CONF);
  printf("System has %i processor(s).\n", NUM_PROCS);
  int num_cpus_to_spin = NUM_PROCS;
  int option = 0;
  while ((option = getopt(argc, argv, "m:c:l?ahd")) != -1) {
    switch (option) {
    case 'c':
      num_cpus_to_spin = atoi(optarg);
      if (num_cpus_to_spin < 1) {
        printf("WARNING: Must utilize at least 1 cpu. Spinning "
               " all %i cpu(s) instead...\n",
               NUM_PROCS);
        num_cpus_to_spin = 1;
      } else if (num_cpus_to_spin > NUM_PROCS) {
        printf("WARNING: %i cpu(s), are not "
               "available on this system, spinning all %i cpu(s) "
               "instead...\n",
               num_cpus_to_spin, NUM_PROCS);
        num_cpus_to_spin = NUM_PROCS;
      } else {
        printf("Maxing computation on %i cpu(s)...\n", num_cpus_to_spin);
      }
      break;
    case '?':
      if (isprint(optopt)) {
        fprintf(stderr, "Unknown option `-%c'.\n", optopt);
      } else {
        fprintf(stderr, "Unknown option character `\\x%x'.\n", optopt);
      }
      break;
    default:
      usage(argv[0]);
      exit(0);
    }
  }
  do_cpu_stress(num_cpus_to_spin);
  return return_code;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    0x2e14(%rip),%rax
mov    (%rax),%edi
call   1080 <sysconf@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%esi
lea    0xe38(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe33(%rip),%rdx
call   1090 <getopt@plt>
mov    %eax,-0x20(%rbp)
cmp    $0xffffffff,%eax
je     1313 <main+0x183>
mov    -0x20(%rbp),%eax
mov    %eax,-0x24(%rbp)
sub    $0x3f,%eax
je     129e <main+0x10e>
jmp    120f <main+0x7f>
mov    -0x24(%rbp),%eax
sub    $0x63,%eax
jne    12fb <main+0x16b>
jmp    1220 <main+0x90>
mov    0x2dd1(%rip),%rax
mov    (%rax),%edi
call   10a0 <atoi@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x1,-0x1c(%rbp)
jge    1258 <main+0xc8>
mov    -0x18(%rbp),%esi
lea    0xde2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x1c(%rbp)
jmp    1299 <main+0x109>
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jle    1283 <main+0xf3>
mov    -0x1c(%rbp),%esi
mov    -0x18(%rbp),%edx
lea    0xe00(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    1294 <main+0x104>
mov    -0x1c(%rbp),%esi
lea    0xe3d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1299 <main+0x109>
jmp    130e <main+0x17e>
mov    0x2d3b(%rip),%rax
mov    (%rax),%edi
call   1070 <isprint@plt>
cmp    $0x0,%eax
je     12d8 <main+0x148>
mov    0x2d14(%rip),%rax
mov    (%rax),%edi
mov    0x2d1b(%rip),%rax
mov    (%rax),%edx
lea    0xe20(%rip),%rsi
call   1050 <fprintf@plt>
jmp    12f6 <main+0x166>
mov    0x2cf1(%rip),%rax
mov    (%rax),%edi
mov    0x2cf8(%rip),%rax
mov    (%rax),%edx
lea    0xe14(%rip),%rsi
call   1050 <fprintf@plt>
jmp    130e <main+0x17e>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1060 <usage@plt>
xor    %edi,%edi
call   10b0 <exit@plt>
jmp    11dc <main+0x4c>
mov    -0x1c(%rbp),%edi
call   1030 <do_cpu_stress@plt>
mov    -0x14(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
call   1080 <sysconf@plt>
mov    %eax,%r12d
lea    0xe48(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe55(%rip),%r15
mov    0x2e11(%rip),%r14
mov    0x2dfa(%rip),%r13
mov    %r12d,0x4(%rsp)
mov    %r12d,(%rsp)
jmp    11ff <main+0x6f>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    0xef7(%rip),%rsi
mov    %r12d,%edx
call   1050 <fprintf@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1090 <getopt@plt>
cmp    $0x3f,%eax
jne    122d <main+0x9d>
mov    (%r14),%r12d
mov    %r12d,%edi
call   1070 <isprint@plt>
mov    0x0(%r13),%edi
test   %eax,%eax
jne    11f0 <main+0x60>
lea    0xeda(%rip),%rsi
jmp    11f7 <main+0x67>
cmp    $0xffffffff,%eax
je     12a8 <main+0x118>
cmp    $0x63,%eax
jne    12c1 <main+0x131>
mov    0x2db6(%rip),%rax
mov    (%rax),%edi
call   10a0 <atoi@plt>
test   %eax,%eax
jle    126a <main+0xda>
mov    0x4(%rsp),%edx
cmp    %edx,%eax
jg     1290 <main+0x100>
lea    0xe6e(%rip),%rdi
mov    %eax,(%rsp)
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11ff <main+0x6f>
lea    0xdb6(%rip),%rdi
mov    0x4(%rsp),%esi
xor    %eax,%eax
call   1040 <printf@plt>
movl   $0x1,(%rsp)
jmp    11ff <main+0x6f>
nopl   0x0(%rax,%rax,1)
lea    0xdda(%rip),%rdi
mov    %eax,%esi
mov    %edx,%r12d
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11db <main+0x4b>
mov    (%rsp),%edi
call   1030 <do_cpu_stress@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%rbx),%rdi
call   1060 <usage@plt>
xor    %edi,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@_SC_NPROCESSORS_CONF = global i32 0
@.str = [29 x i8] c"System has %i processor(s).\0A\00"
@.str.1 = [10 x i8] c"m:c:l?ahd\00"
@optarg = global i32 0
@.str.2 = [74 x i8] c"WARNING: Must utilize at least 1 cpu. Spinning all %i cpu(s) instead...\0A\00"
@.str.3 = [89 x i8] c"WARNING: %i cpu(s), are not available on this system, spinning all %i cpu(s) instead...\0A\00"
@.str.4 = [36 x i8] c"Maxing computation on %i cpu(s)...\0A\00"
@optopt = global i32 0
@stderr = global i32 0
@.str.5 = [23 x i8] c"Unknown option `-%c'.\0A\00"
@.str.6 = [34 x i8] c"Unknown option character `\\x%x'.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
%10 = load i32, i32* @_SC_NPROCESSORS_CONF
%11 = call i32 @sysconf(i32 %10)
store i32 %11, i32* %7
%12 = load i32, i32* %7
%13 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = load i32, i32* %7
store i32 %14, i32* %8
store i32 0, i32* %9
br label %15
15: ; preds = %63, %2
%16 = load i32, i32* %4
%17 = load i8**, i8*** %5
%18 = call i32 @getopt(i32 %16, i8** %17, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
store i32 %18, i32* %9
%19 = icmp ne i32 %18, -1
br i1 %19, label %20, label %64
20: ; preds = %15
%21 = load i32, i32* %9
switch i32 %21, label %57 [
i32 99, label %22
i32 63, label %44
]
22: ; preds = %20
%23 = load i32, i32* @optarg
%24 = call i32 @atoi(i32 %23)
store i32 %24, i32* %8
%25 = load i32, i32* %8
%26 = icmp slt i32 %25, 1
br i1 %26, label %27, label %30
27: ; preds = %22
%28 = load i32, i32* %7
%29 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([74 x i8], [74 x i8]* @.str.2, i64 0, i64 0), i32 %28)
store i32 1, i32* %8
br label %43
30: ; preds = %22
%31 = load i32, i32* %8
%32 = load i32, i32* %7
%33 = icmp sgt i32 %31, %32
br i1 %33, label %34, label %39
34: ; preds = %30
%35 = load i32, i32* %8
%36 = load i32, i32* %7
%37 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([89 x i8], [89 x i8]* @.str.3, i64 0, i64 0), i32 %35, i32 %36)
%38 = load i32, i32* %7
store i32 %38, i32* %8
br label %42
39: ; preds = %30
%40 = load i32, i32* %8
%41 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0), i32 %40)
br label %42
42: ; preds = %39, %34
br label %43
43: ; preds = %42, %27
br label %63
44: ; preds = %20
%45 = load i32, i32* @optopt
%46 = call i32 @isprint(i32 %45)
%47 = icmp ne i32 %46, 0
br i1 %47, label %48, label %52
48: ; preds = %44
%49 = load i32, i32* @stderr
%50 = load i32, i32* @optopt
%51 = call i32 @fprintf(i32 %49, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i32 %50)
br label %56
52: ; preds = %44
%53 = load i32, i32* @stderr
%54 = load i32, i32* @optopt
%55 = call i32 @fprintf(i32 %53, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.6, i64 0, i64 0), i32 %54)
br label %56
56: ; preds = %52, %48
br label %63
57: ; preds = %20
%58 = load i8**, i8*** %5
%59 = getelementptr inbounds i8*, i8** %58, i64 0
%60 = load i8*, i8** %59
%61 = call i32 @usage(i8* %60)
%62 = call i32 @exit(i32 0)
unreachable
63: ; preds = %56, %43
br label %15
64: ; preds = %15
%65 = load i32, i32* %8
%66 = call i32 @do_cpu_stress(i32 %65)
%67 = load i32, i32* %6
ret i32 %67
}

LLVM IR (-O2):
@_SC_NPROCESSORS_CONF = global i32 0
@.str = [29 x i8] c"System has %i processor(s).\0A\00"
@.str.1 = [10 x i8] c"m:c:l?ahd\00"
@optarg = global i32 0
@.str.2 = [74 x i8] c"WARNING: Must utilize at least 1 cpu. Spinning all %i cpu(s) instead...\0A\00"
@.str.3 = [89 x i8] c"WARNING: %i cpu(s), are not available on this system, spinning all %i cpu(s) instead...\0A\00"
@.str.4 = [36 x i8] c"Maxing computation on %i cpu(s)...\0A\00"
@optopt = global i32 0
@stderr = global i32 0
@.str.5 = [23 x i8] c"Unknown option `-%c'.\0A\00"
@.str.6 = [34 x i8] c"Unknown option character `\\x%x'.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = load i32, i32* @_SC_NPROCESSORS_CONF
%4 = tail call i32 @sysconf(i32 %3)
%5 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %4)
br label %6
6: ; preds = %16, %2
%7 = phi i32 [ %4, %2 ], [ %17, %16 ]
br label %8
8: ; preds = %31, %6
%9 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
switch i32 %9, label %34 [
i32 -1, label %38
i32 99, label %10
i32 63, label %24
]
10: ; preds = %8
%11 = load i32, i32* @optarg
%12 = tail call i32 @atoi(i32 %11)
%13 = icmp slt i32 %12, 1
br i1 %13, label %14, label %18
14: ; preds = %10
%15 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([74 x i8], [74 x i8]* @.str.2, i64 0, i64 0), i32 %4)
br label %16
16: ; preds = %14, %20, %22
%17 = phi i32 [ %12, %22 ], [ %4, %20 ], [ 1, %14 ]
br label %6
18: ; preds = %10
%19 = icmp sgt i32 %12, %4
br i1 %19, label %20, label %22
20: ; preds = %18
%21 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([89 x i8], [89 x i8]* @.str.3, i64 0, i64 0), i32 %12, i32 %4)
br label %16
22: ; preds = %18
%23 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0), i32 %12)
br label %16
24: ; preds = %8
%25 = load i32, i32* @optopt
%26 = tail call i32 @isprint(i32 %25)
%27 = icmp eq i32 %26, 0
%28 = load i32, i32* @stderr
br i1 %27, label %32, label %29
29: ; preds = %24
%30 = tail call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i32 %25)
br label %31
31: ; preds = %29, %32
br label %8
32: ; preds = %24
%33 = tail call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.6, i64 0, i64 0), i32 %25)
br label %31
34: ; preds = %8
%35 = load i8*, i8** %1
%36 = tail call i32 @usage(i8* %35)
%37 = tail call i32 @exit(i32 0)
unreachable
38: ; preds = %8
%39 = tail call i32 @do_cpu_stress(i32 %7)
ret i32 0
}