#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 */
char *nextTok(char **);
long strtol(char *, char **, int);
long strtoul(char *, char **, int);
int at_tok_nextint_base(char **p_cur, int *p_out, int base, int uns) {
  char *ret;
  if (*p_cur == NULL)
    return -1;
  if (p_out == NULL)
    return -1;
  ret = nextTok(p_cur);
  if (ret == NULL)
    return -1;
  else {
    long l;
    char *end;
    if (uns)
      l = strtoul(ret, &end, base);
    else
      l = strtol(ret, &end, base);
    *p_out = (int)l;
    if (end == ret)
      return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<at_tok_nextint_base>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1160 <at_tok_nextint_base+0x30>
movl   $0xffffffff,-0x4(%rbp)
jmp    1204 <at_tok_nextint_base+0xd4>
cmpq   $0x0,-0x18(%rbp)
jne    1177 <at_tok_nextint_base+0x47>
movl   $0xffffffff,-0x4(%rbp)
jmp    1204 <at_tok_nextint_base+0xd4>
mov    -0x10(%rbp),%rdi
call   1030 <nextTok@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    119b <at_tok_nextint_base+0x6b>
movl   $0xffffffff,-0x4(%rbp)
jmp    1204 <at_tok_nextint_base+0xd4>
cmpl   $0x0,-0x20(%rbp)
je     11be <at_tok_nextint_base+0x8e>
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%edx
lea    -0x38(%rbp),%rsi
call   1050 <strtoul@plt>
mov    %rax,-0x30(%rbp)
jmp    11d2 <at_tok_nextint_base+0xa2>
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%edx
lea    -0x38(%rbp),%rsi
call   1040 <strtol@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x38(%rbp),%rax
cmp    -0x28(%rbp),%rax
jne    11f8 <at_tok_nextint_base+0xc8>
movl   $0xffffffff,-0x4(%rbp)
jmp    1204 <at_tok_nextint_base+0xd4>
jmp    11fd <at_tok_nextint_base+0xcd>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<at_tok_nextint_base>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    $0xffffffff,%ebp
test   %rsi,%rsi
je     118d <at_tok_nextint_base+0x5d>
cmpq   $0x0,(%rdi)
je     118d <at_tok_nextint_base+0x5d>
mov    %ecx,%r12d
mov    %edx,%r15d
mov    %rsi,%rbx
call   1030 <nextTok@plt>
test   %rax,%rax
je     118d <at_tok_nextint_base+0x5d>
mov    %rax,%r14
lea    0x8(%rsp),%rsi
mov    %rax,%rdi
mov    %r15d,%edx
test   %r12d,%r12d
je     1179 <at_tok_nextint_base+0x49>
call   1050 <strtoul@plt>
jmp    117e <at_tok_nextint_base+0x4e>
call   1040 <strtol@plt>
mov    %eax,(%rbx)
xor    %ebp,%ebp
cmp    %r14,0x8(%rsp)
sete   %bpl
neg    %ebp
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @at_tok_nextint_base(i8** %0, i32* %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i8*
store i8** %0, i8*** %6
store i32* %1, i32** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
%13 = load i8**, i8*** %6
%14 = load i8*, i8** %13
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %17
16: ; preds = %4
store i32 -1, i32* %5
br label %48
17: ; preds = %4
%18 = load i32*, i32** %7
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %21
20: ; preds = %17
store i32 -1, i32* %5
br label %48
21: ; preds = %17
%22 = load i8**, i8*** %6
%23 = call i8* @nextTok(i8** %22)
store i8* %23, i8** %10
%24 = load i8*, i8** %10
%25 = icmp eq i8* %24, null
br i1 %25, label %26, label %27
26: ; preds = %21
store i32 -1, i32* %5
br label %48
27: ; preds = %21
%28 = load i32, i32* %9
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %34
30: ; preds = %27
%31 = load i8*, i8** %10
%32 = load i32, i32* %8
%33 = call i64 @strtoul(i8* %31, i8** %12, i32 %32)
store i64 %33, i64* %11
br label %38
34: ; preds = %27
%35 = load i8*, i8** %10
%36 = load i32, i32* %8
%37 = call i64 @strtol(i8* %35, i8** %12, i32 %36)
store i64 %37, i64* %11
br label %38
38: ; preds = %34, %30
%39 = load i64, i64* %11
%40 = trunc i64 %39 to i32
%41 = load i32*, i32** %7
store i32 %40, i32* %41
%42 = load i8*, i8** %12
%43 = load i8*, i8** %10
%44 = icmp eq i8* %42, %43
br i1 %44, label %45, label %46
45: ; preds = %38
store i32 -1, i32* %5
br label %48
46: ; preds = %38
br label %47
47: ; preds = %46
store i32 0, i32* %5
br label %48
48: ; preds = %47, %45, %26, %20, %16
%49 = load i32, i32* %5
ret i32 %49
}

LLVM IR (-O2):
define i32 @at_tok_nextint_base(i8** %0, i32* writeonly %1, i32 %2, i32 %3) {
%5 = alloca i8*
%6 = load i8*, i8** %0
%7 = icmp eq i8* %6, null
%8 = icmp eq i32* %1, null
%9 = or i1 %8, %7
br i1 %9, label %26, label %10
10: ; preds = %4
%11 = tail call i8* @nextTok(i8** %0)
%12 = icmp eq i8* %11, null
br i1 %12, label %26, label %13
13: ; preds = %10
%14 = bitcast i8** %5 to i8*
%15 = icmp eq i32 %3, 0
br i1 %15, label %18, label %16
16: ; preds = %13
%17 = call i64 @strtoul(i8* %11, i8** %5, i32 %2)
br label %20
18: ; preds = %13
%19 = call i64 @strtol(i8* %11, i8** %5, i32 %2)
br label %20
20: ; preds = %18, %16
%21 = phi i64 [ %17, %16 ], [ %19, %18 ]
%22 = trunc i64 %21 to i32
store i32 %22, i32* %1
%23 = load i8*, i8** %5
%24 = icmp eq i8* %23, %11
%25 = sext i1 %24 to i32
br label %26
26: ; preds = %20, %10, %4
%27 = phi i32 [ -1, %4 ], [ -1, %10 ], [ %25, %20 ]
ret i32 %27
}