#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 *);
char *validate_grid_desc(char **pdesc, int range, int area) {
  char *desc = *pdesc;
  int squares = 0;
  while (*desc && *desc != ',') {
    int n = *desc++;
    if (n >= 'a' && n <= 'z') {
      squares += n - 'a' + 1;
    } else if (n == '_') {
      ;
    } else if (n > '0' && n <= '9') {
      int val = atoi(desc - 1);
      if (val < 1 || val > range)
        return "Out-of-range number in game description";
      squares++;
      while (*desc >= '0' && *desc <= '9')
        desc++;
    } else
      return "Invalid character in game description";
  }
  if (squares < area)
    return "Not enough data to fill grid";
  if (squares > area)
    return "Too much data to fit in grid";
  *pdesc = desc;
  return NULL;
}


x86 assembly (clang, -O0):
<validate_grid_desc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x2d(%rbp)
je     1159 <validate_grid_desc+0x49>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2c,%eax
setne  %al
mov    %al,-0x2d(%rbp)
mov    -0x2d(%rbp),%al
test   $0x1,%al
jne    1169 <validate_grid_desc+0x59>
jmp    1272 <validate_grid_desc+0x162>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movsbl (%rax),%eax
mov    %eax,-0x28(%rbp)
cmpl   $0x61,-0x28(%rbp)
jl     11a6 <validate_grid_desc+0x96>
cmpl   $0x7a,-0x28(%rbp)
jg     11a6 <validate_grid_desc+0x96>
mov    -0x28(%rbp),%eax
sub    $0x61,%eax
add    $0x1,%eax
add    -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
jmp    126d <validate_grid_desc+0x15d>
cmpl   $0x5f,-0x28(%rbp)
jne    11b5 <validate_grid_desc+0xa5>
jmp    1268 <validate_grid_desc+0x158>
cmpl   $0x30,-0x28(%rbp)
jle    1253 <validate_grid_desc+0x143>
cmpl   $0x39,-0x28(%rbp)
jg     1253 <validate_grid_desc+0x143>
mov    -0x20(%rbp),%rdi
add    $0xffffffffffffffff,%rdi
call   1030 <atoi@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x1,-0x2c(%rbp)
jl     11ef <validate_grid_desc+0xdf>
mov    -0x2c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jle    11ff <validate_grid_desc+0xef>
lea    0xe0a(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    12bd <validate_grid_desc+0x1ad>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x30,%ecx
mov    %al,-0x2e(%rbp)
jl     122d <validate_grid_desc+0x11d>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x39,%eax
setle  %al
mov    %al,-0x2e(%rbp)
mov    -0x2e(%rbp),%al
test   $0x1,%al
jne    123d <validate_grid_desc+0x12d>
jmp    124e <validate_grid_desc+0x13e>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1208 <validate_grid_desc+0xf8>
jmp    1263 <validate_grid_desc+0x153>
lea    0xdce(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    12bd <validate_grid_desc+0x1ad>
jmp    1268 <validate_grid_desc+0x158>
jmp    126d <validate_grid_desc+0x15d>
jmp    1134 <validate_grid_desc+0x24>
mov    -0x24(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    128e <validate_grid_desc+0x17e>
lea    0xdc9(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    12bd <validate_grid_desc+0x1ad>
mov    -0x24(%rbp),%eax
cmp    -0x18(%rbp),%eax
jle    12aa <validate_grid_desc+0x19a>
lea    0xdca(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    12bd <validate_grid_desc+0x1ad>
mov    -0x20(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<validate_grid_desc>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r8
mov    (%rdi),%rbp
xor    %r15d,%r15d
lea    0xefd(%rip),%rax
lea    0xece(%rip),%r13
mov    %rbp,%rdi
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rdi,%rbp
movsbl (%rdi),%ebx
test   %ebx,%ebx
je     11d0 <validate_grid_desc+0xc0>
cmp    $0x2c,%bl
je     11d0 <validate_grid_desc+0xc0>
lea    -0x61(%rbx),%ecx
cmp    $0x19,%cl
jbe    11c0 <validate_grid_desc+0xb0>
lea    0x1(%rbp),%rdi
cmp    $0x5f,%bl
je     1140 <validate_grid_desc+0x30>
add    $0xcf,%bl
cmp    $0x8,%bl
ja     11ee <validate_grid_desc+0xde>
mov    %r8,%rbx
mov    %edx,%r14d
mov    %esi,%r12d
add    $0xffffffffffffffff,%rdi
call   1030 <atoi@plt>
test   %eax,%eax
jle    11fd <validate_grid_desc+0xed>
cmp    %r12d,%eax
jg     11fd <validate_grid_desc+0xed>
mov    %r12d,%esi
xchg   %ax,%ax
movzbl 0x1(%rbp),%eax
add    $0x1,%rbp
add    $0xd0,%al
cmp    $0xa,%al
jb     1190 <validate_grid_desc+0x80>
add    $0x1,%r15d
mov    %r14d,%edx
mov    %rbx,%r8
lea    0xe79(%rip),%rax
jmp    1132 <validate_grid_desc+0x22>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    %ebx,%r15d
add    $0xffffffa0,%r15d
add    $0x1,%rbp
jmp    1132 <validate_grid_desc+0x22>
cmp    %edx,%r15d
jge    11de <validate_grid_desc+0xce>
lea    0xe72(%rip),%rax
jmp    11ee <validate_grid_desc+0xde>
jle    11e9 <validate_grid_desc+0xd9>
lea    0xe84(%rip),%rax
jmp    11ee <validate_grid_desc+0xde>
mov    %rbp,(%r8)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r13,%rax
jmp    11ee <validate_grid_desc+0xde>

LLVM IR (-O0):
@.str = [40 x i8] c"Out-of-range number in game description\00"
@.str.1 = [38 x i8] c"Invalid character in game description\00"
@.str.2 = [29 x i8] c"Not enough data to fill grid\00"
@.str.3 = [29 x i8] c"Too much data to fit in grid\00"
define i8* @validate_grid_desc(i8** %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i8** %0, i8*** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%12 = load i8**, i8*** %5
%13 = load i8*, i8** %12
store i8* %13, i8** %8
store i32 0, i32* %9
br label %14
14: ; preds = %85, %3
%15 = load i8*, i8** %8
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %24
19: ; preds = %14
%20 = load i8*, i8** %8
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp ne i32 %22, 44
br label %24
24: ; preds = %19, %14
%25 = phi i1 [ false, %14 ], [ %23, %19 ]
br i1 %25, label %26, label %86
26: ; preds = %24
%27 = load i8*, i8** %8
%28 = getelementptr inbounds i8, i8* %27, i32 1
store i8* %28, i8** %8
%29 = load i8, i8* %27
%30 = sext i8 %29 to i32
store i32 %30, i32* %10
%31 = load i32, i32* %10
%32 = icmp sge i32 %31, 97
br i1 %32, label %33, label %42
33: ; preds = %26
%34 = load i32, i32* %10
%35 = icmp sle i32 %34, 122
br i1 %35, label %36, label %42
36: ; preds = %33
%37 = load i32, i32* %10
%38 = sub nsw i32 %37, 97
%39 = add nsw i32 %38, 1
%40 = load i32, i32* %9
%41 = add nsw i32 %40, %39
store i32 %41, i32* %9
br label %85
42: ; preds = %33, %26
%43 = load i32, i32* %10
%44 = icmp eq i32 %43, 95
br i1 %44, label %45, label %46
45: ; preds = %42
br label %84
46: ; preds = %42
%47 = load i32, i32* %10
%48 = icmp sgt i32 %47, 48
br i1 %48, label %49, label %82
49: ; preds = %46
%50 = load i32, i32* %10
%51 = icmp sle i32 %50, 57
br i1 %51, label %52, label %82
52: ; preds = %49
%53 = load i8*, i8** %8
%54 = getelementptr inbounds i8, i8* %53, i64 -1
%55 = call i32 @atoi(i8* %54)
store i32 %55, i32* %11
%56 = load i32, i32* %11
%57 = icmp slt i32 %56, 1
br i1 %57, label %62, label %58
58: ; preds = %52
%59 = load i32, i32* %11
%60 = load i32, i32* %6
%61 = icmp sgt i32 %59, %60
br i1 %61, label %62, label %63
62: ; preds = %58, %52
store i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i8** %4
br label %99
63: ; preds = %58
%64 = load i32, i32* %9
%65 = add nsw i32 %64, 1
store i32 %65, i32* %9
br label %66
66: ; preds = %78, %63
%67 = load i8*, i8** %8
%68 = load i8, i8* %67
%69 = sext i8 %68 to i32
%70 = icmp sge i32 %69, 48
br i1 %70, label %71, label %76
71: ; preds = %66
%72 = load i8*, i8** %8
%73 = load i8, i8* %72
%74 = sext i8 %73 to i32
%75 = icmp sle i32 %74, 57
br label %76
76: ; preds = %71, %66
%77 = phi i1 [ false, %66 ], [ %75, %71 ]
br i1 %77, label %78, label %81
78: ; preds = %76
%79 = load i8*, i8** %8
%80 = getelementptr inbounds i8, i8* %79, i32 1
store i8* %80, i8** %8
br label %66
81: ; preds = %76
br label %83
82: ; preds = %49, %46
store i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8** %4
br label %99
83: ; preds = %81
br label %84
84: ; preds = %83, %45
br label %85
85: ; preds = %84, %36
br label %14
86: ; preds = %24
%87 = load i32, i32* %9
%88 = load i32, i32* %7
%89 = icmp slt i32 %87, %88
br i1 %89, label %90, label %91
90: ; preds = %86
store i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8** %4
br label %99
91: ; preds = %86
%92 = load i32, i32* %9
%93 = load i32, i32* %7
%94 = icmp sgt i32 %92, %93
br i1 %94, label %95, label %96
95: ; preds = %91
store i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i8** %4
br label %99
96: ; preds = %91
%97 = load i8*, i8** %8
%98 = load i8**, i8*** %5
store i8* %97, i8** %98
store i8* null, i8** %4
br label %99
99: ; preds = %96, %95, %90, %82, %62
%100 = load i8*, i8** %4
ret i8* %100
}

LLVM IR (-O2):
@.str = [40 x i8] c"Out-of-range number in game description\00"
@.str.1 = [38 x i8] c"Invalid character in game description\00"
@.str.2 = [29 x i8] c"Not enough data to fill grid\00"
@.str.3 = [29 x i8] c"Too much data to fit in grid\00"
define i8* @validate_grid_desc(i8** nocapture %0, i32 %1, i32 %2) {
%4 = load i8*, i8** %0
br label %5
5: ; preds = %19, %3
%6 = phi i32 [ 0, %3 ], [ %20, %19 ]
%7 = phi i8* [ %4, %3 ], [ %21, %19 ]
br label %8
8: ; preds = %5, %22
%9 = phi i8* [ %12, %22 ], [ %7, %5 ]
%10 = load i8, i8* %9
switch i8 %10, label %11 [
i8 0, label %40
i8 44, label %40
]
11: ; preds = %8
%12 = getelementptr inbounds i8, i8* %9, i64 1
%13 = add i8 %10, -97
%14 = icmp ult i8 %13, 26
br i1 %14, label %15, label %22
15: ; preds = %11
%16 = sext i8 %10 to i32
%17 = add i32 %6, -96
%18 = add i32 %17, %16
br label %19
19: ; preds = %15, %38
%20 = phi i32 [ %39, %38 ], [ %18, %15 ]
%21 = phi i8* [ %33, %38 ], [ %12, %15 ]
br label %5
22: ; preds = %11
%23 = icmp eq i8 %10, 95
br i1 %23, label %8, label %24
24: ; preds = %22
%25 = add i8 %10, -49
%26 = icmp ult i8 %25, 9
br i1 %26, label %27, label %45
27: ; preds = %24
%28 = tail call i32 @atoi(i8* %9)
%29 = icmp slt i32 %28, 1
%30 = icmp sgt i32 %28, %1
%31 = or i1 %29, %30
br i1 %31, label %45, label %32
32: ; preds = %27, %32
%33 = phi i8* [ %37, %32 ], [ %12, %27 ]
%34 = load i8, i8* %33
%35 = add i8 %34, -48
%36 = icmp ult i8 %35, 10
%37 = getelementptr inbounds i8, i8* %33, i64 1
br i1 %36, label %32, label %38
38: ; preds = %32
%39 = add nsw i32 %6, 1
br label %19
40: ; preds = %8, %8
%41 = icmp slt i32 %6, %2
br i1 %41, label %45, label %42
42: ; preds = %40
%43 = icmp sgt i32 %6, %2
br i1 %43, label %45, label %44
44: ; preds = %42
store i8* %9, i8** %0
br label %45
45: ; preds = %27, %24, %42, %40, %44
%46 = phi i8* [ null, %44 ], [ getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), %40 ], [ getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), %42 ], [ getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), %24 ], [ getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), %27 ]
ret i8* %46
}