#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 *);
char *getenv(char *);
int /*<<< orphan*/ userWarning(char *);
int threadCount(void) {
  char *thChar;
  int thNum[3], choice = 2;
  thNum[0] = 0;
  thNum[1] = 0;
  thNum[2] = 1;
  if ((thChar = getenv("OMP_NUM_THREADS")) != NULL) {
    thNum[0] = atoi(thChar);
    choice = 0;
  }
  if ((thChar = getenv("MKL_NUM_THREADS")) != NULL) {
    thNum[1] = atoi(thChar);
    choice = 1;
  }
  if (thNum[0] != 0 && thNum[1] != 0 && thNum[0] != thNum[1])
    userWarning("OMP and MKL NUM_THREADS differ");
  if (choice == 2)
    userWarning("The number of threads has not been set for this test");
  return thNum[choice];
}


x86 assembly (clang, -O0):
<threadCount>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x2,-0x18(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x1,-0xc(%rbp)
lea    0xea5(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x8(%rbp)
cmp    $0x0,%rax
je     1181 <threadCount+0x51>
mov    -0x8(%rbp),%rdi
call   1040 <atoi@plt>
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
lea    0xe88(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x8(%rbp)
cmp    $0x0,%rax
je     11ae <threadCount+0x7e>
mov    -0x8(%rbp),%rdi
call   1040 <atoi@plt>
mov    %eax,-0x10(%rbp)
movl   $0x1,-0x18(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11da <threadCount+0xaa>
cmpl   $0x0,-0x10(%rbp)
je     11da <threadCount+0xaa>
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
je     11da <threadCount+0xaa>
lea    0xe4b(%rip),%rdi
call   1050 <userWarning@plt>
cmpl   $0x2,-0x18(%rbp)
jne    11f0 <threadCount+0xc0>
lea    0xe54(%rip),%rdi
call   1050 <userWarning@plt>
movslq -0x18(%rbp),%rax
mov    -0x14(%rbp,%rax,4),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<threadCount>:
push   %r14
push   %rbx
sub    $0x18,%rsp
movq   $0x0,0xc(%rsp)
movl   $0x1,0x14(%rsp)
lea    0xeb1(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     117d <threadCount+0x4d>
mov    %rax,%rdi
call   1040 <atoi@plt>
mov    %eax,%ebx
mov    %eax,0xc(%rsp)
lea    0xea2(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
jne    1190 <threadCount+0x60>
xor    %r14d,%r14d
jmp    11c9 <threadCount+0x99>
lea    0xe8c(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     11b7 <threadCount+0x87>
xor    %ebx,%ebx
mov    %rax,%rdi
call   1040 <atoi@plt>
mov    %eax,0x10(%rsp)
mov    $0x1,%r14d
test   %ebx,%ebx
je     11c9 <threadCount+0x99>
test   %eax,%eax
je     11c9 <threadCount+0x99>
cmp    %eax,%ebx
je     11c9 <threadCount+0x99>
lea    0xe6b(%rip),%rdi
jmp    11c4 <threadCount+0x94>
mov    $0x2,%r14d
lea    0xe7b(%rip),%rdi
call   1050 <userWarning@plt>
mov    0xc(%rsp,%r14,4),%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [16 x i8] c"OMP_NUM_THREADS\00"
@.str.1 = [16 x i8] c"MKL_NUM_THREADS\00"
@.str.2 = [31 x i8] c"OMP and MKL NUM_THREADS differ\00"
@.str.3 = [53 x i8] c"The number of threads has not been set for this test\00"
define i32 @threadCount() {
%1 = alloca i8*
%2 = alloca [3 x i32]
%3 = alloca i32
store i32 2, i32* %3
%4 = getelementptr inbounds [3 x i32], [3 x i32]* %2, i64 0, i64 0
store i32 0, i32* %4
%5 = getelementptr inbounds [3 x i32], [3 x i32]* %2, i64 0, i64 1
store i32 0, i32* %5
%6 = getelementptr inbounds [3 x i32], [3 x i32]* %2, i64 0, i64 2
store i32 1, i32* %6
%7 = call i8* @getenv(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
store i8* %7, i8** %1
%8 = icmp ne i8* %7, null
br i1 %8, label %9, label %13
9: ; preds = %0
%10 = load i8*, i8** %1
%11 = call i32 @atoi(i8* %10)
%12 = getelementptr inbounds [3 x i32], [3 x i32]* %2, i64 0, i64 0
store i32 %11, i32* %12
store i32 0, i32* %3
br label %13
13: ; preds = %9, %0
%14 = call i8* @getenv(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
store i8* %14, i8** %1
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %20
16: ; preds = %13
%17 = load i8*, i8** %1
%18 = call i32 @atoi(i8* %17)
%19 = getelementptr inbounds [3 x i32], [3 x i32]* %2, i64 0, i64 1
store i32 %18, i32* %19
store i32 1, i32* %3
br label %20
20: ; preds = %16, %13
%21 = getelementptr inbounds [3 x i32], [3 x i32]* %2, i64 0, i64 0
%22 = load i32, i32* %21
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %36
24: ; preds = %20
%25 = getelementptr inbounds [3 x i32], [3 x i32]* %2, i64 0, i64 1
%26 = load i32, i32* %25
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %36
28: ; preds = %24
%29 = getelementptr inbounds [3 x i32], [3 x i32]* %2, i64 0, i64 0
%30 = load i32, i32* %29
%31 = getelementptr inbounds [3 x i32], [3 x i32]* %2, i64 0, i64 1
%32 = load i32, i32* %31
%33 = icmp ne i32 %30, %32
br i1 %33, label %34, label %36
34: ; preds = %28
%35 = call i32 @userWarning(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
br label %36
36: ; preds = %34, %28, %24, %20
%37 = load i32, i32* %3
%38 = icmp eq i32 %37, 2
br i1 %38, label %39, label %41
39: ; preds = %36
%40 = call i32 @userWarning(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.3, i64 0, i64 0))
br label %41
41: ; preds = %39, %36
%42 = load i32, i32* %3
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [3 x i32], [3 x i32]* %2, i64 0, i64 %43
%45 = load i32, i32* %44
ret i32 %45
}

LLVM IR (-O2):
@.str = [16 x i8] c"OMP_NUM_THREADS\00"
@.str.1 = [16 x i8] c"MKL_NUM_THREADS\00"
@.str.2 = [31 x i8] c"OMP and MKL NUM_THREADS differ\00"
@.str.3 = [53 x i8] c"The number of threads has not been set for this test\00"
define i32 @threadCount() {
%1 = alloca [3 x i32]
%2 = bitcast [3 x i32]* %1 to i8*
%3 = getelementptr inbounds [3 x i32], [3 x i32]* %1, i64 0, i64 0
store i32 0, i32* %3
%4 = getelementptr inbounds [3 x i32], [3 x i32]* %1, i64 0, i64 1
store i32 0, i32* %4
%5 = getelementptr inbounds [3 x i32], [3 x i32]* %1, i64 0, i64 2
store i32 1, i32* %5
%6 = tail call i8* @getenv(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %11
8: ; preds = %0
%9 = tail call i8* @getenv(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i8* %9, null
br i1 %10, label %24, label %15
11: ; preds = %0
%12 = tail call i32 @atoi(i8* %6)
store i32 %12, i32* %3
%13 = tail call i8* @getenv(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i8* %13, null
br i1 %14, label %28, label %15
15: ; preds = %11, %8
%16 = phi i8* [ %13, %11 ], [ %9, %8 ]
%17 = phi i32 [ %12, %11 ], [ 0, %8 ]
%18 = tail call i32 @atoi(i8* %16)
store i32 %18, i32* %4
%19 = icmp eq i32 %17, 0
%20 = icmp eq i32 %18, 0
%21 = select i1 %19, i1 true, i1 %20
%22 = icmp eq i32 %17, %18
%23 = select i1 %21, i1 true, i1 %22
br i1 %23, label %28, label %24
24: ; preds = %8, %15
%25 = phi i8* [ getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), %15 ], [ getelementptr inbounds ([53 x i8], [53 x i8]* @.str.3, i64 0, i64 0), %8 ]
%26 = phi i64 [ 1, %15 ], [ 2, %8 ]
%27 = tail call i32 @userWarning(i8* %25)
br label %28
28: ; preds = %24, %15, %11
%29 = phi i64 [ 0, %11 ], [ 1, %15 ], [ %26, %24 ]
%30 = and i64 %29, 4294967295
%31 = getelementptr inbounds [3 x i32], [3 x i32]* %1, i64 0, i64 %30
%32 = load i32, i32* %31
ret i32 %32
}