#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 /*<<< orphan*/ exit(int);
int /*<<< orphan*/ isdigit(char);
int /*<<< orphan*/ printf(char *, ...);
void validateInput(char *filebuffer, int bufferlen) {
  int linecounter = 1;
  int poscounter = 0;
  int founderror = 0;
  int requireDigit = 0;
  char *endOfBuffer = filebuffer + bufferlen * sizeof(char) - 1;
  for (int i = 0; i <= endOfBuffer - filebuffer; i++) {
    if (filebuffer[i] != '\n') {
      poscounter++;
    } else {
      poscounter = 0;
      linecounter++;
    }
    if ((!isdigit(filebuffer[i]) && filebuffer[i] != ',' &&
         filebuffer[i] != '\n') ||
        (!isdigit(filebuffer[i]) && requireDigit)) {
      if (filebuffer[i] == '\n') {
        printf("char '\\n' with val %i in line %i at pos %i is not a valid "
               "input.\n",
               (int)filebuffer[i], linecounter, poscounter);
      } else {
        printf("char '%c' with val %i in line %i at pos %i is not a valid "
               "input.\n",
               filebuffer[i], (int)filebuffer[i], linecounter, poscounter);
      }
      founderror = 1;
    }
    if (filebuffer[i] == ',') {
      requireDigit = 1;
    } else {
      requireDigit = 0;
    }
  }
  if (founderror) {
    printf("\n%s\n", "only \\n separated lines with comma separated positive "
                     "integers allowed");
    exit(1);
  }
}


x86 assembly (clang, -O0):
<validateInput>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x1,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
shl    $0x0,%rcx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movslq -0x2c(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    -0x8(%rbp),%rdx
sub    %rdx,%rcx
cmp    %rcx,%rax
jg     12d5 <validateInput+0x1a5>
mov    -0x8(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
je     11b4 <validateInput+0x84>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11c4 <validateInput+0x94>
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%eax
jne    1208 <validateInput+0xd8>
mov    -0x8(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2c,%eax
je     1208 <validateInput+0xd8>
mov    -0x8(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    122c <validateInput+0xfc>
mov    -0x8(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%eax
jne    129a <validateInput+0x16a>
cmpl   $0x0,-0x1c(%rbp)
je     129a <validateInput+0x16a>
mov    -0x8(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    1266 <validateInput+0x136>
mov    -0x8(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
mov    -0x10(%rbp),%edx
mov    -0x14(%rbp),%ecx
lea    0xda6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1293 <validateInput+0x163>
mov    -0x8(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
mov    -0x8(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsbl (%rax,%rcx,1),%edx
mov    -0x10(%rbp),%ecx
mov    -0x14(%rbp),%r8d
lea    0xdb6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2c,%eax
jne    12bb <validateInput+0x18b>
movl   $0x1,-0x1c(%rbp)
jmp    12c2 <validateInput+0x192>
movl   $0x0,-0x1c(%rbp)
jmp    12c7 <validateInput+0x197>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1179 <validateInput+0x49>
cmpl   $0x0,-0x18(%rbp)
je     12fe <validateInput+0x1ce>
lea    0xd9e(%rip),%rdi
lea    0xd9c(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<validateInput>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
movslq %esi,%rax
lea    (%rdi,%rax,1),%rcx
mov    %rdi,%rdx
not    %rdx
add    %rcx,%rdx
js     1236 <validateInput+0x106>
mov    %rdi,%r12
cmp    $0x2,%rax
mov    $0x1,%r13d
cmovge %rax,%r13
mov    $0x1,%ebp
xor    %r15d,%r15d
xor    %r14d,%r14d
movl   $0x0,0x4(%rsp)
xor    %ebx,%ebx
jmp    11b5 <validateInput+0x85>
nopl   0x0(%rax)
movsbl %cl,%edx
lea    0xeb8(%rip),%rdi
mov    %edx,%esi
mov    %ebp,%ecx
mov    %ebx,%r8d
xor    %eax,%eax
call   1040 <printf@plt>
movl   $0x1,0x4(%rsp)
xor    %r14d,%r14d
cmpb   $0x2c,(%r12,%r15,1)
sete   %r14b
add    $0x1,%r15
cmp    %r15,%r13
je     122f <validateInput+0xff>
mov    %ebp,%eax
movsbl (%r12,%r15,1),%edi
add    $0x1,%ebx
xor    %ebp,%ebp
cmp    $0xa,%edi
sete   %bpl
mov    $0x0,%ecx
cmove  %ecx,%ebx
add    %eax,%ebp
call   1030 <isdigit@plt>
movzbl (%r12,%r15,1),%ecx
test   %eax,%eax
je     1220 <validateInput+0xf0>
movsbl %cl,%edi
call   1030 <isdigit@plt>
test   %r14d,%r14d
je     11a0 <validateInput+0x70>
test   %eax,%eax
jne    11a0 <validateInput+0x70>
movzbl (%r12,%r15,1),%ecx
cmp    $0xa,%cl
jne    1180 <validateInput+0x50>
lea    0xdfe(%rip),%rdi
mov    $0xa,%esi
mov    %ebp,%edx
mov    %ebx,%ecx
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1198 <validateInput+0x68>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
cmp    $0x2c,%cl
je     11e0 <validateInput+0xb0>
cmp    $0xa,%cl
je     11e0 <validateInput+0xb0>
jmp    1180 <validateInput+0x50>
cmpl   $0x0,0x4(%rsp)
jne    1245 <validateInput+0x115>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe38(%rip),%rdi
lea    0xe36(%rip),%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [66 x i8] c"char '\\n' with val %i in line %i at pos %i is not a valid input.\0A\00"
@.str.1 = [66 x i8] c"char '%c' with val %i in line %i at pos %i is not a valid input.\0A\00"
@.str.2 = [5 x i8] c"\0A%s\0A\00"
@.str.3 = [71 x i8] c"only \\n separated lines with comma separated positive integers allowed\00"
define void @validateInput(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
store i32 1, i32* %5
store i32 0, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
%11 = load i8*, i8** %3
%12 = load i32, i32* %4
%13 = sext i32 %12 to i64
%14 = mul i64 %13, 1
%15 = getelementptr inbounds i8, i8* %11, i64 %14
%16 = getelementptr inbounds i8, i8* %15, i64 -1
store i8* %16, i8** %9
store i32 0, i32* %10
br label %17
17: ; preds = %121, %2
%18 = load i32, i32* %10
%19 = sext i32 %18 to i64
%20 = load i8*, i8** %9
%21 = load i8*, i8** %3
%22 = ptrtoint i8* %20 to i64
%23 = ptrtoint i8* %21 to i64
%24 = sub i64 %22, %23
%25 = icmp sle i64 %19, %24
br i1 %25, label %26, label %124
26: ; preds = %17
%27 = load i8*, i8** %3
%28 = load i32, i32* %10
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp ne i32 %32, 10
br i1 %33, label %34, label %37
34: ; preds = %26
%35 = load i32, i32* %6
%36 = add nsw i32 %35, 1
store i32 %36, i32* %6
br label %40
37: ; preds = %26
store i32 0, i32* %6
%38 = load i32, i32* %5
%39 = add nsw i32 %38, 1
store i32 %39, i32* %5
br label %40
40: ; preds = %37, %34
%41 = load i8*, i8** %3
%42 = load i32, i32* %10
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8, i8* %41, i64 %43
%45 = load i8, i8* %44
%46 = call i32 @isdigit(i8 signext %45)
%47 = icmp ne i32 %46, 0
br i1 %47, label %64, label %48
48: ; preds = %40
%49 = load i8*, i8** %3
%50 = load i32, i32* %10
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8, i8* %49, i64 %51
%53 = load i8, i8* %52
%54 = sext i8 %53 to i32
%55 = icmp ne i32 %54, 44
br i1 %55, label %56, label %64
56: ; preds = %48
%57 = load i8*, i8** %3
%58 = load i32, i32* %10
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i8, i8* %57, i64 %59
%61 = load i8, i8* %60
%62 = sext i8 %61 to i32
%63 = icmp ne i32 %62, 10
br i1 %63, label %75, label %64
64: ; preds = %56, %48, %40
%65 = load i8*, i8** %3
%66 = load i32, i32* %10
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds i8, i8* %65, i64 %67
%69 = load i8, i8* %68
%70 = call i32 @isdigit(i8 signext %69)
%71 = icmp ne i32 %70, 0
br i1 %71, label %110, label %72
72: ; preds = %64
%73 = load i32, i32* %8
%74 = icmp ne i32 %73, 0
br i1 %74, label %75, label %110
75: ; preds = %72, %56
%76 = load i8*, i8** %3
%77 = load i32, i32* %10
%78 = sext i32 %77 to i64
%79 = getelementptr inbounds i8, i8* %76, i64 %78
%80 = load i8, i8* %79
%81 = sext i8 %80 to i32
%82 = icmp eq i32 %81, 10
br i1 %82, label %83, label %93
83: ; preds = %75
%84 = load i8*, i8** %3
%85 = load i32, i32* %10
%86 = sext i32 %85 to i64
%87 = getelementptr inbounds i8, i8* %84, i64 %86
%88 = load i8, i8* %87
%89 = sext i8 %88 to i32
%90 = load i32, i32* %5
%91 = load i32, i32* %6
%92 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str, i64 0, i64 0), i32 %89, i32 %90, i32 %91)
br label %109
93: ; preds = %75
%94 = load i8*, i8** %3
%95 = load i32, i32* %10
%96 = sext i32 %95 to i64
%97 = getelementptr inbounds i8, i8* %94, i64 %96
%98 = load i8, i8* %97
%99 = sext i8 %98 to i32
%100 = load i8*, i8** %3
%101 = load i32, i32* %10
%102 = sext i32 %101 to i64
%103 = getelementptr inbounds i8, i8* %100, i64 %102
%104 = load i8, i8* %103
%105 = sext i8 %104 to i32
%106 = load i32, i32* %5
%107 = load i32, i32* %6
%108 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.1, i64 0, i64 0), i32 %99, i32 %105, i32 %106, i32 %107)
br label %109
109: ; preds = %93, %83
store i32 1, i32* %7
br label %110
110: ; preds = %109, %72, %64
%111 = load i8*, i8** %3
%112 = load i32, i32* %10
%113 = sext i32 %112 to i64
%114 = getelementptr inbounds i8, i8* %111, i64 %113
%115 = load i8, i8* %114
%116 = sext i8 %115 to i32
%117 = icmp eq i32 %116, 44
br i1 %117, label %118, label %119
118: ; preds = %110
store i32 1, i32* %8
br label %120
119: ; preds = %110
store i32 0, i32* %8
br label %120
120: ; preds = %119, %118
br label %121
121: ; preds = %120
%122 = load i32, i32* %10
%123 = add nsw i32 %122, 1
store i32 %123, i32* %10
br label %17
124: ; preds = %17
%125 = load i32, i32* %7
%126 = icmp ne i32 %125, 0
br i1 %126, label %127, label %130
127: ; preds = %124
%128 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str.3, i64 0, i64 0))
%129 = call i32 @exit(i32 1)
unreachable
130: ; preds = %124
ret void
}

LLVM IR (-O2):
@.str = [66 x i8] c"char '\\n' with val %i in line %i at pos %i is not a valid input.\0A\00"
@.str.1 = [66 x i8] c"char '%c' with val %i in line %i at pos %i is not a valid input.\0A\00"
@.str.2 = [5 x i8] c"\0A%s\0A\00"
@.str.3 = [71 x i8] c"only \\n separated lines with comma separated positive integers allowed\00"
define void @validateInput(i8* %0, i32 %1) {
%3 = sext i32 %1 to i64
%4 = getelementptr inbounds i8, i8* %0, i64 %3
%5 = getelementptr inbounds i8, i8* %4, i64 -1
%6 = ptrtoint i8* %5 to i64
%7 = ptrtoint i8* %0 to i64
%8 = sub i64 %6, %7
%9 = icmp slt i64 %8, 0
br i1 %9, label %55, label %10
10: ; preds = %2
%11 = call i64 @llvm.smax.i64(i64 %3, i64 1)
br label %14
12: ; preds = %45
%13 = icmp eq i32 %46, 0
br i1 %13, label %55, label %52
14: ; preds = %10, %45
%15 = phi i64 [ 0, %10 ], [ %50, %45 ]
%16 = phi i32 [ 1, %10 ], [ %26, %45 ]
%17 = phi i32 [ 0, %10 ], [ %49, %45 ]
%18 = phi i32 [ 0, %10 ], [ %46, %45 ]
%19 = phi i32 [ 0, %10 ], [ %24, %45 ]
%20 = getelementptr inbounds i8, i8* %0, i64 %15
%21 = load i8, i8* %20
%22 = icmp eq i8 %21, 10
%23 = add nsw i32 %19, 1
%24 = select i1 %22, i32 0, i32 %23
%25 = zext i1 %22 to i32
%26 = add nuw nsw i32 %16, %25
%27 = tail call i32 @isdigit(i8 signext %21)
%28 = icmp eq i32 %27, 0
%29 = load i8, i8* %20
br i1 %28, label %30, label %31
30: ; preds = %14
switch i8 %29, label %41 [
i8 44, label %31
i8 10, label %31
]
31: ; preds = %14, %30, %30
%32 = tail call i32 @isdigit(i8 signext %29)
%33 = icmp eq i32 %32, 0
%34 = icmp ne i32 %17, 0
%35 = and i1 %34, %33
br i1 %35, label %36, label %45
36: ; preds = %31
%37 = load i8, i8* %20
%38 = icmp eq i8 %37, 10
br i1 %38, label %39, label %41
39: ; preds = %36
%40 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([66 x i8], [66 x i8]* @.str, i64 0, i64 0), i32 10, i32 %26, i32 %24)
br label %45
41: ; preds = %30, %36
%42 = phi i8 [ %37, %36 ], [ %29, %30 ]
%43 = sext i8 %42 to i32
%44 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([66 x i8], [66 x i8]* @.str.1, i64 0, i64 0), i32 %43, i32 %43, i32 %26, i32 %24)
br label %45
45: ; preds = %39, %41, %31
%46 = phi i32 [ %18, %31 ], [ 1, %41 ], [ 1, %39 ]
%47 = load i8, i8* %20
%48 = icmp eq i8 %47, 44
%49 = zext i1 %48 to i32
%50 = add nuw nsw i64 %15, 1
%51 = icmp eq i64 %50, %11
br i1 %51, label %12, label %14
52: ; preds = %12
%53 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str.3, i64 0, i64 0))
%54 = tail call i32 @exit(i32 1)
unreachable
55: ; preds = %2, %12
ret void
}