#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*/ Usage(char *);
int dlg_count_argv(char **);
int /*<<< orphan*/ sprintf(char *, char *, int, char *);
scalar_t__ strtol(char *, char **, int);
int numeric_arg(char **av, int n) {
  int result = 0;
  if (n < dlg_count_argv(av)) {
    char msg[80];
    char *last = 0;
    result = (int)strtol(av[n], &last, 10);
    if (last == 0 || *last != 0) {
      sprintf(msg, "Expected a number for token %d of %.20s", n, av[0]);
      Usage(msg);
    }
  }
  return result;
}


x86 assembly (clang, -O0):
<numeric_arg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x6c(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <dlg_count_argv@plt>
mov    %eax,%ecx
mov    -0x6c(%rbp),%eax
cmp    %ecx,%eax
jge    11da <numeric_arg+0x9a>
movq   $0x0,-0x68(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    -0x68(%rbp),%rsi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    %eax,-0x10(%rbp)
cmpq   $0x0,-0x68(%rbp)
je     11b2 <numeric_arg+0x72>
mov    -0x68(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11d5 <numeric_arg+0x95>
lea    -0x60(%rbp),%rdi
mov    -0xc(%rbp),%edx
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
lea    0xe39(%rip),%rsi
call   1060 <sprintf@plt>
lea    -0x60(%rbp),%rdi
call   1040 <Usage@plt>
jmp    11da <numeric_arg+0x9a>
mov    -0x10(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<numeric_arg>:
push   %rbp
push   %r14
push   %rbx
sub    $0x60,%rsp
mov    %esi,%ebp
mov    %rdi,%rbx
call   1030 <dlg_count_argv@plt>
xor    %r14d,%r14d
cmp    %ebp,%eax
jle    11ab <numeric_arg+0x6b>
movq   $0x0,0x8(%rsp)
movslq %ebp,%rax
mov    (%rbx,%rax,8),%rdi
lea    0x8(%rsp),%rsi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    %rax,%r14
mov    0x8(%rsp),%rax
test   %rax,%rax
je     118a <numeric_arg+0x4a>
cmpb   $0x0,(%rax)
je     11ab <numeric_arg+0x6b>
mov    (%rbx),%rcx
lea    0xe6c(%rip),%rsi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    %ebp,%edx
call   1060 <sprintf@plt>
mov    %rbx,%rdi
call   1040 <Usage@plt>
mov    %r14d,%eax
add    $0x60,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [40 x i8] c"Expected a number for token %d of %.20s\00"
define i32 @numeric_arg(i8** %0, i32 %1) {
%3 = alloca i8**
%4 = alloca i32
%5 = alloca i32
%6 = alloca [80 x i8]
%7 = alloca i8*
store i8** %0, i8*** %3
store i32 %1, i32* %4
store i32 0, i32* %5
%8 = load i32, i32* %4
%9 = load i8**, i8*** %3
%10 = call i32 @dlg_count_argv(i8** %9)
%11 = icmp slt i32 %8, %10
br i1 %11, label %12, label %37
12: ; preds = %2
store i8* null, i8** %7
%13 = load i8**, i8*** %3
%14 = load i32, i32* %4
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8*, i8** %13, i64 %15
%17 = load i8*, i8** %16
%18 = call i64 @strtol(i8* %17, i8** %7, i32 10)
%19 = trunc i64 %18 to i32
store i32 %19, i32* %5
%20 = load i8*, i8** %7
%21 = icmp eq i8* %20, null
br i1 %21, label %27, label %22
22: ; preds = %12
%23 = load i8*, i8** %7
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %36
27: ; preds = %22, %12
%28 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%29 = load i32, i32* %4
%30 = load i8**, i8*** %3
%31 = getelementptr inbounds i8*, i8** %30, i64 0
%32 = load i8*, i8** %31
%33 = call i32 @sprintf(i8* %28, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i32 %29, i8* %32)
%34 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%35 = call i32 @Usage(i8* %34)
br label %36
36: ; preds = %27, %22
br label %37
37: ; preds = %36, %2
%38 = load i32, i32* %5
ret i32 %38
}

LLVM IR (-O2):
@.str = [40 x i8] c"Expected a number for token %d of %.20s\00"
define i32 @numeric_arg(i8** %0, i32 %1) {
%3 = alloca [80 x i8]
%4 = alloca i8*
%5 = tail call i32 @dlg_count_argv(i8** %0)
%6 = icmp sgt i32 %5, %1
br i1 %6, label %7, label %25
7: ; preds = %2
%8 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%9 = bitcast i8** %4 to i8*
store i8* null, i8** %4
%10 = sext i32 %1 to i64
%11 = getelementptr inbounds i8*, i8** %0, i64 %10
%12 = load i8*, i8** %11
%13 = call i64 @strtol(i8* %12, i8** %4, i32 10)
%14 = trunc i64 %13 to i32
%15 = load i8*, i8** %4
%16 = icmp eq i8* %15, null
br i1 %16, label %20, label %17
17: ; preds = %7
%18 = load i8, i8* %15
%19 = icmp eq i8 %18, 0
br i1 %19, label %24, label %20
20: ; preds = %17, %7
%21 = load i8*, i8** %0
%22 = call i32 @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i32 %1, i8* %21)
%23 = call i32 @Usage(i8* %8)
br label %24
24: ; preds = %20, %17
br label %25
25: ; preds = %24, %2
%26 = phi i32 [ %14, %24 ], [ 0, %2 ]
ret i32 %26
}