#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 atoi(char *);
int omp_get_dynamic();
int omp_get_max_threads();
int omp_get_num_procs();
int /*<<< orphan*/ omp_set_dynamic(int /*<<< orphan*/);
int /*<<< orphan*/ omp_set_num_threads(int);
int /*<<< orphan*/ printf(char *, int, ...);
int setnumthreads(int argc, char **argv) {
  int maxthreads = omp_get_max_threads();
  int procs = omp_get_num_procs();
  printf("Maximum threads: %i, Cores: %i\n", maxthreads, procs);
  int dynthreads = omp_get_dynamic();
  if (dynthreads != 0) {
    printf("Dynamic threads is %i, switching off\n", dynthreads);
    omp_set_dynamic(0);
  }
  printf("Dynamic threads is %i\n", omp_get_dynamic());
  int setthreads = maxthreads;
  if (argc == 2) {
    char *threads = argv[1];
    setthreads = atoi(threads);
    if (setthreads > maxthreads)
      setthreads = maxthreads;
  }
  omp_set_num_threads(setthreads);
  return setthreads;
}


x86 assembly (clang, -O0):
<setnumthreads>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1070 <omp_get_max_threads@plt>
mov    %eax,-0x14(%rbp)
mov    $0x0,%al
call   1050 <omp_get_num_procs@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
lea    0xe60(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1090 <omp_get_dynamic@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     11d3 <setnumthreads+0x63>
mov    -0x1c(%rbp),%esi
lea    0xe5b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %edi,%edi
call   1040 <omp_set_dynamic@plt>
mov    $0x0,%al
call   1090 <omp_get_dynamic@plt>
mov    %eax,%esi
lea    0xe63(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x20(%rbp)
cmpl   $0x2,-0x4(%rbp)
jne    1229 <setnumthreads+0xb9>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x14(%rbp),%eax
jle    1224 <setnumthreads+0xb4>
mov    -0x14(%rbp),%eax
mov    %eax,-0x20(%rbp)
jmp    1229 <setnumthreads+0xb9>
mov    -0x20(%rbp),%edi
call   1060 <omp_set_num_threads@plt>
mov    -0x20(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setnumthreads>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %edi,%ebp
xor    %eax,%eax
call   1070 <omp_get_max_threads@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1050 <omp_get_num_procs@plt>
lea    0xe70(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
call   1090 <omp_get_dynamic@plt>
test   %eax,%eax
je     11bd <setnumthreads+0x4d>
lea    0xe73(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %edi,%edi
call   1040 <omp_set_dynamic@plt>
xor    %eax,%eax
call   1090 <omp_get_dynamic@plt>
lea    0xe7b(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1030 <printf@plt>
cmp    $0x2,%ebp
jne    11e7 <setnumthreads+0x77>
mov    0x8(%r14),%rdi
call   1080 <atoi@plt>
cmp    %ebx,%eax
cmovle %eax,%ebx
mov    %ebx,%edi
call   1060 <omp_set_num_threads@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [32 x i8] c"Maximum threads: %i, Cores: %i\0A\00"
@.str.1 = [38 x i8] c"Dynamic threads is %i, switching off\0A\00"
@.str.2 = [23 x i8] c"Dynamic threads is %i\0A\00"
define i32 @setnumthreads(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
store i32 %0, i32* %3
store i8** %1, i8*** %4
%10 = call i32 (...) @omp_get_max_threads()
store i32 %10, i32* %5
%11 = call i32 (...) @omp_get_num_procs()
store i32 %11, i32* %6
%12 = load i32, i32* %5
%13 = load i32, i32* %6
%14 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 %12, i32 %13)
%15 = call i32 (...) @omp_get_dynamic()
store i32 %15, i32* %7
%16 = load i32, i32* %7
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %22
18: ; preds = %2
%19 = load i32, i32* %7
%20 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i32 %19)
%21 = call i32 @omp_set_dynamic(i32 0)
br label %22
22: ; preds = %18, %2
%23 = call i32 (...) @omp_get_dynamic()
%24 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 %23)
%25 = load i32, i32* %5
store i32 %25, i32* %8
%26 = load i32, i32* %3
%27 = icmp eq i32 %26, 2
br i1 %27, label %28, label %40
28: ; preds = %22
%29 = load i8**, i8*** %4
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = load i8*, i8** %30
store i8* %31, i8** %9
%32 = load i8*, i8** %9
%33 = call i32 @atoi(i8* %32)
store i32 %33, i32* %8
%34 = load i32, i32* %8
%35 = load i32, i32* %5
%36 = icmp sgt i32 %34, %35
br i1 %36, label %37, label %39
37: ; preds = %28
%38 = load i32, i32* %5
store i32 %38, i32* %8
br label %39
39: ; preds = %37, %28
br label %40
40: ; preds = %39, %22
%41 = load i32, i32* %8
%42 = call i32 @omp_set_num_threads(i32 %41)
%43 = load i32, i32* %8
ret i32 %43
}

LLVM IR (-O2):
@.str = [32 x i8] c"Maximum threads: %i, Cores: %i\0A\00"
@.str.1 = [38 x i8] c"Dynamic threads is %i, switching off\0A\00"
@.str.2 = [23 x i8] c"Dynamic threads is %i\0A\00"
define i32 @setnumthreads(i32 %0, i8** nocapture %1) {
%3 = tail call i32 (...) @omp_get_max_threads()
%4 = tail call i32 (...) @omp_get_num_procs()
%5 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 %3, i32 %4)
%6 = tail call i32 (...) @omp_get_dynamic()
%7 = icmp eq i32 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %2
%9 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i32 %6)
%10 = tail call i32 @omp_set_dynamic(i32 0)
br label %11
11: ; preds = %8, %2
%12 = tail call i32 (...) @omp_get_dynamic()
%13 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 %12)
%14 = icmp eq i32 %0, 2
br i1 %14, label %15, label %21
15: ; preds = %11
%16 = getelementptr inbounds i8*, i8** %1, i64 1
%17 = load i8*, i8** %16
%18 = tail call i32 @atoi(i8* %17)
%19 = icmp sgt i32 %18, %3
%20 = select i1 %19, i32 %3, i32 %18
br label %21
21: ; preds = %15, %11
%22 = phi i32 [ %20, %15 ], [ %3, %11 ]
%23 = tail call i32 @omp_set_num_threads(i32 %22)
ret i32 %22
}