#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 /*<<< orphan*/ stderr;
long strtol(char *, char **, int);
size_t cli_get_thread_count(int argc, char *argv[]) {
  char *error;
  long count;
  if (argc != 2)
    return 0;
  count = strtol(argv[1], &error, 10);
  if ((*error != '\0') || (count <= 0)) {
    fprintf(stderr, "Error: invalid thread number.\n");
    return 0;
  }
  return (size_t)count;
}


x86 assembly (clang, -O0):
<cli_get_thread_count>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
cmpl   $0x2,-0xc(%rbp)
je     1146 <cli_get_thread_count+0x26>
movq   $0x0,-0x8(%rbp)
jmp    11a5 <cli_get_thread_count+0x85>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x20(%rbp),%rsi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    117b <cli_get_thread_count+0x5b>
cmpq   $0x0,-0x28(%rbp)
jg     119d <cli_get_thread_count+0x7d>
mov    0x2e5e(%rip),%rax
mov    (%rax),%edi
lea    0xe75(%rip),%rsi
call   1030 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    11a5 <cli_get_thread_count+0x85>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cli_get_thread_count>:
push   %rax
cmp    $0x2,%edi
jne    115c <cli_get_thread_count+0x3c>
mov    0x8(%rsi),%rdi
mov    %rsp,%rsi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    (%rsp),%rcx
cmpb   $0x0,(%rcx)
jne    1147 <cli_get_thread_count+0x27>
test   %rax,%rax
jle    1147 <cli_get_thread_count+0x27>
pop    %rcx
ret
mov    0x2e92(%rip),%rax
mov    (%rax),%edi
lea    0xea9(%rip),%rsi
call   1030 <fprintf@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [31 x i8] c"Error: invalid thread number.\0A\00"
define i64 @cli_get_thread_count(i32 %0, i8** %1) {
%3 = alloca i64
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i64
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 2
br i1 %9, label %10, label %11
10: ; preds = %2
store i64 0, i64* %3
br label %28
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = call i64 @strtol(i8* %14, i8** %6, i32 10)
store i64 %15, i64* %7
%16 = load i8*, i8** %6
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp ne i32 %18, 0
br i1 %19, label %23, label %20
20: ; preds = %11
%21 = load i64, i64* %7
%22 = icmp sle i64 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %20, %11
%24 = load i32, i32* @stderr
%25 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
store i64 0, i64* %3
br label %28
26: ; preds = %20
%27 = load i64, i64* %7
store i64 %27, i64* %3
br label %28
28: ; preds = %26, %23, %10
%29 = load i64, i64* %3
ret i64 %29
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [31 x i8] c"Error: invalid thread number.\0A\00"
define i64 @cli_get_thread_count(i32 %0, i8** nocapture %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = icmp eq i32 %0, 2
br i1 %5, label %6, label %18
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = call i64 @strtol(i8* %8, i8** %3, i32 10)
%10 = load i8*, i8** %3
%11 = load i8, i8* %10
%12 = icmp ne i8 %11, 0
%13 = icmp slt i64 %9, 1
%14 = select i1 %12, i1 true, i1 %13
br i1 %14, label %15, label %18
15: ; preds = %6
%16 = load i32, i32* @stderr
%17 = tail call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
br label %18
18: ; preds = %6, %2, %15
%19 = phi i64 [ 0, %15 ], [ 0, %2 ], [ %9, %6 ]
ret i64 %19
}