#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 */
unsigned int __builtin_ldwio(int volatile *);
unsigned int alt_up_rs232_check_parity(unsigned int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ rx_Handshake();
int receiveGameBoard(volatile int gameBoard[], int length) {
  unsigned int data_reg;
  unsigned char *data;
  unsigned int pe = 0;
  int retVal;
  char charGameBoard[101];
  int messageReceived = 0;
  int idx = 0, i = 0;
  rx_Handshake();
  printf("rx_Handshake established!\n");
  while (messageReceived == 0) {
    data_reg = __builtin_ldwio(((volatile int *)0x10001010));
    *data = (data_reg & 0x000001FF);
    retVal = ((data_reg & 0x00008000) >> 15) - 1;
    pe = alt_up_rs232_check_parity(data_reg);
    if (retVal != -1) {
      if (((char)('\n')) == ((char)*data)) {
        messageReceived = 1;
      } else {
        charGameBoard[idx] = (char)(*data);
        idx++;
      }
    }
  }
  if (idx != length)
    return 1;
  for (i = 0; i < idx; i++) {
    if (i % 10 == 0)
      printf("\n");
    printf("%c,", (char)charGameBoard[i]);
  }
  printf("\n");
  for (i = 0; i < length; i++) {
    gameBoard[i] = charGameBoard[i] - '0';
  }
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<receiveGameBoard>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x94(%rbp)
movl   $0x0,-0x98(%rbp)
movl   $0x0,-0x9c(%rbp)
mov    $0x0,%al
call   1030 <rx_Handshake@plt>
lea    0xe7b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x0,-0x94(%rbp)
jne    122c <receiveGameBoard+0xec>
mov    $0x10001010,%edi
call   1050 <__builtin_ldwio@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
and    $0x1ff,%eax
mov    %al,%cl
mov    -0x20(%rbp),%rax
mov    %cl,(%rax)
mov    -0x18(%rbp),%eax
and    $0x8000,%eax
shr    $0xf,%eax
sub    $0x1,%eax
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%edi
call   1060 <alt_up_rs232_check_parity@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x28(%rbp)
je     1227 <receiveGameBoard+0xe7>
mov    -0x20(%rbp),%rax
movsbl (%rax),%ecx
mov    $0xa,%eax
cmp    %ecx,%eax
jne    11ff <receiveGameBoard+0xbf>
movl   $0x1,-0x94(%rbp)
jmp    1222 <receiveGameBoard+0xe2>
mov    -0x20(%rbp),%rax
mov    (%rax),%cl
movslq -0x98(%rbp),%rax
mov    %cl,-0x90(%rbp,%rax,1)
mov    -0x98(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x98(%rbp)
jmp    1227 <receiveGameBoard+0xe7>
jmp    118c <receiveGameBoard+0x4c>
mov    -0x98(%rbp),%eax
cmp    -0x14(%rbp),%eax
je     1247 <receiveGameBoard+0x107>
movl   $0x1,-0x4(%rbp)
jmp    1329 <receiveGameBoard+0x1e9>
movl   $0x0,-0x9c(%rbp)
mov    -0x9c(%rbp),%eax
cmp    -0x98(%rbp),%eax
jge    12b9 <receiveGameBoard+0x179>
mov    -0x9c(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1288 <receiveGameBoard+0x148>
lea    0xd98(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movslq -0x9c(%rbp),%rax
movsbl -0x90(%rbp,%rax,1),%esi
ff
lea    0xd7d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x9c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x9c(%rbp)
jmp    1251 <receiveGameBoard+0x111>
lea    0xd59(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x9c(%rbp)
mov    -0x9c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1314 <receiveGameBoard+0x1d4>
movslq -0x9c(%rbp),%rax
movsbl -0x90(%rbp,%rax,1),%edx
ff
sub    $0x30,%edx
mov    -0x10(%rbp),%rax
movslq -0x9c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x9c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x9c(%rbp)
jmp    12d1 <receiveGameBoard+0x191>
lea    0xcfe(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<receiveGameBoard>:
push   %rax
xor    %eax,%eax
call   1040 <rx_Handshake@plt>
lea    0xec1(%rip),%rdi
call   1030 <puts@plt>
mov    $0x10001010,%edi
call   1050 <__builtin_ldwio@plt>

LLVM IR (-O0):
@.str = [27 x i8] c"rx_Handshake established!\0A\00"
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [4 x i8] c"%c,\00"
define i32 @receiveGameBoard(i32* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca [101 x i8]
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
store i32 0, i32* %8
store i32 0, i32* %11
store i32 0, i32* %12
store i32 0, i32* %13
%14 = call i32 (...) @rx_Handshake()
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %48, %2
%17 = load i32, i32* %11
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %49
19: ; preds = %16
%20 = call i32 @__builtin_ldwio(i32* inttoptr (i64 268439568 to i32*))
store i32 %20, i32* %6
%21 = load i32, i32* %6
%22 = and i32 %21, 511
%23 = trunc i32 %22 to i8
%24 = load i8*, i8** %7
store i8 %23, i8* %24
%25 = load i32, i32* %6
%26 = and i32 %25, 32768
%27 = lshr i32 %26, 15
%28 = sub i32 %27, 1
store i32 %28, i32* %9
%29 = load i32, i32* %6
%30 = call i32 @alt_up_rs232_check_parity(i32 %29)
store i32 %30, i32* %8
%31 = load i32, i32* %9
%32 = icmp ne i32 %31, -1
br i1 %32, label %33, label %48
33: ; preds = %19
%34 = load i8*, i8** %7
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = icmp eq i32 10, %36
br i1 %37, label %38, label %39
38: ; preds = %33
store i32 1, i32* %11
br label %47
39: ; preds = %33
%40 = load i8*, i8** %7
%41 = load i8, i8* %40
%42 = load i32, i32* %12
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [101 x i8], [101 x i8]* %10, i64 0, i64 %43
store i8 %41, i8* %44
%45 = load i32, i32* %12
%46 = add nsw i32 %45, 1
store i32 %46, i32* %12
br label %47
47: ; preds = %39, %38
br label %48
48: ; preds = %47, %19
br label %16
49: ; preds = %16
%50 = load i32, i32* %12
%51 = load i32, i32* %5
%52 = icmp ne i32 %50, %51
br i1 %52, label %53, label %54
53: ; preds = %49
store i32 1, i32* %3
br label %97
54: ; preds = %49
store i32 0, i32* %13
br label %55
55: ; preds = %72, %54
%56 = load i32, i32* %13
%57 = load i32, i32* %12
%58 = icmp slt i32 %56, %57
br i1 %58, label %59, label %75
59: ; preds = %55
%60 = load i32, i32* %13
%61 = srem i32 %60, 10
%62 = icmp eq i32 %61, 0
br i1 %62, label %63, label %65
63: ; preds = %59
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %65
65: ; preds = %63, %59
%66 = load i32, i32* %13
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds [101 x i8], [101 x i8]* %10, i64 0, i64 %67
%69 = load i8, i8* %68
%70 = sext i8 %69 to i32
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %70)
br label %72
72: ; preds = %65
%73 = load i32, i32* %13
%74 = add nsw i32 %73, 1
store i32 %74, i32* %13
br label %55
75: ; preds = %55
%76 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %13
br label %77
77: ; preds = %92, %75
%78 = load i32, i32* %13
%79 = load i32, i32* %5
%80 = icmp slt i32 %78, %79
br i1 %80, label %81, label %95
81: ; preds = %77
%82 = load i32, i32* %13
%83 = sext i32 %82 to i64
%84 = getelementptr inbounds [101 x i8], [101 x i8]* %10, i64 0, i64 %83
%85 = load i8, i8* %84
%86 = sext i8 %85 to i32
%87 = sub nsw i32 %86, 48
%88 = load i32*, i32** %4
%89 = load i32, i32* %13
%90 = sext i32 %89 to i64
%91 = getelementptr inbounds i32, i32* %88, i64 %90
store volatile i32 %87, i32* %91
br label %92
92: ; preds = %81
%93 = load i32, i32* %13
%94 = add nsw i32 %93, 1
store i32 %94, i32* %13
br label %77
95: ; preds = %77
%96 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %3
br label %97
97: ; preds = %95, %53
%98 = load i32, i32* %3
ret i32 %98
}

LLVM IR (-O2):
@str = [26 x i8] c"rx_Handshake established!\00"
define i32 @receiveGameBoard(i32* nocapture readnone %0, i32 %1) {
%3 = tail call i32 (...) @rx_Handshake()
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
%5 = tail call i32 @__builtin_ldwio(i32* inttoptr (i64 268439568 to i32*))
unreachable
}