#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 ERANGE;
int SHRT_MAX;
int /*<<< orphan*/ assert(int /*<<< orphan*/);
int errno;
int strtol(char *, int /*<<< orphan*/ *, int);
int cfg_parse_nid(char *tok, short *nid) {
  int n;
  assert(tok != NULL);
  assert(nid != NULL);
  errno = 0;
  n = strtol(tok, NULL, 10);
  if (n < 0 || errno == ERANGE) {
    do {
      errno =
          errno < 0 ? errno : (-1 * ((((8) * 10000 + (705))) * 1000 + (errno)));
    } while (0);
    return -1;
  }
  if (n > SHRT_MAX) {
    do {
      errno =
          errno < 0 ? errno : (-1 * ((((8) * 10000 + (710))) * 1000 + (errno)));
    } while (0);
    return -1;
  }
  *nid = n;
  return 0;
}


x86 assembly (clang, -O0):
<cfg_parse_nid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
cmpq   $0x0,-0x18(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    0x2e7d(%rip),%rax
movl   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jl     1198 <cfg_parse_nid+0x78>
mov    0x2e51(%rip),%rax
mov    (%rax),%eax
mov    0x2e58(%rip),%rcx
cmp    (%rcx),%eax
jne    11ed <cfg_parse_nid+0xcd>
jmp    119d <cfg_parse_nid+0x7d>
mov    0x2e34(%rip),%rax
cmpl   $0x0,(%rax)
jge    11be <cfg_parse_nid+0x9e>
mov    0x2e24(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
jmp    11d5 <cfg_parse_nid+0xb5>
mov    0x2e13(%rip),%rax
mov    (%rax),%eax
add    $0x4cf75e8,%eax
imul   $0xffffffff,%eax,%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%ecx
mov    0x2df9(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    1268 <cfg_parse_nid+0x148>
mov    -0x1c(%rbp),%eax
mov    0x2dd9(%rip),%rcx
cmp    (%rcx),%eax
jle    1254 <cfg_parse_nid+0x134>
jmp    1204 <cfg_parse_nid+0xe4>
mov    0x2dcd(%rip),%rax
cmpl   $0x0,(%rax)
jge    1225 <cfg_parse_nid+0x105>
mov    0x2dbd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
jmp    123c <cfg_parse_nid+0x11c>
mov    0x2dac(%rip),%rax
mov    (%rax),%eax
add    $0x4cf8970,%eax
imul   $0xffffffff,%eax,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%ecx
mov    0x2d92(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    1268 <cfg_parse_nid+0x148>
mov    -0x1c(%rbp),%eax
mov    %ax,%cx
mov    -0x18(%rbp),%rax
mov    %cx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cfg_parse_nid>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
xor    %edi,%edi
test   %rbx,%rbx
setne  %dil
call   1030 <assert@plt>
xor    %edi,%edi
test   %r14,%r14
setne  %dil
call   1030 <assert@plt>
mov    0x2e8a(%rip),%r15
movl   $0x0,(%r15)
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    (%r15),%ecx
test   %eax,%eax
js     1188 <cfg_parse_nid+0x68>
mov    0x2e76(%rip),%rdx
cmp    (%rdx),%ecx
je     1188 <cfg_parse_nid+0x68>
mov    0x2e53(%rip),%rdx
cmp    (%rdx),%eax
jle    119e <cfg_parse_nid+0x7e>
mov    $0xfb307690,%eax
jmp    118d <cfg_parse_nid+0x6d>
mov    $0xfb308a18,%eax
sub    %ecx,%eax
test   %ecx,%ecx
cmovs  %ecx,%eax
mov    %eax,(%r15)
mov    $0xffffffff,%eax
jmp    11a4 <cfg_parse_nid+0x84>
mov    %ax,(%r14)
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@errno = global i32 0
@ERANGE = global i32 0
@SHRT_MAX = global i32 0
define i32 @cfg_parse_nid(i8* %0, i16* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i16*
%6 = alloca i32
store i8* %0, i8** %4
store i16* %1, i16** %5
%7 = load i8*, i8** %4
%8 = icmp ne i8* %7, null
%9 = zext i1 %8 to i32
%10 = call i32 @assert(i32 %9)
%11 = load i16*, i16** %5
%12 = icmp ne i16* %11, null
%13 = zext i1 %12 to i32
%14 = call i32 @assert(i32 %13)
store i32 0, i32* @errno
%15 = load i8*, i8** %4
%16 = call i32 @strtol(i8* %15, i32* null, i32 10)
store i32 %16, i32* %6
%17 = load i32, i32* %6
%18 = icmp slt i32 %17, 0
br i1 %18, label %23, label %19
19: ; preds = %2
%20 = load i32, i32* @errno
%21 = load i32, i32* @ERANGE
%22 = icmp eq i32 %20, %21
br i1 %22, label %23, label %36
23: ; preds = %19, %2
br label %24
24: ; preds = %23
%25 = load i32, i32* @errno
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %24
%28 = load i32, i32* @errno
br label %33
29: ; preds = %24
%30 = load i32, i32* @errno
%31 = add nsw i32 80705000, %30
%32 = mul nsw i32 -1, %31
br label %33
33: ; preds = %29, %27
%34 = phi i32 [ %28, %27 ], [ %32, %29 ]
store i32 %34, i32* @errno
br label %35
35: ; preds = %33
store i32 -1, i32* %3
br label %57
36: ; preds = %19
%37 = load i32, i32* %6
%38 = load i32, i32* @SHRT_MAX
%39 = icmp sgt i32 %37, %38
br i1 %39, label %40, label %53
40: ; preds = %36
br label %41
41: ; preds = %40
%42 = load i32, i32* @errno
%43 = icmp slt i32 %42, 0
br i1 %43, label %44, label %46
44: ; preds = %41
%45 = load i32, i32* @errno
br label %50
46: ; preds = %41
%47 = load i32, i32* @errno
%48 = add nsw i32 80710000, %47
%49 = mul nsw i32 -1, %48
br label %50
50: ; preds = %46, %44
%51 = phi i32 [ %45, %44 ], [ %49, %46 ]
store i32 %51, i32* @errno
br label %52
52: ; preds = %50
store i32 -1, i32* %3
br label %57
53: ; preds = %36
%54 = load i32, i32* %6
%55 = trunc i32 %54 to i16
%56 = load i16*, i16** %5
store i16 %55, i16* %56
store i32 0, i32* %3
br label %57
57: ; preds = %53, %52, %35
%58 = load i32, i32* %3
ret i32 %58
}

LLVM IR (-O2):
@errno = global i32 0
@ERANGE = global i32 0
@SHRT_MAX = global i32 0
define i32 @cfg_parse_nid(i8* %0, i16* writeonly %1) {
%3 = icmp ne i8* %0, null
%4 = zext i1 %3 to i32
%5 = tail call i32 @assert(i32 %4)
%6 = icmp ne i16* %1, null
%7 = zext i1 %6 to i32
%8 = tail call i32 @assert(i32 %7)
store i32 0, i32* @errno
%9 = tail call i32 @strtol(i8* nocapture %0, i32* null, i32 10)
%10 = icmp slt i32 %9, 0
%11 = load i32, i32* @errno
%12 = load i32, i32* @ERANGE
%13 = icmp eq i32 %11, %12
%14 = select i1 %10, i1 true, i1 %13
br i1 %14, label %15, label %19
15: ; preds = %2
%16 = icmp slt i32 %11, 0
%17 = sub i32 -80705000, %11
%18 = select i1 %16, i32 %11, i32 %17
store i32 %18, i32* @errno
br label %28
19: ; preds = %2
%20 = load i32, i32* @SHRT_MAX
%21 = icmp sgt i32 %9, %20
br i1 %21, label %22, label %26
22: ; preds = %19
%23 = icmp slt i32 %11, 0
%24 = sub i32 -80710000, %11
%25 = select i1 %23, i32 %11, i32 %24
store i32 %25, i32* @errno
br label %28
26: ; preds = %19
%27 = trunc i32 %9 to i16
store i16 %27, i16* %1
br label %28
28: ; preds = %26, %22, %15
%29 = phi i32 [ -1, %15 ], [ -1, %22 ], [ 0, %26 ]
ret i32 %29
}