#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 */
long INT_MAX;
long strtol(char const *, char **, int /*<<< orphan*/);
int /*<<< orphan*/ usage();
int /*<<< orphan*/ warnx(char *, char);
int parse_positive_int_option(char optname, const char *optarg) {
  char *endptr;
  long val;
  val = strtol(optarg, &endptr, 0);
  if (*endptr != '\0' || val <= 0 || val >= INT_MAX) {
    warnx("invalid value for -%c", optname);
    usage();
  }
  return ((int)val);
}


x86 assembly (clang, -O0):
<parse_positive_int_option>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
xor    %edx,%edx
call   1040 <strtol@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1184 <parse_positive_int_option+0x54>
cmpq   $0x0,-0x20(%rbp)
jle    1184 <parse_positive_int_option+0x54>
mov    -0x20(%rbp),%rax
mov    0x2e6d(%rip),%rcx
cmp    (%rcx),%rax
jl     119b <parse_positive_int_option+0x6b>
lea    0xe75(%rip),%rdi
movsbl -0x1(%rbp),%esi
call   1030 <warnx@plt>
mov    $0x0,%al
call   1050 <usage@plt>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_positive_int_option>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rax
mov    %edi,%ebp
mov    %rsp,%rsi
mov    %rax,%rdi
xor    %edx,%edx
call   1040 <strtol@plt>
mov    %rax,%rbx
mov    (%rsp),%rax
cmpb   $0x0,(%rax)
jne    1162 <parse_positive_int_option+0x32>
test   %rbx,%rbx
jle    1162 <parse_positive_int_option+0x32>
mov    0x2e8b(%rip),%rax
cmp    (%rax),%rbx
jl     1179 <parse_positive_int_option+0x49>
movsbl %bpl,%esi
lea    0xe93(%rip),%rdi
call   1030 <warnx@plt>
xor    %eax,%eax
call   1050 <usage@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@INT_MAX = global i64 0
@.str = [22 x i8] c"invalid value for -%c\00"
define i32 @parse_positive_int_option(i8 signext %0, i8* %1) {
%3 = alloca i8
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
store i8 %0, i8* %3
store i8* %1, i8** %4
%7 = load i8*, i8** %4
%8 = call i64 @strtol(i8* %7, i8** %5, i32 0)
store i64 %8, i64* %6
%9 = load i8*, i8** %5
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = icmp ne i32 %11, 0
br i1 %12, label %20, label %13
13: ; preds = %2
%14 = load i64, i64* %6
%15 = icmp sle i64 %14, 0
br i1 %15, label %20, label %16
16: ; preds = %13
%17 = load i64, i64* %6
%18 = load i64, i64* @INT_MAX
%19 = icmp sge i64 %17, %18
br i1 %19, label %20, label %24
20: ; preds = %16, %13, %2
%21 = load i8, i8* %3
%22 = call i32 @warnx(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8 signext %21)
%23 = call i32 (...) @usage()
br label %24
24: ; preds = %20, %16
%25 = load i64, i64* %6
%26 = trunc i64 %25 to i32
ret i32 %26
}

LLVM IR (-O2):
@INT_MAX = global i64 0
@.str = [22 x i8] c"invalid value for -%c\00"
define i32 @parse_positive_int_option(i8 signext %0, i8* %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = call i64 @strtol(i8* %1, i8** %3, i32 0)
%6 = load i8*, i8** %3
%7 = load i8, i8* %6
%8 = icmp eq i8 %7, 0
%9 = icmp sgt i64 %5, 0
%10 = select i1 %8, i1 %9, i1 false
%11 = load i64, i64* @INT_MAX
%12 = icmp slt i64 %5, %11
%13 = select i1 %10, i1 %12, i1 false
br i1 %13, label %17, label %14
14: ; preds = %2
%15 = tail call i32 @warnx(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8 signext %0)
%16 = tail call i32 (...) @usage()
br label %17
17: ; preds = %2, %14
%18 = trunc i64 %5 to i32
ret i32 %18
}