#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 build_header(int, int);
unsigned int get_flit_payload(unsigned int);
unsigned int get_flit_type(unsigned int);
int /*<<< orphan*/ setup_uart(int, int);
int /*<<< orphan*/ test_plasma_funcitons();
int /*<<< orphan*/ uart_print_num(unsigned int, int, int /*<<< orphan*/);
int /*<<< orphan*/ uart_putchar(char);
int /*<<< orphan*/ uart_puts(char *);
int main(int argc, char const *argv[]) {
  unsigned flit;
  unsigned flit_type;
  unsigned payload;
  unsigned packet_counter = 1;
  setup_uart(25000000, 57600);
  uart_puts("UART TEST: If you can read this, then UART output works!\n");
  unsigned gpio_in = (*(volatile unsigned int *)(0x20000050));
  (*(volatile unsigned int *)(0x20000030) = (gpio_in));
  uart_puts("\n\nBeginning communication test\n\n");
  (*(volatile unsigned int *)0x7FFCu = (build_header(1, 3)));
  (*(volatile unsigned int *)0x7FFCu = (0b1111111111111111111111111111));
  (*(volatile unsigned int *)0x7FFCu = (0));
  while (packet_counter <= 100) {
    if (((*(volatile unsigned int *)0x8000u) & 0x80000000) == 0) {
      flit = (*(volatile unsigned int *)0x7FFCu);
      flit_type = get_flit_type(flit);
      if (flit_type == 0b001) {
        uart_puts("Sending packet number ");
        uart_print_num(packet_counter, 10, 0);
        uart_putchar('\n');
        (*(volatile unsigned int *)0x7FFCu = (build_header(1, 3)));
      } else if (flit_type == 0b100) {
        payload = get_flit_payload(flit);
        (*(volatile unsigned int *)0x7FFCu = (payload));
        packet_counter++;
      } else {
        payload = get_flit_payload(flit);
        (*(volatile unsigned int *)0x7FFCu = (payload));
      }
    }
  }
  while (((*(volatile unsigned int *)0x8000u) & 0x80000000) == 0) {
    flit = (*(volatile unsigned int *)0x7FFCu);
    flit_type = get_flit_type(flit);
    packet_counter++;
  }
  test_plasma_funcitons();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x20(%rbp)
mov    $0x17d7840,%edi
mov    $0xe100,%esi
call   1060 <setup_uart@plt>
lea    0xe4d(%rip),%rdi
call   10a0 <uart_puts@plt>
mov    $0x20000050,%eax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%ecx
mov    $0x20000030,%eax
mov    %ecx,(%rax)
lea    0xe67(%rip),%rdi
call   10a0 <uart_puts@plt>
mov    $0x1,%edi
mov    $0x3,%esi
call   1080 <build_header@plt>
mov    %eax,%ecx
mov    $0x7ffc,%eax
mov    %ecx,(%rax)
mov    $0x7ffc,%eax
movl   $0xfffffff,(%rax)
mov    $0x7ffc,%eax
movl   $0x0,(%rax)
cmpl   $0x64,-0x20(%rbp)
ja     12d7 <main+0x157>
mov    $0x8000,%eax
mov    (%rax),%eax
and    $0x80000000,%eax
cmp    $0x0,%eax
jne    12d2 <main+0x152>
mov    $0x7ffc,%eax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <get_flit_type@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x1,-0x18(%rbp)
jne    1286 <main+0x106>
lea    0xe10(%rip),%rdi
call   10a0 <uart_puts@plt>
mov    -0x20(%rbp),%edi
mov    $0xa,%esi
xor    %edx,%edx
call   1040 <uart_print_num@plt>
mov    $0xa,%edi
call   1050 <uart_putchar@plt>
mov    $0x1,%edi
mov    $0x3,%esi
call   1080 <build_header@plt>
mov    %eax,%ecx
mov    $0x7ffc,%eax
mov    %ecx,(%rax)
jmp    12cd <main+0x14d>
cmpl   $0x4,-0x18(%rbp)
jne    12b3 <main+0x133>
mov    -0x14(%rbp),%edi
call   1070 <get_flit_payload@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%ecx
mov    $0x7ffc,%eax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    12c8 <main+0x148>
mov    -0x14(%rbp),%edi
call   1070 <get_flit_payload@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%ecx
mov    $0x7ffc,%eax
mov    %ecx,(%rax)
jmp    12cd <main+0x14d>
jmp    12d2 <main+0x152>
jmp    1206 <main+0x86>
jmp    12dc <main+0x15c>
mov    $0x8000,%eax
mov    (%rax),%eax
and    $0x80000000,%eax
cmp    $0x0,%eax
jne    1314 <main+0x194>
mov    $0x7ffc,%eax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <get_flit_type@plt>
mov    %eax,-0x18(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    12dc <main+0x15c>
mov    $0x0,%al
call   1090 <test_plasma_funcitons@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    $0x17d7840,%edi
mov    $0xe100,%esi
call   1060 <setup_uart@plt>
lea    0xe66(%rip),%rdi
call   10a0 <uart_puts@plt>
mov    0x20000050,%eax
mov    %eax,0x20000030
lea    0xe86(%rip),%rdi
call   10a0 <uart_puts@plt>
mov    $0x1,%ebx
mov    $0x1,%edi
mov    $0x3,%esi
call   1080 <build_header@plt>
mov    %eax,0x7ffc
movl   $0xfffffff,0x7ffc
ff ff ff 0f
movl   $0x0,0x7ffc
lea    0xe6a(%rip),%r14
jmp    1217 <main+0x97>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %ebp,%edi
call   1070 <get_flit_payload@plt>
mov    %eax,0x7ffc
cmp    $0x65,%ebx
jae    129c <main+0x11c>
cmpl   $0x0,0x8000
js     120e <main+0x8e>
mov    0x7ffc,%ebp
mov    %ebp,%edi
call   1030 <get_flit_type@plt>
cmp    $0x4,%eax
je     1270 <main+0xf0>
cmp    $0x1,%eax
jne    1200 <main+0x80>
mov    %r14,%rdi
call   10a0 <uart_puts@plt>
mov    %ebx,%edi
mov    $0xa,%esi
xor    %edx,%edx
call   1040 <uart_print_num@plt>
mov    $0xa,%edi
call   1050 <uart_putchar@plt>
mov    $0x1,%edi
mov    $0x3,%esi
call   1080 <build_header@plt>
jmp    1207 <main+0x87>
nopw   0x0(%rax,%rax,1)
mov    %ebp,%edi
call   1070 <get_flit_payload@plt>
mov    %eax,0x7ffc
add    $0x1,%ebx
jmp    120e <main+0x8e>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    0x7ffc,%edi
call   1030 <get_flit_type@plt>
cmpl   $0x0,0x8000
jns    1290 <main+0x110>
xor    %eax,%eax
call   1090 <test_plasma_funcitons@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [58 x i8] c"UART TEST: If you can read this, then UART output works!\0A\00"
@.str.1 = [33 x i8] c"\0A\0ABeginning communication test\0A\0A\00"
@.str.2 = [23 x i8] c"Sending packet number \00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %9
%11 = call i32 @setup_uart(i32 25000000, i32 57600)
%12 = call i32 @uart_puts(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str, i64 0, i64 0))
%13 = load volatile i32, i32* inttoptr (i64 536870992 to i32*)
store i32 %13, i32* %10
%14 = load i32, i32* %10
store volatile i32 %14, i32* inttoptr (i64 536870960 to i32*)
%15 = call i32 @uart_puts(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
%16 = call i32 @build_header(i32 1, i32 3)
store volatile i32 %16, i32* inttoptr (i64 32764 to i32*)
store volatile i32 268435455, i32* inttoptr (i64 32764 to i32*)
store volatile i32 0, i32* inttoptr (i64 32764 to i32*)
br label %17
17: ; preds = %51, %2
%18 = load i32, i32* %9
%19 = icmp ule i32 %18, 100
br i1 %19, label %20, label %52
20: ; preds = %17
%21 = load volatile i32, i32* inttoptr (i64 32768 to i32*)
%22 = and i32 %21, -2147483648
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %51
24: ; preds = %20
%25 = load volatile i32, i32* inttoptr (i64 32764 to i32*)
store i32 %25, i32* %6
%26 = load i32, i32* %6
%27 = call i32 @get_flit_type(i32 %26)
store i32 %27, i32* %7
%28 = load i32, i32* %7
%29 = icmp eq i32 %28, 1
br i1 %29, label %30, label %36
30: ; preds = %24
%31 = call i32 @uart_puts(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%32 = load i32, i32* %9
%33 = call i32 @uart_print_num(i32 %32, i32 10, i32 0)
%34 = call i32 @uart_putchar(i8 signext 10)
%35 = call i32 @build_header(i32 1, i32 3)
store volatile i32 %35, i32* inttoptr (i64 32764 to i32*)
br label %50
36: ; preds = %24
%37 = load i32, i32* %7
%38 = icmp eq i32 %37, 4
br i1 %38, label %39, label %45
39: ; preds = %36
%40 = load i32, i32* %6
%41 = call i32 @get_flit_payload(i32 %40)
store i32 %41, i32* %8
%42 = load i32, i32* %8
store volatile i32 %42, i32* inttoptr (i64 32764 to i32*)
%43 = load i32, i32* %9
%44 = add i32 %43, 1
store i32 %44, i32* %9
br label %49
45: ; preds = %36
%46 = load i32, i32* %6
%47 = call i32 @get_flit_payload(i32 %46)
store i32 %47, i32* %8
%48 = load i32, i32* %8
store volatile i32 %48, i32* inttoptr (i64 32764 to i32*)
br label %49
49: ; preds = %45, %39
br label %50
50: ; preds = %49, %30
br label %51
51: ; preds = %50, %20
br label %17
52: ; preds = %17
br label %53
53: ; preds = %57, %52
%54 = load volatile i32, i32* inttoptr (i64 32768 to i32*)
%55 = and i32 %54, -2147483648
%56 = icmp eq i32 %55, 0
br i1 %56, label %57, label %63
57: ; preds = %53
%58 = load volatile i32, i32* inttoptr (i64 32764 to i32*)
store i32 %58, i32* %6
%59 = load i32, i32* %6
%60 = call i32 @get_flit_type(i32 %59)
store i32 %60, i32* %7
%61 = load i32, i32* %9
%62 = add i32 %61, 1
store i32 %62, i32* %9
br label %53
63: ; preds = %53
%64 = call i32 (...) @test_plasma_funcitons()
ret i32 0
}

LLVM IR (-O2):
@.str = [58 x i8] c"UART TEST: If you can read this, then UART output works!\0A\00"
@.str.1 = [33 x i8] c"\0A\0ABeginning communication test\0A\0A\00"
@.str.2 = [23 x i8] c"Sending packet number \00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 @setup_uart(i32 25000000, i32 57600)
%4 = tail call i32 @uart_puts(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str, i64 0, i64 0))
%5 = load volatile i32, i32* inttoptr (i64 536870992 to i32*)
store volatile i32 %5, i32* inttoptr (i64 536870960 to i32*)
%6 = tail call i32 @uart_puts(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
%7 = tail call i32 @build_header(i32 1, i32 3)
store volatile i32 %7, i32* inttoptr (i64 32764 to i32*)
store volatile i32 268435455, i32* inttoptr (i64 32764 to i32*)
store volatile i32 0, i32* inttoptr (i64 32764 to i32*)
br label %11
8: ; preds = %28
%9 = load volatile i32, i32* inttoptr (i64 32768 to i32*)
%10 = icmp sgt i32 %9, -1
br i1 %10, label %31, label %36
11: ; preds = %2, %28
%12 = phi i32 [ 1, %2 ], [ %29, %28 ]
%13 = load volatile i32, i32* inttoptr (i64 32768 to i32*)
%14 = icmp sgt i32 %13, -1
br i1 %14, label %15, label %28
15: ; preds = %11
%16 = load volatile i32, i32* inttoptr (i64 32764 to i32*)
%17 = tail call i32 @get_flit_type(i32 %16)
switch i32 %17, label %26 [
i32 1, label %18
i32 4, label %23
]
18: ; preds = %15
%19 = tail call i32 @uart_puts(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%20 = tail call i32 @uart_print_num(i32 %12, i32 10, i32 0)
%21 = tail call i32 @uart_putchar(i8 signext 10)
%22 = tail call i32 @build_header(i32 1, i32 3)
store volatile i32 %22, i32* inttoptr (i64 32764 to i32*)
br label %28
23: ; preds = %15
%24 = tail call i32 @get_flit_payload(i32 %16)
store volatile i32 %24, i32* inttoptr (i64 32764 to i32*)
%25 = add nuw nsw i32 %12, 1
br label %28
26: ; preds = %15
%27 = tail call i32 @get_flit_payload(i32 %16)
store volatile i32 %27, i32* inttoptr (i64 32764 to i32*)
br label %28
28: ; preds = %18, %26, %23, %11
%29 = phi i32 [ %12, %18 ], [ %25, %23 ], [ %12, %26 ], [ %12, %11 ]
%30 = icmp ult i32 %29, 101
br i1 %30, label %11, label %8
31: ; preds = %8, %31
%32 = load volatile i32, i32* inttoptr (i64 32764 to i32*)
%33 = tail call i32 @get_flit_type(i32 %32)
%34 = load volatile i32, i32* inttoptr (i64 32768 to i32*)
%35 = icmp sgt i32 %34, -1
br i1 %35, label %31, label %36
36: ; preds = %31, %8
%37 = tail call i32 (...) @test_plasma_funcitons()
ret i32 0
}