#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(2, 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(2, 3)));
        packet_counter++;
      } else {
        payload = get_flit_payload(flit);
        (*(volatile unsigned int *)0x7FFCu = (payload));
      }
    }
  }
  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    $0x2,%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     12ae <main+0x12e>
mov    $0x8000,%eax
mov    (%rax),%eax
and    $0x80000000,%eax
cmp    $0x0,%eax
jne    12a9 <main+0x129>
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    128f <main+0x10f>
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    $0x2,%edi
mov    $0x3,%esi
call   1080 <build_header@plt>
mov    %eax,%ecx
mov    $0x7ffc,%eax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    12a4 <main+0x124>
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    12a9 <main+0x129>
jmp    1206 <main+0x86>
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    $0x2,%edi
mov    $0x3,%esi
call   1080 <build_header@plt>
mov    %eax,0x7ffc
movl   $0xfffffff,0x7ffc
ff ff ff 0f
movl   $0x0,0x7ffc
mov    $0x1,%ebx
lea    0xe6a(%rip),%r14
jmp    1213 <main+0x93>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %ebp,%edi
call   1070 <get_flit_payload@plt>
mov    %eax,0x7ffc
cmp    $0x65,%ebx
jae    126b <main+0xeb>
cmpl   $0x0,0x8000
js     120e <main+0x8e>
mov    0x7ffc,%ebp
mov    %ebp,%edi
call   1030 <get_flit_type@plt>
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    $0x2,%edi
mov    $0x3,%esi
call   1080 <build_header@plt>
mov    %eax,0x7ffc
add    $0x1,%ebx
jmp    120e <main+0x8e>
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 2, 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 = %43, %2
%18 = load i32, i32* %9
%19 = icmp ule i32 %18, 100
br i1 %19, label %20, label %44
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 %43
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 %38
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 2, i32 3)
store volatile i32 %35, i32* inttoptr (i64 32764 to i32*)
%36 = load i32, i32* %9
%37 = add i32 %36, 1
store i32 %37, i32* %9
br label %42
38: ; preds = %24
%39 = load i32, i32* %6
%40 = call i32 @get_flit_payload(i32 %39)
store i32 %40, i32* %8
%41 = load i32, i32* %8
store volatile i32 %41, i32* inttoptr (i64 32764 to i32*)
br label %42
42: ; preds = %38, %30
br label %43
43: ; preds = %42, %20
br label %17
44: ; preds = %17
%45 = 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 2, 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 %8
8: ; preds = %2, %24
%9 = phi i32 [ 1, %2 ], [ %25, %24 ]
%10 = load volatile i32, i32* inttoptr (i64 32768 to i32*)
%11 = icmp sgt i32 %10, -1
br i1 %11, label %12, label %24
12: ; preds = %8
%13 = load volatile i32, i32* inttoptr (i64 32764 to i32*)
%14 = tail call i32 @get_flit_type(i32 %13)
%15 = icmp eq i32 %14, 1
br i1 %15, label %16, label %22
16: ; preds = %12
%17 = tail call i32 @uart_puts(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%18 = tail call i32 @uart_print_num(i32 %9, i32 10, i32 0)
%19 = tail call i32 @uart_putchar(i8 signext 10)
%20 = tail call i32 @build_header(i32 2, i32 3)
store volatile i32 %20, i32* inttoptr (i64 32764 to i32*)
%21 = add nuw nsw i32 %9, 1
br label %24
22: ; preds = %12
%23 = tail call i32 @get_flit_payload(i32 %13)
store volatile i32 %23, i32* inttoptr (i64 32764 to i32*)
br label %24
24: ; preds = %16, %22, %8
%25 = phi i32 [ %21, %16 ], [ %9, %22 ], [ %9, %8 ]
%26 = icmp ult i32 %25, 101
br i1 %26, label %8, label %27
27: ; preds = %24
%28 = tail call i32 (...) @test_plasma_funcitons()
ret i32 0
}