#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 */
typedef scalar_t__ uint32_t;
typedef int int64_t;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int get_llnum(char const *);
int /*<<< orphan*/ stderr;
char *strchr(char const *, char);
int strlen(char const *);
int strspn(char const *, char *);
int build_num_arr(const char *inp, uint32_t *num_arr, int *num_arr_len,
                  int max_arr_len) {
  int in_len, k;
  const char *lcp;
  int64_t ll;
  char *cp;
  char *c2p;
  if ((NULL == inp) || (NULL == num_arr) || (NULL == num_arr_len))
    return 1;
  lcp = inp;
  in_len = strlen(inp);
  if (0 == in_len)
    *num_arr_len = 0;
  if ('-' == inp[0]) {
    fprintf(stderr, "'--len' cannot be read from stdin\n");
    return 1;
  } else {
    k = strspn(inp, "0123456789aAbBcCdDeEfFhHxX, ");
    if (in_len != k) {
      fprintf(stderr, "build_num_arr: error at pos %d\n", k + 1);
      return 1;
    }
    for (k = 0; k < max_arr_len; ++k) {
      ll = get_llnum(lcp);
      if (-1 != ll) {
        num_arr[k] = (uint32_t)ll;
        cp = strchr(lcp, ',');
        c2p = strchr(lcp, ' ');
        if (NULL == cp)
          cp = c2p;
        if (NULL == cp)
          break;
        if (c2p && (c2p < cp))
          cp = c2p;
        lcp = cp + 1;
      } else {
        fprintf(stderr, "build_num_arr: error at pos %d\n",
                (int)(lcp - inp + 1));
        return 1;
      }
    }
    *num_arr_len = k + 1;
    if (k == max_arr_len) {
      fprintf(stderr, "build_num_arr: array length exceeded\n");
      return 1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<build_num_arr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
xor    %eax,%eax
cmp    -0x10(%rbp),%rax
je     118b <build_num_arr+0x3b>
xor    %eax,%eax
cmp    -0x18(%rbp),%rax
je     118b <build_num_arr+0x3b>
xor    %eax,%eax
cmp    -0x20(%rbp),%rax
jne    1197 <build_num_arr+0x47>
movl   $0x1,-0x4(%rbp)
jmp    1385 <build_num_arr+0x235>
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x28(%rbp)
xor    %eax,%eax
cmp    -0x28(%rbp),%eax
jne    11c0 <build_num_arr+0x70>
mov    -0x20(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x10(%rbp),%rax
movsbl (%rax),%ecx
mov    $0x2d,%eax
cmp    %ecx,%eax
jne    11f7 <build_num_arr+0xa7>
mov    0x2e05(%rip),%rax
mov    (%rax),%edi
lea    0xe1c(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1385 <build_num_arr+0x235>
mov    -0x10(%rbp),%rdi
lea    0xe21(%rip),%rsi
call   1060 <strspn@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x2c(%rbp),%eax
je     123f <build_num_arr+0xef>
mov    0x2dc3(%rip),%rax
mov    (%rax),%edi
mov    -0x2c(%rbp),%edx
add    $0x1,%edx
lea    0xe14(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1385 <build_num_arr+0x235>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    133e <build_num_arr+0x1ee>
mov    -0x38(%rbp),%rdi
call   1030 <get_llnum@plt>
mov    %eax,-0x3c(%rbp)
mov    $0xffffffff,%eax
cmp    -0x3c(%rbp),%eax
je     12f7 <build_num_arr+0x1a7>
movslq -0x3c(%rbp),%rdx
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x38(%rbp),%rdi
mov    $0x2c,%esi
call   1050 <strchr@plt>
mov    %rax,-0x48(%rbp)
mov    -0x38(%rbp),%rdi
mov    $0x20,%esi
call   1050 <strchr@plt>
mov    %rax,-0x50(%rbp)
xor    %eax,%eax
cmp    -0x48(%rbp),%rax
jne    12b4 <build_num_arr+0x164>
mov    -0x50(%rbp),%rax
mov    %rax,-0x48(%rbp)
xor    %eax,%eax
cmp    -0x48(%rbp),%rax
jne    12c5 <build_num_arr+0x175>
jmp    133e <build_num_arr+0x1ee>
cmpq   $0x0,-0x50(%rbp)
je     12e6 <build_num_arr+0x196>
mov    -0x50(%rbp),%rax
cmp    -0x48(%rbp),%rax
jae    12e6 <build_num_arr+0x196>
mov    -0x50(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    132b <build_num_arr+0x1db>
mov    0x2ce2(%rip),%rax
mov    (%rax),%edi
mov    -0x38(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
add    $0x1,%rax
mov    %eax,%edx
lea    0xd28(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1385 <build_num_arr+0x235>
jmp    1330 <build_num_arr+0x1e0>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1246 <build_num_arr+0xf6>
mov    -0x2c(%rbp),%ecx
add    $0x1,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x2c(%rbp),%eax
cmp    -0x24(%rbp),%eax
jne    1379 <build_num_arr+0x229>
mov    0x2c83(%rip),%rax
mov    (%rax),%edi
lea    0xcfa(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1385 <build_num_arr+0x235>
jmp    137e <build_num_arr+0x22e>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<build_num_arr>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    $0x1,%r12d
test   %rdi,%rdi
je     12d6 <build_num_arr+0x186>
mov    %rsi,%r13
test   %rsi,%rsi
je     12d6 <build_num_arr+0x186>
mov    %rdx,%rbp
test   %rdx,%rdx
je     12d6 <build_num_arr+0x186>
mov    %ecx,%r15d
mov    %rdi,%r14
call   1040 <strlen@plt>
mov    %eax,%ebx
test   %eax,%eax
je     11b1 <build_num_arr+0x61>
cmpb   $0x2d,(%r14)
jne    11be <build_num_arr+0x6e>
mov    0x2e3d(%rip),%rax
mov    (%rax),%edi
lea    0xe54(%rip),%rsi
jmp    12c9 <build_num_arr+0x179>
movl   $0x0,0x0(%rbp)
cmpb   $0x2d,(%r14)
je     119c <build_num_arr+0x4c>
lea    0xe5e(%rip),%rsi
mov    %r14,%rdi
call   1060 <strspn@plt>
cmp    %eax,%ebx
jne    126d <build_num_arr+0x11d>
mov    %rbp,0x8(%rsp)
xor    %r12d,%r12d
mov    %r15d,%ebp
mov    $0x0,%r15d
test   %ebp,%ebp
jle    12a9 <build_num_arr+0x159>
mov    %ebp,0x4(%rsp)
mov    %ebp,%eax
mov    %rax,0x10(%rsp)
xor    %r15d,%r15d
mov    %r14,%rbx
nop
mov    %rbx,%rdi
call   1030 <get_llnum@plt>
cmp    $0xffffffff,%eax
je     128b <build_num_arr+0x13b>
cltq
mov    %rax,0x0(%r13,%r15,8)
mov    %rbx,%rdi
mov    $0x2c,%esi
call   1050 <strchr@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
mov    $0x20,%esi
call   1050 <strchr@plt>
test   %rbp,%rbp
cmove  %rax,%rbp
test   %rbp,%rbp
je     12a5 <build_num_arr+0x155>
cmp    %rbp,%rax
mov    %rbp,%rbx
cmovb  %rax,%rbx
test   %rax,%rax
cmove  %rbp,%rbx
add    $0x1,%rbx
add    $0x1,%r15
cmp    %r15,0x10(%rsp)
jne    1200 <build_num_arr+0xb0>
mov    0x4(%rsp),%eax
add    $0x1,%eax
mov    0x8(%rsp),%rcx
mov    %eax,(%rcx)
jmp    12b9 <build_num_arr+0x169>
mov    0x2d6c(%rip),%rcx
mov    (%rcx),%edi
add    $0x1,%eax
lea    0xdc0(%rip),%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    12d0 <build_num_arr+0x180>
mov    0x2d4e(%rip),%rax
mov    (%rax),%edi
sub    %r14d,%ebx
add    $0x1,%ebx
lea    0xd9f(%rip),%rsi
mov    %ebx,%edx
jmp    1282 <build_num_arr+0x132>
mov    0x4(%rsp),%ebp
lea    0x1(%r15),%eax
mov    0x8(%rsp),%rcx
mov    %eax,(%rcx)
cmp    %ebp,%r15d
jne    12d6 <build_num_arr+0x186>
mov    0x2d20(%rip),%rax
mov    (%rax),%edi
lea    0xd97(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x1,%r12d
mov    %r12d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [35 x i8] c"'--len' cannot be read from stdin\0A\00"
@.str.1 = [29 x i8] c"0123456789aAbBcCdDeEfFhHxX, \00"
@.str.2 = [32 x i8] c"build_num_arr: error at pos %d\0A\00"
@.str.3 = [38 x i8] c"build_num_arr: array length exceeded\0A\00"
define i32 @build_num_arr(i8* %0, i64* %1, i32* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64*
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i32
%14 = alloca i8*
%15 = alloca i8*
store i8* %0, i8** %6
store i64* %1, i64** %7
store i32* %2, i32** %8
store i32 %3, i32* %9
%16 = load i8*, i8** %6
%17 = icmp eq i8* null, %16
br i1 %17, label %24, label %18
18: ; preds = %4
%19 = load i64*, i64** %7
%20 = icmp eq i64* null, %19
br i1 %20, label %24, label %21
21: ; preds = %18
%22 = load i32*, i32** %8
%23 = icmp eq i32* null, %22
br i1 %23, label %24, label %25
24: ; preds = %21, %18, %4
store i32 1, i32* %5
br label %120
25: ; preds = %21
%26 = load i8*, i8** %6
store i8* %26, i8** %12
%27 = load i8*, i8** %6
%28 = call i32 @strlen(i8* %27)
store i32 %28, i32* %10
%29 = load i32, i32* %10
%30 = icmp eq i32 0, %29
br i1 %30, label %31, label %33
31: ; preds = %25
%32 = load i32*, i32** %8
store i32 0, i32* %32
br label %33
33: ; preds = %31, %25
%34 = load i8*, i8** %6
%35 = getelementptr inbounds i8, i8* %34, i64 0
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = icmp eq i32 45, %37
br i1 %38, label %39, label %42
39: ; preds = %33
%40 = load i32, i32* @stderr
%41 = call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %5
br label %120
42: ; preds = %33
%43 = load i8*, i8** %6
%44 = call i32 @strspn(i8* %43, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
store i32 %44, i32* %11
%45 = load i32, i32* %10
%46 = load i32, i32* %11
%47 = icmp ne i32 %45, %46
br i1 %47, label %48, label %53
48: ; preds = %42
%49 = load i32, i32* @stderr
%50 = load i32, i32* %11
%51 = add nsw i32 %50, 1
%52 = call i32 (i32, i8*, ...) @fprintf(i32 %49, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i32 %51)
store i32 1, i32* %5
br label %120
53: ; preds = %42
store i32 0, i32* %11
br label %54
54: ; preds = %105, %53
%55 = load i32, i32* %11
%56 = load i32, i32* %9
%57 = icmp slt i32 %55, %56
br i1 %57, label %58, label %108
58: ; preds = %54
%59 = load i8*, i8** %12
%60 = call i32 @get_llnum(i8* %59)
store i32 %60, i32* %13
%61 = load i32, i32* %13
%62 = icmp ne i32 -1, %61
br i1 %62, label %63, label %94
63: ; preds = %58
%64 = load i32, i32* %13
%65 = sext i32 %64 to i64
%66 = load i64*, i64** %7
%67 = load i32, i32* %11
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds i64, i64* %66, i64 %68
store i64 %65, i64* %69
%70 = load i8*, i8** %12
%71 = call i8* @strchr(i8* %70, i8 signext 44)
store i8* %71, i8** %14
%72 = load i8*, i8** %12
%73 = call i8* @strchr(i8* %72, i8 signext 32)
store i8* %73, i8** %15
%74 = load i8*, i8** %14
%75 = icmp eq i8* null, %74
br i1 %75, label %76, label %78
76: ; preds = %63
%77 = load i8*, i8** %15
store i8* %77, i8** %14
br label %78
78: ; preds = %76, %63
%79 = load i8*, i8** %14
%80 = icmp eq i8* null, %79
br i1 %80, label %81, label %82
81: ; preds = %78
br label %108
82: ; preds = %78
%83 = load i8*, i8** %15
%84 = icmp ne i8* %83, null
br i1 %84, label %85, label %91
85: ; preds = %82
%86 = load i8*, i8** %15
%87 = load i8*, i8** %14
%88 = icmp ult i8* %86, %87
br i1 %88, label %89, label %91
89: ; preds = %85
%90 = load i8*, i8** %15
store i8* %90, i8** %14
br label %91
91: ; preds = %89, %85, %82
%92 = load i8*, i8** %14
%93 = getelementptr inbounds i8, i8* %92, i64 1
store i8* %93, i8** %12
br label %104
94: ; preds = %58
%95 = load i32, i32* @stderr
%96 = load i8*, i8** %12
%97 = load i8*, i8** %6
%98 = ptrtoint i8* %96 to i64
%99 = ptrtoint i8* %97 to i64
%100 = sub i64 %98, %99
%101 = add nsw i64 %100, 1
%102 = trunc i64 %101 to i32
%103 = call i32 (i32, i8*, ...) @fprintf(i32 %95, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i32 %102)
store i32 1, i32* %5
br label %120
104: ; preds = %91
br label %105
105: ; preds = %104
%106 = load i32, i32* %11
%107 = add nsw i32 %106, 1
store i32 %107, i32* %11
br label %54
108: ; preds = %81, %54
%109 = load i32, i32* %11
%110 = add nsw i32 %109, 1
%111 = load i32*, i32** %8
store i32 %110, i32* %111
%112 = load i32, i32* %11
%113 = load i32, i32* %9
%114 = icmp eq i32 %112, %113
br i1 %114, label %115, label %118
115: ; preds = %108
%116 = load i32, i32* @stderr
%117 = call i32 (i32, i8*, ...) @fprintf(i32 %116, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %5
br label %120
118: ; preds = %108
br label %119
119: ; preds = %118
store i32 0, i32* %5
br label %120
120: ; preds = %119, %115, %94, %48, %39, %24
%121 = load i32, i32* %5
ret i32 %121
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [35 x i8] c"'--len' cannot be read from stdin\0A\00"
@.str.1 = [29 x i8] c"0123456789aAbBcCdDeEfFhHxX, \00"
@.str.2 = [32 x i8] c"build_num_arr: error at pos %d\0A\00"
@.str.3 = [38 x i8] c"build_num_arr: array length exceeded\0A\00"
define i32 @build_num_arr(i8* %0, i64* writeonly %1, i32* writeonly %2, i32 %3) {
%5 = icmp eq i8* %0, null
%6 = icmp eq i64* %1, null
%7 = or i1 %5, %6
%8 = icmp eq i32* %2, null
%9 = or i1 %7, %8
br i1 %9, label %71, label %10
10: ; preds = %4
%11 = tail call i32 @strlen(i8* %0)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %10
store i32 0, i32* %2
br label %14
14: ; preds = %13, %10
%15 = load i8, i8* %0
%16 = icmp eq i8 %15, 45
br i1 %16, label %17, label %20
17: ; preds = %14
%18 = load i32, i32* @stderr
%19 = tail call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
br label %71
20: ; preds = %14
%21 = tail call i32 @strspn(i8* %0, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
%22 = icmp eq i32 %11, %21
br i1 %22, label %23, label %27
23: ; preds = %20
%24 = icmp sgt i32 %3, 0
br i1 %24, label %25, label %64
25: ; preds = %23
%26 = zext i32 %3 to i64
br label %31
27: ; preds = %20
%28 = load i32, i32* @stderr
%29 = add nsw i32 %21, 1
%30 = tail call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i32 %29)
br label %71
31: ; preds = %25, %44
%32 = phi i64 [ 0, %25 ], [ %50, %44 ]
%33 = phi i8* [ %0, %25 ], [ %49, %44 ]
%34 = tail call i32 @get_llnum(i8* %33)
%35 = icmp eq i32 %34, -1
br i1 %35, label %54, label %36
36: ; preds = %31
%37 = sext i32 %34 to i64
%38 = getelementptr inbounds i64, i64* %1, i64 %32
store i64 %37, i64* %38
%39 = tail call i8* @strchr(i8* %33, i8 signext 44)
%40 = tail call i8* @strchr(i8* %33, i8 signext 32)
%41 = icmp eq i8* %39, null
%42 = select i1 %41, i8* %40, i8* %39
%43 = icmp eq i8* %42, null
br i1 %43, label %62, label %44
44: ; preds = %36
%45 = icmp ne i8* %40, null
%46 = icmp ult i8* %40, %42
%47 = select i1 %45, i1 %46, i1 false
%48 = select i1 %47, i8* %40, i8* %42
%49 = getelementptr inbounds i8, i8* %48, i64 1
%50 = add nuw nsw i64 %32, 1
%51 = icmp eq i64 %50, %26
br i1 %51, label %52, label %31
52: ; preds = %44
%53 = add nuw nsw i32 %3, 1
store i32 %53, i32* %2
br label %68
54: ; preds = %31
%55 = load i32, i32* @stderr
%56 = ptrtoint i8* %33 to i64
%57 = ptrtoint i8* %0 to i64
%58 = sub i64 %56, %57
%59 = trunc i64 %58 to i32
%60 = add i32 %59, 1
%61 = tail call i32 (i32, i8*, ...) @fprintf(i32 %55, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i32 %60)
br label %71
62: ; preds = %36
%63 = trunc i64 %32 to i32
br label %64
64: ; preds = %62, %23
%65 = phi i32 [ 0, %23 ], [ %63, %62 ]
%66 = add nuw nsw i32 %65, 1
store i32 %66, i32* %2
%67 = icmp eq i32 %65, %3
br i1 %67, label %68, label %71
68: ; preds = %52, %64
%69 = load i32, i32* @stderr
%70 = tail call i32 (i32, i8*, ...) @fprintf(i32 %69, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0))
br label %71
71: ; preds = %64, %4, %68, %54, %27, %17
%72 = phi i32 [ 1, %17 ], [ 1, %27 ], [ 1, %68 ], [ 1, %54 ], [ 1, %4 ], [ 0, %64 ]
ret i32 %72
}