#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_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ getenv(char *);
int /*<<< orphan*/ stderr;
long strtol(int /*<<< orphan*/, int /*<<< orphan*/ *, int);
long env_threads() {
  if (!getenv("OMP_NUM_THREADS")) {
    fprintf(stderr, "Specify OMP_NUM_THREADS\n");
    exit(EXIT_FAILURE);
  }
  long nthreads = strtol(getenv("OMP_NUM_THREADS"), NULL, 10);
  if (nthreads <= 0) {
    fprintf(stderr, "Invalid OMP_NUM_THREADS: %ld\n", nthreads);
    exit(EXIT_FAILURE);
  }
  return nthreads;
}


x86 assembly (clang, -O0):
<env_threads>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xeb1(%rip),%rdi
call   1030 <getenv@plt>
cmp    $0x0,%eax
jne    1182 <env_threads+0x42>
mov    0x2e7c(%rip),%rax
mov    (%rax),%edi
lea    0xea3(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2e5d(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
lea    0xe77(%rip),%rdi
call   1030 <getenv@plt>
mov    %eax,%edi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jg     11d6 <env_threads+0x96>
mov    0x2e2c(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe68(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2e09(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<env_threads>:
push   %rax
lea    0xeb8(%rip),%rdi
call   1030 <getenv@plt>
test   %eax,%eax
je     1166 <env_threads+0x26>
mov    %eax,%edi
xor    %esi,%esi
mov    $0xa,%edx
call   1050 <strtol@plt>
test   %rax,%rax
jle    117f <env_threads+0x3f>
pop    %rcx
ret
mov    0x2e73(%rip),%rax
mov    (%rax),%edi
lea    0xe9a(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    1199 <env_threads+0x59>
mov    0x2e5a(%rip),%rcx
mov    (%rcx),%edi
lea    0xe9a(%rip),%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    0x2e38(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [16 x i8] c"OMP_NUM_THREADS\00"
@stderr = global i32 0
@.str.1 = [25 x i8] c"Specify OMP_NUM_THREADS\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [30 x i8] c"Invalid OMP_NUM_THREADS: %ld\0A\00"
define i64 @env_threads() {
%1 = alloca i64
%2 = call i32 @getenv(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%3 = icmp ne i32 %2, 0
br i1 %3, label %9, label %4
4: ; preds = %0
%5 = load i32, i32* @stderr
%6 = call i32 (i32, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%7 = load i32, i32* @EXIT_FAILURE
%8 = call i32 @exit(i32 %7)
unreachable
9: ; preds = %0
%10 = call i32 @getenv(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%11 = call i64 @strtol(i32 %10, i32* null, i32 10)
store i64 %11, i64* %1
%12 = load i64, i64* %1
%13 = icmp sle i64 %12, 0
br i1 %13, label %14, label %20
14: ; preds = %9
%15 = load i32, i32* @stderr
%16 = load i64, i64* %1
%17 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i64 %16)
%18 = load i32, i32* @EXIT_FAILURE
%19 = call i32 @exit(i32 %18)
unreachable
20: ; preds = %9
%21 = load i64, i64* %1
ret i64 %21
}

LLVM IR (-O2):
@.str = [16 x i8] c"OMP_NUM_THREADS\00"
@stderr = global i32 0
@.str.1 = [25 x i8] c"Specify OMP_NUM_THREADS\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [30 x i8] c"Invalid OMP_NUM_THREADS: %ld\0A\00"
define i64 @env_threads() {
%1 = tail call i32 @getenv(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%2 = icmp eq i32 %1, 0
br i1 %2, label %3, label %8
3: ; preds = %0
%4 = load i32, i32* @stderr
%5 = tail call i32 (i32, i8*, ...) @fprintf(i32 %4, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%6 = load i32, i32* @EXIT_FAILURE
%7 = tail call i32 @exit(i32 %6)
unreachable
8: ; preds = %0
%9 = tail call i64 @strtol(i32 %1, i32* null, i32 10)
%10 = icmp slt i64 %9, 1
br i1 %10, label %11, label %16
11: ; preds = %8
%12 = load i32, i32* @stderr
%13 = tail call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i64 %9)
%14 = load i32, i32* @EXIT_FAILURE
%15 = tail call i32 @exit(i32 %14)
unreachable
16: ; preds = %8
ret i64 %9
}