#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;
  }
  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    11ed <at_tok_nextint_base+0xbd>
mov    -0x10(%rbp),%rdi
call   1030 <nextTok@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1184 <at_tok_nextint_base+0x54>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ed <at_tok_nextint_base+0xbd>
cmpl   $0x0,-0x20(%rbp)
je     11a7 <at_tok_nextint_base+0x77>
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%edx
lea    -0x38(%rbp),%rsi
call   1050 <strtoul@plt>
mov    %rax,-0x30(%rbp)
jmp    11bb <at_tok_nextint_base+0x8b>
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    11e1 <at_tok_nextint_base+0xb1>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ed <at_tok_nextint_base+0xbd>
jmp    11e6 <at_tok_nextint_base+0xb6>
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
cmpq   $0x0,(%rdi)
je     1189 <at_tok_nextint_base+0x59>
mov    %ecx,%r12d
mov    %edx,%r15d
mov    %rsi,%r14
call   1030 <nextTok@plt>
test   %rax,%rax
je     1189 <at_tok_nextint_base+0x59>
mov    %rax,%rbx
lea    0x8(%rsp),%rsi
mov    %rax,%rdi
mov    %r15d,%edx
test   %r12d,%r12d
je     1174 <at_tok_nextint_base+0x44>
call   1050 <strtoul@plt>
jmp    1179 <at_tok_nextint_base+0x49>
call   1040 <strtol@plt>
mov    %eax,(%r14)
xor    %ebp,%ebp
cmp    %rbx,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 %44
17: ; preds = %4
%18 = load i8**, i8*** %6
%19 = call i8* @nextTok(i8** %18)
store i8* %19, i8** %10
%20 = load i8*, i8** %10
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %23
22: ; preds = %17
store i32 -1, i32* %5
br label %44
23: ; preds = %17
%24 = load i32, i32* %9
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %30
26: ; preds = %23
%27 = load i8*, i8** %10
%28 = load i32, i32* %8
%29 = call i64 @strtoul(i8* %27, i8** %12, i32 %28)
store i64 %29, i64* %11
br label %34
30: ; preds = %23
%31 = load i8*, i8** %10
%32 = load i32, i32* %8
%33 = call i64 @strtol(i8* %31, i8** %12, i32 %32)
store i64 %33, i64* %11
br label %34
34: ; preds = %30, %26
%35 = load i64, i64* %11
%36 = trunc i64 %35 to i32
%37 = load i32*, i32** %7
store i32 %36, i32* %37
%38 = load i8*, i8** %12
%39 = load i8*, i8** %10
%40 = icmp eq i8* %38, %39
br i1 %40, label %41, label %42
41: ; preds = %34
store i32 -1, i32* %5
br label %44
42: ; preds = %34
br label %43
43: ; preds = %42
store i32 0, i32* %5
br label %44
44: ; preds = %43, %41, %22, %16
%45 = load i32, i32* %5
ret i32 %45
}

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