#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 */
scalar_t__ ERANGE;
long INT_MAX;
long INT_MIN;
scalar_t__ errno;
long strtol(char const *, char **, int);
int /*<<< orphan*/ warnx(char *, char const *, char const *);
int getnum(const char *com, const char *str, int *val) {
  long v;
  char *ep;
  errno = 0;
  v = strtol(str, &ep, 10);
  if (v < INT_MIN || v > INT_MAX || errno == ERANGE) {
    warnx("%s argument %s is out of range.", com, str);
    return (1);
  }
  if (ep == str || *ep != '\0' || errno != 0) {
    warnx("Bad %s argument: %s.", com, str);
    return (1);
  }
  *val = (int)v;
  return (0);
}


x86 assembly (clang, -O0):
<getnum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    0x2e8d(%rip),%rax
movq   $0x0,(%rax)
mov    -0x18(%rbp),%rdi
lea    -0x30(%rbp),%rsi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    0x2e7d(%rip),%rcx
cmp    (%rcx),%rax
jl     119a <getnum+0x7a>
mov    -0x28(%rbp),%rax
mov    0x2e71(%rip),%rcx
cmp    (%rcx),%rax
jg     119a <getnum+0x7a>
mov    0x2e41(%rip),%rax
mov    (%rax),%rax
mov    0x2e47(%rip),%rcx
cmp    (%rcx),%rax
jne    11ba <getnum+0x9a>
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xe57(%rip),%rdi
call   1030 <warnx@plt>
movl   $0x1,-0x4(%rbp)
jmp    121c <getnum+0xfc>
mov    -0x30(%rbp),%rax
cmp    -0x18(%rbp),%rax
je     11e9 <getnum+0xc9>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11e9 <getnum+0xc9>
mov    0x2de9(%rip),%rax
cmpq   $0x0,(%rax)
je     1209 <getnum+0xe9>
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xe28(%rip),%rdi
call   1030 <warnx@plt>
movl   $0x1,-0x4(%rbp)
jmp    121c <getnum+0xfc>
mov    -0x28(%rbp),%rax
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getnum>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%r14
mov    0x2e90(%rip),%r12
movq   $0x0,(%r12)
mov    %rsp,%rsi
mov    %rbx,%rdi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    0x2e89(%rip),%rcx
cmp    (%rcx),%rax
jl     1178 <getnum+0x58>
mov    0x2e85(%rip),%rcx
cmp    (%rcx),%rax
jg     1178 <getnum+0x58>
mov    (%r12),%rcx
mov    0x2e65(%rip),%rdx
cmp    (%rdx),%rcx
jne    119b <getnum+0x7b>
lea    0xe81(%rip),%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1030 <warnx@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    (%rsp),%rdx
cmp    %rbx,%rdx
je     11b5 <getnum+0x95>
cmpb   $0x0,(%rdx)
jne    11b5 <getnum+0x95>
test   %rcx,%rcx
jne    11b5 <getnum+0x95>
mov    %eax,(%r15)
xor    %eax,%eax
jmp    118f <getnum+0x6f>
lea    0xe64(%rip),%rdi
jmp    117f <getnum+0x5f>

LLVM IR (-O0):
@errno = global i64 0
@INT_MIN = global i64 0
@INT_MAX = global i64 0
@ERANGE = global i64 0
@.str = [32 x i8] c"%s argument %s is out of range.\00"
@.str.1 = [21 x i8] c"Bad %s argument: %s.\00"
define i32 @getnum(i8* %0, i8* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i64
%9 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32* %2, i32** %7
store i64 0, i64* @errno
%10 = load i8*, i8** %6
%11 = call i64 @strtol(i8* %10, i8** %9, i32 10)
store i64 %11, i64* %8
%12 = load i64, i64* %8
%13 = load i64, i64* @INT_MIN
%14 = icmp slt i64 %12, %13
br i1 %14, label %23, label %15
15: ; preds = %3
%16 = load i64, i64* %8
%17 = load i64, i64* @INT_MAX
%18 = icmp sgt i64 %16, %17
br i1 %18, label %23, label %19
19: ; preds = %15
%20 = load i64, i64* @errno
%21 = load i64, i64* @ERANGE
%22 = icmp eq i64 %20, %21
br i1 %22, label %23, label %27
23: ; preds = %19, %15, %3
%24 = load i8*, i8** %5
%25 = load i8*, i8** %6
%26 = call i32 @warnx(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %24, i8* %25)
store i32 1, i32* %4
br label %47
27: ; preds = %19
%28 = load i8*, i8** %9
%29 = load i8*, i8** %6
%30 = icmp eq i8* %28, %29
br i1 %30, label %39, label %31
31: ; preds = %27
%32 = load i8*, i8** %9
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = icmp ne i32 %34, 0
br i1 %35, label %39, label %36
36: ; preds = %31
%37 = load i64, i64* @errno
%38 = icmp ne i64 %37, 0
br i1 %38, label %39, label %43
39: ; preds = %36, %31, %27
%40 = load i8*, i8** %5
%41 = load i8*, i8** %6
%42 = call i32 @warnx(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %40, i8* %41)
store i32 1, i32* %4
br label %47
43: ; preds = %36
%44 = load i64, i64* %8
%45 = trunc i64 %44 to i32
%46 = load i32*, i32** %7
store i32 %45, i32* %46
store i32 0, i32* %4
br label %47
47: ; preds = %43, %39, %23
%48 = load i32, i32* %4
ret i32 %48
}

LLVM IR (-O2):
@errno = global i64 0
@INT_MIN = global i64 0
@INT_MAX = global i64 0
@ERANGE = global i64 0
@.str = [32 x i8] c"%s argument %s is out of range.\00"
@.str.1 = [21 x i8] c"Bad %s argument: %s.\00"
define i32 @getnum(i8* %0, i8* %1, i32* nocapture writeonly %2) {
%4 = alloca i8*
%5 = bitcast i8** %4 to i8*
store i64 0, i64* @errno
%6 = call i64 @strtol(i8* %1, i8** %4, i32 10)
%7 = load i64, i64* @INT_MIN
%8 = icmp slt i64 %6, %7
%9 = load i64, i64* @INT_MAX
%10 = icmp sgt i64 %6, %9
%11 = select i1 %8, i1 true, i1 %10
br i1 %11, label %16, label %12
12: ; preds = %3
%13 = load i64, i64* @errno
%14 = load i64, i64* @ERANGE
%15 = icmp eq i64 %13, %14
br i1 %15, label %16, label %18
16: ; preds = %12, %3
%17 = tail call i32 @warnx(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1)
br label %30
18: ; preds = %12
%19 = load i8*, i8** %4
%20 = icmp eq i8* %19, %1
br i1 %20, label %26, label %21
21: ; preds = %18
%22 = load i8, i8* %19
%23 = icmp ne i8 %22, 0
%24 = icmp ne i64 %13, 0
%25 = select i1 %23, i1 true, i1 %24
br i1 %25, label %26, label %28
26: ; preds = %21, %18
%27 = tail call i32 @warnx(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %1)
br label %30
28: ; preds = %21
%29 = trunc i64 %6 to i32
store i32 %29, i32* %2
br label %30
30: ; preds = %28, %26, %16
%31 = phi i32 [ 1, %16 ], [ 1, %26 ], [ 0, %28 ]
ret i32 %31
}