#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 */
unsigned long long UCHAR_MAX;
unsigned long long ULLONG_MAX;
unsigned long long ULONG_MAX;
unsigned long long USHRT_MAX;
scalar_t__ isspace(char const);
int scan_for_uint64_pre(char const *, unsigned long long, unsigned long long *,
                        char const **);
int scan_for_uintN(const char *_str, int Nbit, unsigned long long *ret_,
                   const char **end_) {
  unsigned long long ret;
  unsigned long long max;
  int b_err = 0;
  const char *end;
  while (isspace(*_str)) {
    ++_str;
  }
  if (*_str == '+') {
    ++_str;
  }
  max = (Nbit == 64
             ? ULLONG_MAX
             : (Nbit == 32
                    ? ULONG_MAX
                    : (Nbit == 16 ? USHRT_MAX : (Nbit == 8 ? UCHAR_MAX : 0))));
  b_err = scan_for_uint64_pre(_str, max, &ret, &end);
  if (ret_) {
    *ret_ = ret;
  }
  if (end_) {
    *end_ = end;
  }
  return b_err;
}


x86 assembly (clang, -O0):
<scan_for_uintN>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isspace@plt>
cmp    $0x0,%rax
je     1165 <scan_for_uintN+0x45>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    113e <scan_for_uintN+0x1e>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2b,%eax
jne    1181 <scan_for_uintN+0x61>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
cmpl   $0x40,-0xc(%rbp)
jne    119e <scan_for_uintN+0x7e>
mov    0x2e4e(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x48(%rbp)
jmp    1218 <scan_for_uintN+0xf8>
cmpl   $0x20,-0xc(%rbp)
jne    11bb <scan_for_uintN+0x9b>
mov    0x2e11(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x50(%rbp)
jmp    1210 <scan_for_uintN+0xf0>
cmpl   $0x10,-0xc(%rbp)
jne    11d8 <scan_for_uintN+0xb8>
mov    0x2e0c(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x58(%rbp)
jmp    1208 <scan_for_uintN+0xe8>
cmpl   $0x8,-0xc(%rbp)
jne    11f5 <scan_for_uintN+0xd5>
mov    0x2e07(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x60(%rbp)
jmp    1200 <scan_for_uintN+0xe0>
xor    %eax,%eax
mov    %rax,-0x60(%rbp)
jmp    1200 <scan_for_uintN+0xe0>
mov    -0x60(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x30(%rbp),%rsi
lea    -0x28(%rbp),%rdx
lea    -0x40(%rbp),%rcx
call   1040 <scan_for_uint64_pre@plt>
mov    %eax,-0x34(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     124e <scan_for_uintN+0x12e>
mov    -0x28(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
cmpq   $0x0,-0x20(%rbp)
je     1264 <scan_for_uintN+0x144>
mov    -0x40(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x34(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<scan_for_uintN>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%r14
mov    %rdx,%r15
mov    %esi,%ebp
mov    %rdi,%rbx
add    $0xffffffffffffffff,%rbx
nopl   0x0(%rax)
movsbl 0x1(%rbx),%edi
add    $0x1,%rbx
call   1030 <isspace@plt>
test   %rax,%rax
jne    1140 <scan_for_uintN+0x20>
xor    %edi,%edi
cmpb   $0x2b,(%rbx)
sete   %dil
add    %rbx,%rdi
cmp    $0x10,%ebp
je     1176 <scan_for_uintN+0x56>
cmp    $0x20,%ebp
je     117f <scan_for_uintN+0x5f>
cmp    $0x40,%ebp
jne    1188 <scan_for_uintN+0x68>
mov    0x2e6c(%rip),%rax
jmp    1194 <scan_for_uintN+0x74>
mov    0x2e5b(%rip),%rax
jmp    1194 <scan_for_uintN+0x74>
mov    0x2e3a(%rip),%rax
jmp    1194 <scan_for_uintN+0x74>
cmp    $0x8,%ebp
jne    11cb <scan_for_uintN+0xab>
mov    0x2e5c(%rip),%rax
mov    (%rax),%rsi
lea    0x10(%rsp),%rdx
lea    0x8(%rsp),%rcx
call   1040 <scan_for_uint64_pre@plt>
test   %r15,%r15
je     11b3 <scan_for_uintN+0x93>
mov    0x10(%rsp),%rcx
mov    %rcx,(%r15)
test   %r14,%r14
je     11c0 <scan_for_uintN+0xa0>
mov    0x8(%rsp),%rcx
mov    %rcx,(%r14)
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %esi,%esi
jmp    1197 <scan_for_uintN+0x77>

LLVM IR (-O0):
@ULLONG_MAX = global i64 0
@ULONG_MAX = global i64 0
@USHRT_MAX = global i64 0
@UCHAR_MAX = global i64 0
define i32 @scan_for_uintN(i8* %0, i32 %1, i64* %2, i8** %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i64*
%8 = alloca i8**
%9 = alloca i64
%10 = alloca i64
%11 = alloca i32
%12 = alloca i8*
store i8* %0, i8** %5
store i32 %1, i32* %6
store i64* %2, i64** %7
store i8** %3, i8*** %8
store i32 0, i32* %11
br label %13
13: ; preds = %18, %4
%14 = load i8*, i8** %5
%15 = load i8, i8* %14
%16 = call i64 @isspace(i8 signext %15)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %13
%19 = load i8*, i8** %5
%20 = getelementptr inbounds i8, i8* %19, i32 1
store i8* %20, i8** %5
br label %13
21: ; preds = %13
%22 = load i8*, i8** %5
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %24, 43
br i1 %25, label %26, label %29
26: ; preds = %21
%27 = load i8*, i8** %5
%28 = getelementptr inbounds i8, i8* %27, i32 1
store i8* %28, i8** %5
br label %29
29: ; preds = %26, %21
%30 = load i32, i32* %6
%31 = icmp eq i32 %30, 64
br i1 %31, label %32, label %34
32: ; preds = %29
%33 = load i64, i64* @ULLONG_MAX
br label %56
34: ; preds = %29
%35 = load i32, i32* %6
%36 = icmp eq i32 %35, 32
br i1 %36, label %37, label %39
37: ; preds = %34
%38 = load i64, i64* @ULONG_MAX
br label %54
39: ; preds = %34
%40 = load i32, i32* %6
%41 = icmp eq i32 %40, 16
br i1 %41, label %42, label %44
42: ; preds = %39
%43 = load i64, i64* @USHRT_MAX
br label %52
44: ; preds = %39
%45 = load i32, i32* %6
%46 = icmp eq i32 %45, 8
br i1 %46, label %47, label %49
47: ; preds = %44
%48 = load i64, i64* @UCHAR_MAX
br label %50
49: ; preds = %44
br label %50
50: ; preds = %49, %47
%51 = phi i64 [ %48, %47 ], [ 0, %49 ]
br label %52
52: ; preds = %50, %42
%53 = phi i64 [ %43, %42 ], [ %51, %50 ]
br label %54
54: ; preds = %52, %37
%55 = phi i64 [ %38, %37 ], [ %53, %52 ]
br label %56
56: ; preds = %54, %32
%57 = phi i64 [ %33, %32 ], [ %55, %54 ]
store i64 %57, i64* %10
%58 = load i8*, i8** %5
%59 = load i64, i64* %10
%60 = call i32 @scan_for_uint64_pre(i8* %58, i64 %59, i64* %9, i8** %12)
store i32 %60, i32* %11
%61 = load i64*, i64** %7
%62 = icmp ne i64* %61, null
br i1 %62, label %63, label %66
63: ; preds = %56
%64 = load i64, i64* %9
%65 = load i64*, i64** %7
store i64 %64, i64* %65
br label %66
66: ; preds = %63, %56
%67 = load i8**, i8*** %8
%68 = icmp ne i8** %67, null
br i1 %68, label %69, label %72
69: ; preds = %66
%70 = load i8*, i8** %12
%71 = load i8**, i8*** %8
store i8* %70, i8** %71
br label %72
72: ; preds = %69, %66
%73 = load i32, i32* %11
ret i32 %73
}

LLVM IR (-O2):
@ULLONG_MAX = global i64 0
@ULONG_MAX = global i64 0
@USHRT_MAX = global i64 0
@UCHAR_MAX = global i64 0
define i32 @scan_for_uintN(i8* %0, i32 %1, i64* writeonly %2, i8** writeonly %3) {
%5 = alloca i64
%6 = alloca i8*
%7 = bitcast i64* %5 to i8*
%8 = bitcast i8** %6 to i8*
br label %9
9: ; preds = %9, %4
%10 = phi i8* [ %0, %4 ], [ %14, %9 ]
%11 = load i8, i8* %10
%12 = tail call i64 @isspace(i8 signext %11)
%13 = icmp eq i64 %12, 0
%14 = getelementptr inbounds i8, i8* %10, i64 1
br i1 %13, label %15, label %9
15: ; preds = %9
%16 = load i8, i8* %10
%17 = icmp eq i8 %16, 43
%18 = zext i1 %17 to i64
%19 = getelementptr i8, i8* %10, i64 %18
switch i32 %1, label %26 [
i32 64, label %20
i32 32, label %22
i32 16, label %24
]
20: ; preds = %15
%21 = load i64, i64* @ULLONG_MAX
br label %30
22: ; preds = %15
%23 = load i64, i64* @ULONG_MAX
br label %30
24: ; preds = %15
%25 = load i64, i64* @USHRT_MAX
br label %30
26: ; preds = %15
%27 = icmp eq i32 %1, 8
%28 = load i64, i64* @UCHAR_MAX
%29 = select i1 %27, i64 %28, i64 0
br label %30
30: ; preds = %22, %26, %24, %20
%31 = phi i64 [ %21, %20 ], [ %23, %22 ], [ %25, %24 ], [ %29, %26 ]
%32 = call i32 @scan_for_uint64_pre(i8* %19, i64 %31, i64* %5, i8** %6)
%33 = icmp eq i64* %2, null
br i1 %33, label %36, label %34
34: ; preds = %30
%35 = load i64, i64* %5
store i64 %35, i64* %2
br label %36
36: ; preds = %34, %30
%37 = icmp eq i8** %3, null
br i1 %37, label %40, label %38
38: ; preds = %36
%39 = load i8*, i8** %6
store i8* %39, i8** %3
br label %40
40: ; preds = %38, %36
ret i32 %32
}