#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*/ isdigit(char);
int strlen(char *);
char toupper(char);
int cwirc_is_grid_square(char *gs) {
  int i;
  i = strlen(gs);
  if (i != 4 && i != 6)
    return (0);
  if (toupper(gs[0]) < 'A' || toupper(gs[0]) > 'R' || toupper(gs[1]) < 'A' ||
      toupper(gs[1]) > 'R' || !isdigit(gs[2]) || !isdigit(gs[3]) ||
      (i == 6 && (toupper(gs[4]) < 'A' || toupper(gs[4]) > 'X' ||
                  toupper(gs[5]) < 'A' || toupper(gs[5]) > 'X')))
    return (0);
  return (1);
}


x86 assembly (clang, -O0):
<cwirc_is_grid_square>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x4,-0x14(%rbp)
je     1168 <cwirc_is_grid_square+0x38>
cmpl   $0x6,-0x14(%rbp)
je     1168 <cwirc_is_grid_square+0x38>
movl   $0x0,-0x4(%rbp)
jmp    1277 <cwirc_is_grid_square+0x147>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1040 <toupper@plt>
movsbl %al,%eax
cmp    $0x41,%eax
jl     1264 <cwirc_is_grid_square+0x134>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1040 <toupper@plt>
movsbl %al,%eax
cmp    $0x52,%eax
jg     1264 <cwirc_is_grid_square+0x134>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%edi
call   1040 <toupper@plt>
movsbl %al,%eax
cmp    $0x41,%eax
jl     1264 <cwirc_is_grid_square+0x134>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%edi
call   1040 <toupper@plt>
movsbl %al,%eax
cmp    $0x52,%eax
jg     1264 <cwirc_is_grid_square+0x134>
mov    -0x10(%rbp),%rax
movsbl 0x2(%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%eax
je     1264 <cwirc_is_grid_square+0x134>
mov    -0x10(%rbp),%rax
movsbl 0x3(%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%eax
je     1264 <cwirc_is_grid_square+0x134>
cmpl   $0x6,-0x14(%rbp)
jne    1270 <cwirc_is_grid_square+0x140>
mov    -0x10(%rbp),%rax
movsbl 0x4(%rax),%edi
call   1040 <toupper@plt>
movsbl %al,%eax
cmp    $0x41,%eax
jl     1264 <cwirc_is_grid_square+0x134>
mov    -0x10(%rbp),%rax
movsbl 0x4(%rax),%edi
call   1040 <toupper@plt>
movsbl %al,%eax
cmp    $0x58,%eax
jg     1264 <cwirc_is_grid_square+0x134>
mov    -0x10(%rbp),%rax
movsbl 0x5(%rax),%edi
call   1040 <toupper@plt>
movsbl %al,%eax
cmp    $0x41,%eax
jl     1264 <cwirc_is_grid_square+0x134>
mov    -0x10(%rbp),%rax
movsbl 0x5(%rax),%edi
call   1040 <toupper@plt>
movsbl %al,%eax
cmp    $0x58,%eax
jle    1270 <cwirc_is_grid_square+0x140>
movl   $0x0,-0x4(%rbp)
jmp    1277 <cwirc_is_grid_square+0x147>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cwirc_is_grid_square>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
call   1050 <strlen@plt>
mov    %eax,%ebp
and    $0xfffffffd,%eax
xor    %r14d,%r14d
cmp    $0x4,%eax
jne    11d8 <cwirc_is_grid_square+0xa8>
movsbl (%rbx),%edi
call   1040 <toupper@plt>
cmp    $0x41,%al
jl     11d8 <cwirc_is_grid_square+0xa8>
movsbl (%rbx),%edi
call   1040 <toupper@plt>
cmp    $0x52,%al
jg     11d8 <cwirc_is_grid_square+0xa8>
movsbl 0x1(%rbx),%edi
call   1040 <toupper@plt>
cmp    $0x41,%al
jl     11d8 <cwirc_is_grid_square+0xa8>
movsbl 0x1(%rbx),%edi
call   1040 <toupper@plt>
cmp    $0x52,%al
jg     11d8 <cwirc_is_grid_square+0xa8>
movsbl 0x2(%rbx),%edi
call   1030 <isdigit@plt>
test   %eax,%eax
je     11d8 <cwirc_is_grid_square+0xa8>
movsbl 0x3(%rbx),%edi
call   1030 <isdigit@plt>
test   %eax,%eax
je     11d8 <cwirc_is_grid_square+0xa8>
cmp    $0x6,%ebp
jne    11d2 <cwirc_is_grid_square+0xa2>
movsbl 0x4(%rbx),%edi
call   1040 <toupper@plt>
cmp    $0x41,%al
jl     11d8 <cwirc_is_grid_square+0xa8>
movsbl 0x4(%rbx),%edi
call   1040 <toupper@plt>
cmp    $0x58,%al
jg     11d8 <cwirc_is_grid_square+0xa8>
movsbl 0x5(%rbx),%edi
call   1040 <toupper@plt>
cmp    $0x41,%al
jl     11d8 <cwirc_is_grid_square+0xa8>
movsbl 0x5(%rbx),%edi
call   1040 <toupper@plt>
cmp    $0x58,%al
jg     11d8 <cwirc_is_grid_square+0xa8>
mov    $0x1,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @cwirc_is_grid_square(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = call i32 @strlen(i8* %5)
store i32 %6, i32* %4
%7 = load i32, i32* %4
%8 = icmp ne i32 %7, 4
br i1 %8, label %9, label %13
9: ; preds = %1
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 6
br i1 %11, label %12, label %13
12: ; preds = %9
store i32 0, i32* %2
br label %86
13: ; preds = %9, %1
%14 = load i8*, i8** %3
%15 = getelementptr inbounds i8, i8* %14, i64 0
%16 = load i8, i8* %15
%17 = call signext i8 @toupper(i8 signext %16)
%18 = sext i8 %17 to i32
%19 = icmp slt i32 %18, 65
br i1 %19, label %84, label %20
20: ; preds = %13
%21 = load i8*, i8** %3
%22 = getelementptr inbounds i8, i8* %21, i64 0
%23 = load i8, i8* %22
%24 = call signext i8 @toupper(i8 signext %23)
%25 = sext i8 %24 to i32
%26 = icmp sgt i32 %25, 82
br i1 %26, label %84, label %27
27: ; preds = %20
%28 = load i8*, i8** %3
%29 = getelementptr inbounds i8, i8* %28, i64 1
%30 = load i8, i8* %29
%31 = call signext i8 @toupper(i8 signext %30)
%32 = sext i8 %31 to i32
%33 = icmp slt i32 %32, 65
br i1 %33, label %84, label %34
34: ; preds = %27
%35 = load i8*, i8** %3
%36 = getelementptr inbounds i8, i8* %35, i64 1
%37 = load i8, i8* %36
%38 = call signext i8 @toupper(i8 signext %37)
%39 = sext i8 %38 to i32
%40 = icmp sgt i32 %39, 82
br i1 %40, label %84, label %41
41: ; preds = %34
%42 = load i8*, i8** %3
%43 = getelementptr inbounds i8, i8* %42, i64 2
%44 = load i8, i8* %43
%45 = call i32 @isdigit(i8 signext %44)
%46 = icmp ne i32 %45, 0
br i1 %46, label %47, label %84
47: ; preds = %41
%48 = load i8*, i8** %3
%49 = getelementptr inbounds i8, i8* %48, i64 3
%50 = load i8, i8* %49
%51 = call i32 @isdigit(i8 signext %50)
%52 = icmp ne i32 %51, 0
br i1 %52, label %53, label %84
53: ; preds = %47
%54 = load i32, i32* %4
%55 = icmp eq i32 %54, 6
br i1 %55, label %56, label %85
56: ; preds = %53
%57 = load i8*, i8** %3
%58 = getelementptr inbounds i8, i8* %57, i64 4
%59 = load i8, i8* %58
%60 = call signext i8 @toupper(i8 signext %59)
%61 = sext i8 %60 to i32
%62 = icmp slt i32 %61, 65
br i1 %62, label %84, label %63
63: ; preds = %56
%64 = load i8*, i8** %3
%65 = getelementptr inbounds i8, i8* %64, i64 4
%66 = load i8, i8* %65
%67 = call signext i8 @toupper(i8 signext %66)
%68 = sext i8 %67 to i32
%69 = icmp sgt i32 %68, 88
br i1 %69, label %84, label %70
70: ; preds = %63
%71 = load i8*, i8** %3
%72 = getelementptr inbounds i8, i8* %71, i64 5
%73 = load i8, i8* %72
%74 = call signext i8 @toupper(i8 signext %73)
%75 = sext i8 %74 to i32
%76 = icmp slt i32 %75, 65
br i1 %76, label %84, label %77
77: ; preds = %70
%78 = load i8*, i8** %3
%79 = getelementptr inbounds i8, i8* %78, i64 5
%80 = load i8, i8* %79
%81 = call signext i8 @toupper(i8 signext %80)
%82 = sext i8 %81 to i32
%83 = icmp sgt i32 %82, 88
br i1 %83, label %84, label %85
84: ; preds = %77, %70, %63, %56, %47, %41, %34, %27, %20, %13
store i32 0, i32* %2
br label %86
85: ; preds = %77, %53
store i32 1, i32* %2
br label %86
86: ; preds = %85, %84, %12
%87 = load i32, i32* %2
ret i32 %87
}

LLVM IR (-O2):
define i32 @cwirc_is_grid_square(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = and i32 %2, -3
%4 = icmp eq i32 %3, 4
br i1 %4, label %5, label %53
5: ; preds = %1
%6 = load i8, i8* %0
%7 = tail call signext i8 @toupper(i8 signext %6)
%8 = icmp slt i8 %7, 65
br i1 %8, label %53, label %9
9: ; preds = %5
%10 = load i8, i8* %0
%11 = tail call signext i8 @toupper(i8 signext %10)
%12 = icmp sgt i8 %11, 82
br i1 %12, label %53, label %13
13: ; preds = %9
%14 = getelementptr inbounds i8, i8* %0, i64 1
%15 = load i8, i8* %14
%16 = tail call signext i8 @toupper(i8 signext %15)
%17 = icmp slt i8 %16, 65
br i1 %17, label %53, label %18
18: ; preds = %13
%19 = load i8, i8* %14
%20 = tail call signext i8 @toupper(i8 signext %19)
%21 = icmp sgt i8 %20, 82
br i1 %21, label %53, label %22
22: ; preds = %18
%23 = getelementptr inbounds i8, i8* %0, i64 2
%24 = load i8, i8* %23
%25 = tail call i32 @isdigit(i8 signext %24)
%26 = icmp eq i32 %25, 0
br i1 %26, label %53, label %27
27: ; preds = %22
%28 = getelementptr inbounds i8, i8* %0, i64 3
%29 = load i8, i8* %28
%30 = tail call i32 @isdigit(i8 signext %29)
%31 = icmp eq i32 %30, 0
br i1 %31, label %53, label %32
32: ; preds = %27
%33 = icmp eq i32 %2, 6
br i1 %33, label %34, label %52
34: ; preds = %32
%35 = getelementptr inbounds i8, i8* %0, i64 4
%36 = load i8, i8* %35
%37 = tail call signext i8 @toupper(i8 signext %36)
%38 = icmp slt i8 %37, 65
br i1 %38, label %53, label %39
39: ; preds = %34
%40 = load i8, i8* %35
%41 = tail call signext i8 @toupper(i8 signext %40)
%42 = icmp sgt i8 %41, 88
br i1 %42, label %53, label %43
43: ; preds = %39
%44 = getelementptr inbounds i8, i8* %0, i64 5
%45 = load i8, i8* %44
%46 = tail call signext i8 @toupper(i8 signext %45)
%47 = icmp slt i8 %46, 65
br i1 %47, label %53, label %48
48: ; preds = %43
%49 = load i8, i8* %44
%50 = tail call signext i8 @toupper(i8 signext %49)
%51 = icmp sgt i8 %50, 88
br i1 %51, label %53, label %52
52: ; preds = %48, %32
br label %53
53: ; preds = %5, %9, %13, %18, %22, %27, %34, %39, %43, %48, %1, %52
%54 = phi i32 [ 1, %52 ], [ 0, %1 ], [ 0, %48 ], [ 0, %43 ], [ 0, %39 ], [ 0, %34 ], [ 0, %27 ], [ 0, %22 ], [ 0, %18 ], [ 0, %13 ], [ 0, %9 ], [ 0, %5 ]
ret i32 %54
}