#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*/ clearInputStream();
unsigned char getchar();
unsigned char int2color(unsigned char);
int /*<<< orphan*/ printf(char *);
unsigned char getRowColors(unsigned char *rowColors) {
  unsigned char color, getAnother, valid = 0, column = 0;
  do {
    color = getchar();
    color = int2color(color);
    switch (color) {
    case 127u:
      if (column == 3) {
        getAnother = 0;
        valid = 1;
      } else {
        printf("not enough colors\n");
        getAnother = 0;
        valid = 0;
      }
      break;
    case 255u:
      printf("invalid color\n");
      clearInputStream();
      getAnother = 0;
      valid = 0;
      break;
    default:
      if (column < 3) {
        rowColors[column] = color;
        getAnother = 1;
        column++;
      } else {
        printf("too many colors\n");
        clearInputStream();
        getAnother = 0;
        valid = 0;
      }
      break;
    }
  } while (getAnother);
  return valid;
}


x86 assembly (clang, -O0):
<getRowColors>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movb   $0x0,-0xb(%rbp)
movb   $0x0,-0xc(%rbp)
xor    %eax,%eax
call   1060 <getchar@plt>
mov    %al,-0x9(%rbp)
movzbl -0x9(%rbp),%edi
call   1030 <int2color@plt>
mov    %al,-0x9(%rbp)
movzbl -0x9(%rbp),%eax
mov    %eax,-0x10(%rbp)
sub    $0x7f,%eax
je     1192 <getRowColors+0x52>
jmp    117f <getRowColors+0x3f>
mov    -0x10(%rbp),%eax
sub    $0xff,%eax
je     11c5 <getRowColors+0x85>
jmp    11e5 <getRowColors+0xa5>
movzbl -0xc(%rbp),%eax
cmp    $0x3,%eax
jne    11ac <getRowColors+0x6c>
movb   $0x0,-0xa(%rbp)
movb   $0x1,-0xb(%rbp)
jmp    11c0 <getRowColors+0x80>
lea    0xe4d(%rip),%rdi
call   1040 <printf@plt>
movb   $0x0,-0xa(%rbp)
movb   $0x0,-0xb(%rbp)
jmp    1231 <getRowColors+0xf1>
lea    0xe47(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1050 <clearInputStream@plt>
movb   $0x0,-0xa(%rbp)
movb   $0x0,-0xb(%rbp)
jmp    1231 <getRowColors+0xf1>
movzbl -0xc(%rbp),%eax
cmp    $0x3,%eax
jge    1211 <getRowColors+0xd1>
mov    -0x9(%rbp),%dl
mov    -0x8(%rbp),%rax
movzbl -0xc(%rbp),%ecx
mov    %dl,(%rax,%rcx,1)
movb   $0x1,-0xa(%rbp)
mov    -0xc(%rbp),%al
add    $0x1,%al
mov    %al,-0xc(%rbp)
jmp    122c <getRowColors+0xec>
lea    0xe0a(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1050 <clearInputStream@plt>
movb   $0x0,-0xa(%rbp)
movb   $0x0,-0xb(%rbp)
jmp    1231 <getRowColors+0xf1>
jmp    1236 <getRowColors+0xf6>
cmpb   $0x0,-0xa(%rbp)
jne    1154 <getRowColors+0x14>
movzbl -0xb(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getRowColors>:
push   %rbx
mov    %rdi,%rbx
xor    %eax,%eax
call   1060 <getchar@plt>
movzbl %al,%edi
call   1040 <int2color@plt>
cmp    $0xff,%al
je     11c3 <getRowColors+0x83>
cmp    $0x7f,%al
je     118e <getRowColors+0x4e>
mov    %al,(%rbx)
xor    %eax,%eax
call   1060 <getchar@plt>
movzbl %al,%edi
call   1040 <int2color@plt>
cmp    $0xff,%al
je     11c3 <getRowColors+0x83>
cmp    $0x7f,%al
je     118e <getRowColors+0x4e>
mov    %al,0x1(%rbx)
xor    %eax,%eax
call   1060 <getchar@plt>
movzbl %al,%edi
call   1040 <int2color@plt>
cmp    $0xff,%al
je     11c3 <getRowColors+0x83>
cmp    $0x7f,%al
jne    119e <getRowColors+0x5e>
lea    0xe79(%rip),%rdi
call   1030 <puts@plt>
xor    %ebx,%ebx
jmp    11d8 <getRowColors+0x98>
mov    %al,0x2(%rbx)
xor    %eax,%eax
call   1060 <getchar@plt>
movzbl %al,%edi
call   1040 <int2color@plt>
cmp    $0xff,%al
je     11c3 <getRowColors+0x83>
mov    $0x1,%bl
cmp    $0x7f,%al
je     11d8 <getRowColors+0x98>
lea    0xe5f(%rip),%rdi
jmp    11ca <getRowColors+0x8a>
lea    0xe36(%rip),%rdi
call   1030 <puts@plt>
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <clearInputStream@plt>
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [19 x i8] c"not enough colors\0A\00"
@.str.1 = [15 x i8] c"invalid color\0A\00"
@.str.2 = [17 x i8] c"too many colors\0A\00"
define zeroext i8 @getRowColors(i8* %0) {
%2 = alloca i8*
%3 = alloca i8
%4 = alloca i8
%5 = alloca i8
%6 = alloca i8
store i8* %0, i8** %2
store i8 0, i8* %5
store i8 0, i8* %6
br label %7
7: ; preds = %41, %1
%8 = call zeroext i8 (...) @getchar()
store i8 %8, i8* %3
%9 = load i8, i8* %3
%10 = call zeroext i8 @int2color(i8 zeroext %9)
store i8 %10, i8* %3
%11 = load i8, i8* %3
%12 = zext i8 %11 to i32
switch i32 %12, label %24 [
i32 127, label %13
i32 255, label %21
]
13: ; preds = %7
%14 = load i8, i8* %6
%15 = zext i8 %14 to i32
%16 = icmp eq i32 %15, 3
br i1 %16, label %17, label %18
17: ; preds = %13
store i8 0, i8* %4
store i8 1, i8* %5
br label %20
18: ; preds = %13
%19 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
store i8 0, i8* %4
store i8 0, i8* %5
br label %20
20: ; preds = %18, %17
br label %40
21: ; preds = %7
%22 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%23 = call i32 (...) @clearInputStream()
store i8 0, i8* %4
store i8 0, i8* %5
br label %40
24: ; preds = %7
%25 = load i8, i8* %6
%26 = zext i8 %25 to i32
%27 = icmp slt i32 %26, 3
br i1 %27, label %28, label %36
28: ; preds = %24
%29 = load i8, i8* %3
%30 = load i8*, i8** %2
%31 = load i8, i8* %6
%32 = zext i8 %31 to i64
%33 = getelementptr inbounds i8, i8* %30, i64 %32
store i8 %29, i8* %33
store i8 1, i8* %4
%34 = load i8, i8* %6
%35 = add i8 %34, 1
store i8 %35, i8* %6
br label %39
36: ; preds = %24
%37 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%38 = call i32 (...) @clearInputStream()
store i8 0, i8* %4
store i8 0, i8* %5
br label %39
39: ; preds = %36, %28
br label %40
40: ; preds = %39, %21, %20
br label %41
41: ; preds = %40
%42 = load i8, i8* %4
%43 = icmp ne i8 %42, 0
br i1 %43, label %7, label %44
44: ; preds = %41
%45 = load i8, i8* %5
ret i8 %45
}

LLVM IR (-O2):
@str = [14 x i8] c"invalid color\00"
@str.3 = [18 x i8] c"not enough colors\00"
@str.4 = [16 x i8] c"too many colors\00"
define zeroext i8 @getRowColors(i8* nocapture writeonly %0) {
%2 = tail call zeroext i8 (...) @getchar()
%3 = tail call zeroext i8 @int2color(i8 zeroext %2)
switch i8 %3, label %9 [
i8 127, label %4
i8 -1, label %6
]
4: ; preds = %15, %9, %1
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.3, i64 0, i64 0))
br label %23
6: ; preds = %19, %15, %9, %1
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
%8 = tail call i32 (...) @clearInputStream()
br label %23
9: ; preds = %1
store i8 %3, i8* %0
%10 = tail call zeroext i8 (...) @getchar()
%11 = tail call zeroext i8 @int2color(i8 zeroext %10)
switch i8 %11, label %15 [
i8 127, label %4
i8 -1, label %6
]
12: ; preds = %19
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.4, i64 0, i64 0))
%14 = tail call i32 (...) @clearInputStream()
br label %23
15: ; preds = %9
%16 = getelementptr inbounds i8, i8* %0, i64 1
store i8 %11, i8* %16
%17 = tail call zeroext i8 (...) @getchar()
%18 = tail call zeroext i8 @int2color(i8 zeroext %17)
switch i8 %18, label %19 [
i8 127, label %4
i8 -1, label %6
]
19: ; preds = %15
%20 = getelementptr inbounds i8, i8* %0, i64 2
store i8 %18, i8* %20
%21 = tail call zeroext i8 (...) @getchar()
%22 = tail call zeroext i8 @int2color(i8 zeroext %21)
switch i8 %22, label %12 [
i8 127, label %23
i8 -1, label %6
]
23: ; preds = %19, %6, %4, %12
%24 = phi i8 [ 0, %12 ], [ 0, %4 ], [ 0, %6 ], [ 1, %19 ]
ret i8 %24
}