#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 *, char *);
int /*<<< orphan*/ stderr;
int strtol(char *, char **, int);
int atoi_validate(char *a, char *var_name) {
  char *cnv;
  int val;
  val = strtol(a, &cnv, 10);
  if (cnv == a || *cnv != '\0' || val < 1) {
    fprintf(stderr, "Error: %s needs to be int>0!\n", var_name);
    val = -1;
  }
  return val;
}


x86 assembly (clang, -O0):
<atoi_validate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x18(%rbp),%rsi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x8(%rbp),%rax
je     116d <atoi_validate+0x4d>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    116d <atoi_validate+0x4d>
cmpl   $0x1,-0x1c(%rbp)
jge    118d <atoi_validate+0x6d>
mov    0x2e6c(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe7f(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0xffffffff,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<atoi_validate>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsp,%rsi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    (%rsp),%rcx
cmp    %rbx,%rcx
je     1149 <atoi_validate+0x29>
cmpb   $0x0,(%rcx)
jne    1149 <atoi_validate+0x29>
test   %eax,%eax
jg     1166 <atoi_validate+0x46>
mov    0x2e90(%rip),%rax
mov    (%rax),%edi
lea    0xea7(%rip),%rsi
mov    %r14,%rdx
call   1030 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [30 x i8] c"Error: %s needs to be int>0!\0A\00"
define i32 @atoi_validate(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%7 = load i8*, i8** %3
%8 = call i32 @strtol(i8* %7, i8** %5, i32 10)
store i32 %8, i32* %6
%9 = load i8*, i8** %5
%10 = load i8*, i8** %3
%11 = icmp eq i8* %9, %10
br i1 %11, label %20, label %12
12: ; preds = %2
%13 = load i8*, i8** %5
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp ne i32 %15, 0
br i1 %16, label %20, label %17
17: ; preds = %12
%18 = load i32, i32* %6
%19 = icmp slt i32 %18, 1
br i1 %19, label %20, label %24
20: ; preds = %17, %12, %2
%21 = load i32, i32* @stderr
%22 = load i8*, i8** %4
%23 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %22)
store i32 -1, i32* %6
br label %24
24: ; preds = %20, %17
%25 = load i32, i32* %6
ret i32 %25
}

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