#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 atoi(char *);
int *calloc(int, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int *realloc(int *, int);
int /*<<< orphan*/ stderr;
char *strtok(char *, char *);
int parse_field_numbers(int **indices, int *idxsize, int *nidx, char *list,
                        int nfields) {
  int n, i;
  char *fnum;
  int err = 0;
  int *idx = 0;
  if (!*indices || idxsize == 0) {
    *idxsize = nfields * 2;
    idx = calloc((*idxsize), sizeof(int));
    *indices = idx;
    *nidx = 0;
  }
  fnum = strtok(list, ", \t");
  i = 0;
  while (fnum) {
    if (*nidx >= *idxsize) {
      *idxsize *= 2;
      idx = realloc((idx), ((*idxsize) * sizeof(int)));
      *indices = idx;
    }
    n = atoi(fnum);
    if (n < 0 || n >= nfields) {
      fprintf(stderr, "bad field number in -n option: %s\n", fnum);
      err = -1;
    } else {
      idx[i++] = n;
      (*nidx)++;
    }
    fnum = strtok(NULL, ", \t");
  }
  return err;
}


x86 assembly (clang, -O0):
<parse_field_numbers>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
movl   $0x0,-0x3c(%rbp)
movq   $0x0,-0x48(%rbp)
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
je     1194 <parse_field_numbers+0x44>
cmpq   $0x0,-0x10(%rbp)
jne    11c9 <parse_field_numbers+0x79>
mov    -0x24(%rbp),%ecx
shl    $0x1,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
mov    $0x4,%esi
call   1030 <calloc@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x20(%rbp),%rdi
lea    0xe2c(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x2c(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     12b4 <parse_field_numbers+0x164>
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%eax
jl     1231 <parse_field_numbers+0xe1>
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
shl    $0x1,%ecx
mov    %ecx,(%rax)
mov    -0x48(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq (%rax),%rax
shl    $0x2,%rax
mov    %eax,%esi
call   1050 <realloc@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x38(%rbp),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jl     1253 <parse_field_numbers+0x103>
mov    -0x28(%rbp),%eax
cmp    -0x24(%rbp),%eax
jl     1278 <parse_field_numbers+0x128>
mov    0x2d86(%rip),%rax
mov    (%rax),%edi
mov    -0x38(%rbp),%rdx
lea    0xd9d(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x3c(%rbp)
jmp    129b <parse_field_numbers+0x14b>
mov    -0x28(%rbp),%edx
mov    -0x48(%rbp),%rax
mov    -0x2c(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x2c(%rbp)
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
xor    %eax,%eax
mov    %eax,%edi
lea    0xd5a(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x38(%rbp)
jmp    11e4 <parse_field_numbers+0x94>
mov    -0x3c(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_field_numbers>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8,0x8(%rsp)
mov    %rcx,%rbp
mov    %rdx,%r15
mov    %rsi,%r13
mov    %rdi,%r14
test   %rsi,%rsi
je     117e <parse_field_numbers+0x2e>
cmpq   $0x0,(%r14)
je     117e <parse_field_numbers+0x2e>
xor    %ebx,%ebx
jmp    11a1 <parse_field_numbers+0x51>
mov    0x8(%rsp),%rax
lea    (%rax,%rax,1),%edi
mov    %edi,0x0(%r13)
mov    $0x4,%esi
call   1030 <calloc@plt>
mov    %rax,%rbx
mov    %rax,(%r14)
movl   $0x0,(%r15)
lea    0xe58(%rip),%rsi
mov    %rbp,%rdi
call   1060 <strtok@plt>
test   %rax,%rax
je     124c <parse_field_numbers+0xfc>
mov    %rax,%rbp
mov    %r14,0x10(%rsp)
xor    %r12d,%r12d
xor    %r14d,%r14d
jmp    1204 <parse_field_numbers+0xb4>
nopl   0x0(%rax)
mov    0x2e09(%rip),%rax
mov    (%rax),%edi
lea    0xe24(%rip),%rsi
mov    %rbp,%rdx
call   1040 <fprintf@plt>
mov    $0xffffffff,%r12d
xor    %edi,%edi
lea    0xe09(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,%rbp
test   %rax,%rax
je     124f <parse_field_numbers+0xff>
mov    0x0(%r13),%esi
cmp    %esi,(%r15)
jl     122a <parse_field_numbers+0xda>
lea    (%rsi,%rsi,1),%eax
mov    %eax,0x0(%r13)
shl    $0x3,%esi
mov    %rbx,%rdi
call   1050 <realloc@plt>
mov    %rax,%rbx
mov    0x10(%rsp),%rax
mov    %rbx,(%rax)
mov    %rbp,%rdi
call   1070 <atoi@plt>
test   %eax,%eax
js     11d0 <parse_field_numbers+0x80>
cmp    0x8(%rsp),%eax
jge    11d0 <parse_field_numbers+0x80>
movslq %r14d,%rcx
add    $0x1,%r14d
mov    %eax,(%rbx,%rcx,4)
addl   $0x1,(%r15)
jmp    11ee <parse_field_numbers+0x9e>
xor    %r12d,%r12d
mov    %r12d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c", \09\00"
@stderr = global i32 0
@.str.1 = [35 x i8] c"bad field number in -n option: %s\0A\00"
define i32 @parse_field_numbers(i32** %0, i32* %1, i32* %2, i8* %3, i32 %4) {
%6 = alloca i32**
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i8*
%14 = alloca i32
%15 = alloca i32*
store i32** %0, i32*** %6
store i32* %1, i32** %7
store i32* %2, i32** %8
store i8* %3, i8** %9
store i32 %4, i32* %10
store i32 0, i32* %14
store i32* null, i32** %15
%16 = load i32**, i32*** %6
%17 = load i32*, i32** %16
%18 = icmp ne i32* %17, null
br i1 %18, label %19, label %22
19: ; preds = %5
%20 = load i32*, i32** %7
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %32
22: ; preds = %19, %5
%23 = load i32, i32* %10
%24 = mul nsw i32 %23, 2
%25 = load i32*, i32** %7
store i32 %24, i32* %25
%26 = load i32*, i32** %7
%27 = load i32, i32* %26
%28 = call i32* @calloc(i32 %27, i32 4)
store i32* %28, i32** %15
%29 = load i32*, i32** %15
%30 = load i32**, i32*** %6
store i32* %29, i32** %30
%31 = load i32*, i32** %8
store i32 0, i32* %31
br label %32
32: ; preds = %22, %19
%33 = load i8*, i8** %9
%34 = call i8* @strtok(i8* %33, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i8* %34, i8** %13
store i32 0, i32* %12
br label %35
35: ; preds = %80, %32
%36 = load i8*, i8** %13
%37 = icmp ne i8* %36, null
br i1 %37, label %38, label %82
38: ; preds = %35
%39 = load i32*, i32** %8
%40 = load i32, i32* %39
%41 = load i32*, i32** %7
%42 = load i32, i32* %41
%43 = icmp sge i32 %40, %42
br i1 %43, label %44, label %57
44: ; preds = %38
%45 = load i32*, i32** %7
%46 = load i32, i32* %45
%47 = mul nsw i32 %46, 2
store i32 %47, i32* %45
%48 = load i32*, i32** %15
%49 = load i32*, i32** %7
%50 = load i32, i32* %49
%51 = sext i32 %50 to i64
%52 = mul i64 %51, 4
%53 = trunc i64 %52 to i32
%54 = call i32* @realloc(i32* %48, i32 %53)
store i32* %54, i32** %15
%55 = load i32*, i32** %15
%56 = load i32**, i32*** %6
store i32* %55, i32** %56
br label %57
57: ; preds = %44, %38
%58 = load i8*, i8** %13
%59 = call i32 @atoi(i8* %58)
store i32 %59, i32* %11
%60 = load i32, i32* %11
%61 = icmp slt i32 %60, 0
br i1 %61, label %66, label %62
62: ; preds = %57
%63 = load i32, i32* %11
%64 = load i32, i32* %10
%65 = icmp sge i32 %63, %64
br i1 %65, label %66, label %70
66: ; preds = %62, %57
%67 = load i32, i32* @stderr
%68 = load i8*, i8** %13
%69 = call i32 @fprintf(i32 %67, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i8* %68)
store i32 -1, i32* %14
br label %80
70: ; preds = %62
%71 = load i32, i32* %11
%72 = load i32*, i32** %15
%73 = load i32, i32* %12
%74 = add nsw i32 %73, 1
store i32 %74, i32* %12
%75 = sext i32 %73 to i64
%76 = getelementptr inbounds i32, i32* %72, i64 %75
store i32 %71, i32* %76
%77 = load i32*, i32** %8
%78 = load i32, i32* %77
%79 = add nsw i32 %78, 1
store i32 %79, i32* %77
br label %80
80: ; preds = %70, %66
%81 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i8* %81, i8** %13
br label %35
82: ; preds = %35
%83 = load i32, i32* %14
ret i32 %83
}

LLVM IR (-O2):
@.str = [4 x i8] c", \09\00"
@stderr = global i32 0
@.str.1 = [35 x i8] c"bad field number in -n option: %s\0A\00"
define i32 @parse_field_numbers(i32** nocapture %0, i32* %1, i32* nocapture %2, i8* %3, i32 %4) {
%6 = load i32*, i32** %0
%7 = icmp eq i32* %6, null
%8 = icmp eq i32* %1, null
%9 = or i1 %8, %7
br i1 %9, label %10, label %13
10: ; preds = %5
%11 = shl nsw i32 %4, 1
store i32 %11, i32* %1
%12 = tail call i32* @calloc(i32 %11, i32 4)
store i32* %12, i32** %0
store i32 0, i32* %2
br label %13
13: ; preds = %5, %10
%14 = phi i32* [ %12, %10 ], [ null, %5 ]
%15 = tail call i8* @strtok(i8* %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%16 = icmp eq i8* %15, null
br i1 %16, label %49, label %17
17: ; preds = %13, %44
%18 = phi i32* [ %30, %44 ], [ %14, %13 ]
%19 = phi i32 [ %46, %44 ], [ 0, %13 ]
%20 = phi i8* [ %47, %44 ], [ %15, %13 ]
%21 = phi i32 [ %45, %44 ], [ 0, %13 ]
%22 = load i32, i32* %2
%23 = load i32, i32* %1
%24 = icmp slt i32 %22, %23
br i1 %24, label %29, label %25
25: ; preds = %17
%26 = shl nsw i32 %23, 1
store i32 %26, i32* %1
%27 = shl i32 %23, 3
%28 = tail call i32* @realloc(i32* %18, i32 %27)
store i32* %28, i32** %0
br label %29
29: ; preds = %25, %17
%30 = phi i32* [ %28, %25 ], [ %18, %17 ]
%31 = tail call i32 @atoi(i8* %20)
%32 = icmp sgt i32 %31, -1
%33 = icmp slt i32 %31, %4
%34 = and i1 %32, %33
br i1 %34, label %38, label %35
35: ; preds = %29
%36 = load i32, i32* @stderr
%37 = tail call i32 @fprintf(i32 %36, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i8* %20)
br label %44
38: ; preds = %29
%39 = add nsw i32 %21, 1
%40 = sext i32 %21 to i64
%41 = getelementptr inbounds i32, i32* %30, i64 %40
store i32 %31, i32* %41
%42 = load i32, i32* %2
%43 = add nsw i32 %42, 1
store i32 %43, i32* %2
br label %44
44: ; preds = %38, %35
%45 = phi i32 [ %21, %35 ], [ %39, %38 ]
%46 = phi i32 [ -1, %35 ], [ %19, %38 ]
%47 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%48 = icmp eq i8* %47, null
br i1 %48, label %49, label %17
49: ; preds = %44, %13
%50 = phi i32 [ 0, %13 ], [ %46, %44 ]
ret i32 %50
}