#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 int /*<<< orphan*/ FILE;

/* Variables and functions */
int EOF;
scalar_t__ calloc(int, int);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ free(int *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
int *parse_file_to_grid(FILE *fp) {
  int *board = (int *)calloc(81, sizeof(int));
  int *grid_pointer = board;
  int cell_counter = 0;
  for (int input = 0; (input = fgetc(fp)) != EOF;) {
    if (input != '\n' && input != ' ') {
      int current_char = input - '0';
      if ((current_char >= 0 && current_char <= 9) && (cell_counter < 81)) {
        *(grid_pointer++) = current_char;
        ++cell_counter;
      } else {
        if (current_char < 0 || current_char > 9) {
          printf("Invalid character '%c' present\n", input);
        } else {
          puts("More than 81 valid characters present.");
          ++cell_counter;
        }
        break;
      }
    }
  }
  if (cell_counter != 81) {
    puts("The wrong amount of cell values were given.");
    char *error = (cell_counter > 81) ? "more than" : "only";
    printf("81 should have been given, where as %s %i are present\n", error,
           cell_counter);
    free(board);
    board = NULL;
  }
  return board;
}


x86 assembly (clang, -O0):
<parse_file_to_grid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x51,%edi
mov    $0x4,%esi
call   1070 <calloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %eax,-0x20(%rbp)
mov    0x2e50(%rip),%rcx
cmp    (%rcx),%eax
je     124b <parse_file_to_grid+0xfb>
cmpl   $0xa,-0x20(%rbp)
je     1246 <parse_file_to_grid+0xf6>
cmpl   $0x20,-0x20(%rbp)
je     1246 <parse_file_to_grid+0xf6>
mov    -0x20(%rbp),%eax
sub    $0x30,%eax
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jl     11fd <parse_file_to_grid+0xad>
cmpl   $0x9,-0x24(%rbp)
jg     11fd <parse_file_to_grid+0xad>
cmpl   $0x51,-0x1c(%rbp)
jge    11fd <parse_file_to_grid+0xad>
mov    -0x24(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x4,%rdx
mov    %rdx,-0x18(%rbp)
mov    %ecx,(%rax)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1241 <parse_file_to_grid+0xf1>
cmpl   $0x0,-0x24(%rbp)
jl     1211 <parse_file_to_grid+0xc1>
cmpl   $0x9,-0x24(%rbp)
jle    1227 <parse_file_to_grid+0xd7>
mov    -0x20(%rbp),%esi
lea    0xde5(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    123c <parse_file_to_grid+0xec>
lea    0xdf2(%rip),%rdi
call   1040 <puts@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    124b <parse_file_to_grid+0xfb>
jmp    1246 <parse_file_to_grid+0xf6>
jmp    1185 <parse_file_to_grid+0x35>
cmpl   $0x51,-0x1c(%rbp)
je     12a3 <parse_file_to_grid+0x153>
lea    0xdeb(%rip),%rdi
call   1040 <puts@plt>
mov    -0x1c(%rbp),%edx
lea    0xe12(%rip),%rax
lea    0xe01(%rip),%rcx
cmp    $0x51,%edx
cmovg  %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rsi
mov    -0x1c(%rbp),%edx
lea    0xdf7(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_file_to_grid>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%rbx
mov    $0x51,%edi
mov    $0x4,%esi
call   1070 <calloc@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1060 <fgetc@plt>
mov    0x2e6c(%rip),%r15
cmp    (%r15),%eax
jne    119c <parse_file_to_grid+0x4c>
lea    0xebf(%rip),%rdi
call   1040 <puts@plt>
lea    0xee9(%rip),%rsi
xor    %r12d,%r12d
jmp    1222 <parse_file_to_grid+0xd2>
xor    %r12d,%r12d
mov    %r14,%rbp
jmp    11bd <parse_file_to_grid+0x6d>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
call   1060 <fgetc@plt>
cmp    (%r15),%eax
je     11fa <parse_file_to_grid+0xaa>
cmp    $0xa,%eax
je     11b0 <parse_file_to_grid+0x60>
cmp    $0x20,%eax
je     11b0 <parse_file_to_grid+0x60>
lea    -0x30(%rax),%ecx
cmp    $0x9,%ecx
ja     11e2 <parse_file_to_grid+0x92>
cmp    $0x51,%r12d
jge    11e2 <parse_file_to_grid+0x92>
mov    %ecx,0x0(%rbp)
add    $0x4,%rbp
add    $0x1,%r12d
jmp    11b0 <parse_file_to_grid+0x60>
lea    -0x3a(%rax),%ecx
cmp    $0xfffffff5,%ecx
ja     124a <parse_file_to_grid+0xfa>
lea    0xe0f(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
cmp    $0x51,%r12d
je     123e <parse_file_to_grid+0xee>
lea    0xe40(%rip),%rdi
call   1040 <puts@plt>
cmp    $0x52,%r12d
lea    0xe5c(%rip),%rax
lea    0xe5f(%rip),%rsi
cmovge %rax,%rsi
lea    0xe59(%rip),%rdi
mov    %r12d,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %r14d,%r14d
mov    %r14,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdcf(%rip),%rdi
call   1040 <puts@plt>
add    $0x1,%r12d
cmp    $0x51,%r12d
jne    1200 <parse_file_to_grid+0xb0>
jmp    123e <parse_file_to_grid+0xee>

LLVM IR (-O0):
@EOF = global i32 0
@.str = [32 x i8] c"Invalid character '%c' present\0A\00"
@.str.1 = [39 x i8] c"More than 81 valid characters present.\00"
@.str.2 = [44 x i8] c"The wrong amount of cell values were given.\00"
@.str.3 = [10 x i8] c"more than\00"
@.str.4 = [5 x i8] c"only\00"
@.str.5 = [55 x i8] c"81 should have been given, where as %s %i are present\0A\00"
define i32* @parse_file_to_grid(i32* %0) {
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
store i32* %0, i32** %2
%9 = call i64 @calloc(i32 81, i32 4)
%10 = inttoptr i64 %9 to i32*
store i32* %10, i32** %3
%11 = load i32*, i32** %3
store i32* %11, i32** %4
store i32 0, i32* %5
store i32 0, i32* %6
br label %12
12: ; preds = %55, %1
%13 = load i32*, i32** %2
%14 = call i32 @fgetc(i32* %13)
store i32 %14, i32* %6
%15 = load i32, i32* @EOF
%16 = icmp ne i32 %14, %15
br i1 %16, label %17, label %56
17: ; preds = %12
%18 = load i32, i32* %6
%19 = icmp ne i32 %18, 10
br i1 %19, label %20, label %55
20: ; preds = %17
%21 = load i32, i32* %6
%22 = icmp ne i32 %21, 32
br i1 %22, label %23, label %55
23: ; preds = %20
%24 = load i32, i32* %6
%25 = sub nsw i32 %24, 48
store i32 %25, i32* %7
%26 = load i32, i32* %7
%27 = icmp sge i32 %26, 0
br i1 %27, label %28, label %40
28: ; preds = %23
%29 = load i32, i32* %7
%30 = icmp sle i32 %29, 9
br i1 %30, label %31, label %40
31: ; preds = %28
%32 = load i32, i32* %5
%33 = icmp slt i32 %32, 81
br i1 %33, label %34, label %40
34: ; preds = %31
%35 = load i32, i32* %7
%36 = load i32*, i32** %4
%37 = getelementptr inbounds i32, i32* %36, i32 1
store i32* %37, i32** %4
store i32 %35, i32* %36
%38 = load i32, i32* %5
%39 = add nsw i32 %38, 1
store i32 %39, i32* %5
br label %54
40: ; preds = %31, %28, %23
%41 = load i32, i32* %7
%42 = icmp slt i32 %41, 0
br i1 %42, label %46, label %43
43: ; preds = %40
%44 = load i32, i32* %7
%45 = icmp sgt i32 %44, 9
br i1 %45, label %46, label %49
46: ; preds = %43, %40
%47 = load i32, i32* %6
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 %47)
br label %53
49: ; preds = %43
%50 = call i32 @puts(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0))
%51 = load i32, i32* %5
%52 = add nsw i32 %51, 1
store i32 %52, i32* %5
br label %53
53: ; preds = %49, %46
br label %56
54: ; preds = %34
br label %55
55: ; preds = %54, %20, %17
br label %12
56: ; preds = %53, %12
%57 = load i32, i32* %5
%58 = icmp ne i32 %57, 81
br i1 %58, label %59, label %70
59: ; preds = %56
%60 = call i32 @puts(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0))
%61 = load i32, i32* %5
%62 = icmp sgt i32 %61, 81
%63 = zext i1 %62 to i64
%64 = select i1 %62, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0)
store i8* %64, i8** %8
%65 = load i8*, i8** %8
%66 = load i32, i32* %5
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.5, i64 0, i64 0), i8* %65, i32 %66)
%68 = load i32*, i32** %3
%69 = call i32 @free(i32* %68)
store i32* null, i32** %3
br label %70
70: ; preds = %59, %56
%71 = load i32*, i32** %3
ret i32* %71
}

LLVM IR (-O2):
@EOF = global i32 0
@.str = [32 x i8] c"Invalid character '%c' present\0A\00"
@.str.1 = [39 x i8] c"More than 81 valid characters present.\00"
@.str.2 = [44 x i8] c"The wrong amount of cell values were given.\00"
@.str.3 = [10 x i8] c"more than\00"
@.str.4 = [5 x i8] c"only\00"
@.str.5 = [55 x i8] c"81 should have been given, where as %s %i are present\0A\00"
define i32* @parse_file_to_grid(i32* nocapture %0) {
%2 = tail call i64 @calloc(i32 81, i32 4)
%3 = inttoptr i64 %2 to i32*
%4 = tail call i32 @fgetc(i32* %0)
%5 = load i32, i32* @EOF
%6 = icmp eq i32 %4, %5
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0))
br label %42
9: ; preds = %1, %29
%10 = phi i32 [ %32, %29 ], [ %4, %1 ]
%11 = phi i32* [ %31, %29 ], [ %3, %1 ]
%12 = phi i32 [ %30, %29 ], [ 0, %1 ]
switch i32 %10, label %13 [
i32 32, label %29
i32 10, label %29
]
13: ; preds = %9
%14 = add i32 %10, -48
%15 = icmp ult i32 %14, 10
%16 = icmp slt i32 %12, 81
%17 = select i1 %15, i1 %16, i1 false
br i1 %17, label %26, label %18
18: ; preds = %13
%19 = add i32 %10, -58
%20 = icmp ult i32 %19, -10
br i1 %20, label %21, label %23
21: ; preds = %18
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 %10)
br label %35
23: ; preds = %18
%24 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0))
%25 = add nsw i32 %12, 1
br label %35
26: ; preds = %13
%27 = getelementptr inbounds i32, i32* %11, i64 1
store i32 %14, i32* %11
%28 = add nsw i32 %12, 1
br label %29
29: ; preds = %26, %9, %9
%30 = phi i32 [ %28, %26 ], [ %12, %9 ], [ %12, %9 ]
%31 = phi i32* [ %27, %26 ], [ %11, %9 ], [ %11, %9 ]
%32 = tail call i32 @fgetc(i32* %0)
%33 = load i32, i32* @EOF
%34 = icmp eq i32 %32, %33
br i1 %34, label %35, label %9
35: ; preds = %29, %23, %21
%36 = phi i32 [ %25, %23 ], [ %12, %21 ], [ %30, %29 ]
%37 = icmp eq i32 %36, 81
br i1 %37, label %47, label %38
38: ; preds = %35
%39 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0))
%40 = icmp sgt i32 %36, 81
%41 = select i1 %40, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0)
br label %42
42: ; preds = %38, %7
%43 = phi i32 [ 0, %7 ], [ %36, %38 ]
%44 = phi i8* [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), %7 ], [ %41, %38 ]
%45 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @.str.5, i64 0, i64 0), i8* %44, i32 %43)
%46 = tail call i32 @free(i32* %3)
br label %47
47: ; preds = %42, %35
%48 = phi i32* [ null, %42 ], [ %3, %35 ]
ret i32* %48
}