#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(unsigned int, int);
int /*<<< orphan*/ setup_uart(int, int);
int /*<<< orphan*/ test_plasma_funcitons();
int /*<<< orphan*/ uart_puts(char *);
int main(int argc, char const *argv[]) {
  unsigned destination = 0;
  unsigned flit_number = 0;
  unsigned flit;
  unsigned packet_counter = 0;
  setup_uart(10, 1);
  uart_puts("UART TEST: If you can read this, then UART output works!\n");
  (*(volatile unsigned int *)0x7FFCu = (build_header(0, 6)));
  (*(volatile unsigned int *)0x7FFCu = (0b0000010101000101000001001001));
  (*(volatile unsigned int *)0x7FFCu = (1));
  (*(volatile unsigned int *)0x7FFCu = (1));
  (*(volatile unsigned int *)0x7FFCu = (1));
  (*(volatile unsigned int *)0x7FFCu = (1));
  while (1) {
    if (((*(volatile unsigned int *)0x8000u) & 0x80000000) == 0) {
      flit = (*(volatile unsigned int *)0x7FFCu);
    } else if (((*(volatile unsigned int *)0x8000u) & 0x40000000) == 0 &&
               packet_counter < 100) {
      flit_number++;
      if (flit_number == 1) {
        (*(volatile unsigned int *)0x7FFCu = (build_header(destination, 3)));
        destination++;
        if (destination == 3) {
          destination++;
        }
        if (destination == 4) {
          destination = 0;
        }
      } else if (flit_number == 3) {
        (*(volatile unsigned int *)0x7FFCu = (0));
        flit_number = 0;
        packet_counter++;
      } else {
        (*(volatile unsigned int *)0x7FFCu = (0b1111111111111111111111111111));
      }
    }
    if (packet_counter >= 100) {
      while (((*(volatile unsigned int *)0x8000u) & 0x80000000) == 0) {
        flit = (*(volatile unsigned int *)0x7FFCu);
      }
      uart_puts("finished sending packets!\n");
      break;
    }
  }
  test_plasma_funcitons();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
mov    $0xa,%edi
mov    $0x1,%esi
call   1030 <setup_uart@plt>
lea    0xe7f(%rip),%rdi
call   1060 <uart_puts@plt>
xor    %edi,%edi
mov    $0x6,%esi
call   1040 <build_header@plt>
mov    %eax,%ecx
mov    $0x7ffc,%eax
mov    %ecx,(%rax)
mov    $0x7ffc,%eax
movl   $0x545049,(%rax)
mov    $0x7ffc,%eax
movl   $0x1,(%rax)
mov    $0x7ffc,%eax
movl   $0x1,(%rax)
mov    $0x7ffc,%eax
movl   $0x1,(%rax)
mov    $0x7ffc,%eax
movl   $0x1,(%rax)
mov    $0x8000,%eax
mov    (%rax),%eax
and    $0x80000000,%eax
cmp    $0x0,%eax
jne    11f6 <main+0xb6>
mov    $0x7ffc,%eax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
jmp    12b4 <main+0x174>
mov    $0x8000,%eax
mov    (%rax),%eax
and    $0x40000000,%eax
cmp    $0x0,%eax
jne    12af <main+0x16f>
cmpl   $0x64,-0x20(%rbp)
jae    12af <main+0x16f>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x1,-0x18(%rbp)
jne    1270 <main+0x130>
mov    -0x14(%rbp),%edi
mov    $0x3,%esi
call   1040 <build_header@plt>
mov    %eax,%ecx
mov    $0x7ffc,%eax
mov    %ecx,(%rax)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x3,-0x14(%rbp)
jne    125a <main+0x11a>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x4,-0x14(%rbp)
jne    126b <main+0x12b>
movl   $0x0,-0x14(%rbp)
jmp    12aa <main+0x16a>
cmpl   $0x3,-0x18(%rbp)
jne    129a <main+0x15a>
mov    $0x7ffc,%eax
movl   $0x0,(%rax)
movl   $0x0,-0x18(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    12a5 <main+0x165>
mov    $0x7ffc,%eax
movl   $0xfffffff,(%rax)
jmp    12aa <main+0x16a>
jmp    12af <main+0x16f>
jmp    12b4 <main+0x174>
cmpl   $0x64,-0x20(%rbp)
jb     12f8 <main+0x1b8>
jmp    12c3 <main+0x183>
mov    $0x8000,%eax
mov    (%rax),%eax
and    $0x80000000,%eax
cmp    $0x0,%eax
jne    12e7 <main+0x1a7>
mov    $0x7ffc,%eax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
jmp    12c3 <main+0x183>
lea    0xd4c(%rip),%rdi
call   1060 <uart_puts@plt>
jmp    12fd <main+0x1bd>
jmp    11d2 <main+0x92>
mov    $0x0,%al
call   1050 <test_plasma_funcitons@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    $0xa,%edi
mov    $0x1,%esi
call   1030 <setup_uart@plt>
lea    0xea3(%rip),%rdi
call   1060 <uart_puts@plt>
xor    %r14d,%r14d
xor    %edi,%edi
mov    $0x6,%esi
call   1040 <build_header@plt>
mov    %eax,0x7ffc
movl   $0x545049,0x7ffc
movl   $0x1,0x7ffc
movl   $0x1,0x7ffc
movl   $0x1,0x7ffc
movl   $0x1,0x7ffc
mov    $0x4,%r15d
xor    %ebx,%ebx
xor    %eax,%eax
xor    %ebp,%ebp
jmp    11cc <main+0x8c>
nopl   (%rax)
mov    0x7ffc,%ecx
cmp    $0x64,%ebp
jae    1247 <main+0x107>
cmpl   $0x0,0x8000
jns    11c0 <main+0x80>
testl  $0x40000000,0x8000
jne    11c7 <main+0x87>
test   %eax,%eax
je     11fc <main+0xbc>
add    $0x1,%eax
cmp    $0x3,%eax
je     1227 <main+0xe7>
movl   $0xfffffff,0x7ffc
ff ff ff 0f
jmp    11c7 <main+0x87>
mov    %ebx,%edi
mov    $0x3,%esi
call   1040 <build_header@plt>
mov    %eax,0x7ffc
add    $0x1,%ebx
cmp    $0x3,%ebx
cmove  %r15d,%ebx
cmp    $0x4,%ebx
cmove  %r14d,%ebx
mov    $0x1,%eax
jmp    11c7 <main+0x87>
movl   $0x0,0x7ffc
add    $0x1,%ebp
xor    %eax,%eax
jmp    11c7 <main+0x87>
nopl   0x0(%rax)
mov    0x7ffc,%eax
cmpl   $0x0,0x8000
jns    1240 <main+0x100>
lea    0xde2(%rip),%rdi
call   1060 <uart_puts@plt>
xor    %eax,%eax
call   1050 <test_plasma_funcitons@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
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 = [27 x i8] c"finished sending packets!\0A\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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i32 0, i32* %7
store i32 0, i32* %9
%10 = call i32 @setup_uart(i32 10, i32 1)
%11 = call i32 @uart_puts(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @build_header(i32 0, i32 6)
store volatile i32 %12, i32* inttoptr (i64 32764 to i32*)
store volatile i32 5525577, i32* inttoptr (i64 32764 to i32*)
store volatile i32 1, i32* inttoptr (i64 32764 to i32*)
store volatile i32 1, i32* inttoptr (i64 32764 to i32*)
store volatile i32 1, i32* inttoptr (i64 32764 to i32*)
store volatile i32 1, i32* inttoptr (i64 32764 to i32*)
br label %13
13: ; preds = %2, %68
%14 = load volatile i32, i32* inttoptr (i64 32768 to i32*)
%15 = and i32 %14, -2147483648
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %13
%18 = load volatile i32, i32* inttoptr (i64 32764 to i32*)
store i32 %18, i32* %8
br label %56
19: ; preds = %13
%20 = load volatile i32, i32* inttoptr (i64 32768 to i32*)
%21 = and i32 %20, 1073741824
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %55
23: ; preds = %19
%24 = load i32, i32* %9
%25 = icmp ult i32 %24, 100
br i1 %25, label %26, label %55
26: ; preds = %23
%27 = load i32, i32* %7
%28 = add i32 %27, 1
store i32 %28, i32* %7
%29 = load i32, i32* %7
%30 = icmp eq i32 %29, 1
br i1 %30, label %31, label %46
31: ; preds = %26
%32 = load i32, i32* %6
%33 = call i32 @build_header(i32 %32, i32 3)
store volatile i32 %33, i32* inttoptr (i64 32764 to i32*)
%34 = load i32, i32* %6
%35 = add i32 %34, 1
store i32 %35, i32* %6
%36 = load i32, i32* %6
%37 = icmp eq i32 %36, 3
br i1 %37, label %38, label %41
38: ; preds = %31
%39 = load i32, i32* %6
%40 = add i32 %39, 1
store i32 %40, i32* %6
br label %41
41: ; preds = %38, %31
%42 = load i32, i32* %6
%43 = icmp eq i32 %42, 4
br i1 %43, label %44, label %45
44: ; preds = %41
store i32 0, i32* %6
br label %45
45: ; preds = %44, %41
br label %54
46: ; preds = %26
%47 = load i32, i32* %7
%48 = icmp eq i32 %47, 3
br i1 %48, label %49, label %52
49: ; preds = %46
store volatile i32 0, i32* inttoptr (i64 32764 to i32*)
store i32 0, i32* %7
%50 = load i32, i32* %9
%51 = add i32 %50, 1
store i32 %51, i32* %9
br label %53
52: ; preds = %46
store volatile i32 268435455, i32* inttoptr (i64 32764 to i32*)
br label %53
53: ; preds = %52, %49
br label %54
54: ; preds = %53, %45
br label %55
55: ; preds = %54, %23, %19
br label %56
56: ; preds = %55, %17
%57 = load i32, i32* %9
%58 = icmp uge i32 %57, 100
br i1 %58, label %59, label %68
59: ; preds = %56
br label %60
60: ; preds = %64, %59
%61 = load volatile i32, i32* inttoptr (i64 32768 to i32*)
%62 = and i32 %61, -2147483648
%63 = icmp eq i32 %62, 0
br i1 %63, label %64, label %66
64: ; preds = %60
%65 = load volatile i32, i32* inttoptr (i64 32764 to i32*)
store i32 %65, i32* %8
br label %60
66: ; preds = %60
%67 = call i32 @uart_puts(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
br label %69
68: ; preds = %56
br label %13
69: ; preds = %66
%70 = 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 = [27 x i8] c"finished sending packets!\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 @setup_uart(i32 10, i32 1)
%4 = tail call i32 @uart_puts(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32 @build_header(i32 0, i32 6)
store volatile i32 %5, i32* inttoptr (i64 32764 to i32*)
store volatile i32 5525577, i32* inttoptr (i64 32764 to i32*)
store volatile i32 1, i32* inttoptr (i64 32764 to i32*)
store volatile i32 1, i32* inttoptr (i64 32764 to i32*)
store volatile i32 1, i32* inttoptr (i64 32764 to i32*)
store volatile i32 1, i32* inttoptr (i64 32764 to i32*)
br label %6
6: ; preds = %33, %2
%7 = phi i32 [ 0, %2 ], [ %34, %33 ]
%8 = phi i32 [ 0, %2 ], [ %35, %33 ]
%9 = phi i32 [ 0, %2 ], [ %36, %33 ]
%10 = load volatile i32, i32* inttoptr (i64 32768 to i32*)
%11 = icmp sgt i32 %10, -1
br i1 %11, label %12, label %14
12: ; preds = %6
%13 = load volatile i32, i32* inttoptr (i64 32764 to i32*)
br label %33
14: ; preds = %6
%15 = load volatile i32, i32* inttoptr (i64 32768 to i32*)
%16 = and i32 %15, 1073741824
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %33
18: ; preds = %14
%19 = add i32 %8, 1
%20 = icmp eq i32 %8, 0
br i1 %20, label %21, label %28
21: ; preds = %18
%22 = tail call i32 @build_header(i32 %7, i32 3)
store volatile i32 %22, i32* inttoptr (i64 32764 to i32*)
%23 = add i32 %7, 1
%24 = icmp eq i32 %23, 3
%25 = select i1 %24, i32 4, i32 %23
%26 = icmp eq i32 %25, 4
%27 = select i1 %26, i32 0, i32 %25
br label %33
28: ; preds = %18
%29 = icmp eq i32 %19, 3
br i1 %29, label %30, label %32
30: ; preds = %28
store volatile i32 0, i32* inttoptr (i64 32764 to i32*)
%31 = add nuw nsw i32 %9, 1
br label %33
32: ; preds = %28
store volatile i32 268435455, i32* inttoptr (i64 32764 to i32*)
br label %33
33: ; preds = %14, %30, %32, %21, %12
%34 = phi i32 [ %7, %12 ], [ %27, %21 ], [ %7, %30 ], [ %7, %32 ], [ %7, %14 ]
%35 = phi i32 [ %8, %12 ], [ 1, %21 ], [ 0, %30 ], [ %19, %32 ], [ %8, %14 ]
%36 = phi i32 [ %9, %12 ], [ %9, %21 ], [ %31, %30 ], [ %9, %32 ], [ %9, %14 ]
%37 = icmp ugt i32 %36, 99
br i1 %37, label %38, label %6
38: ; preds = %33
%39 = load volatile i32, i32* inttoptr (i64 32768 to i32*)
%40 = icmp sgt i32 %39, -1
br i1 %40, label %41, label %45
41: ; preds = %38, %41
%42 = load volatile i32, i32* inttoptr (i64 32764 to i32*)
%43 = load volatile i32, i32* inttoptr (i64 32768 to i32*)
%44 = icmp sgt i32 %43, -1
br i1 %44, label %41, label %45
45: ; preds = %41, %38
%46 = tail call i32 @uart_puts(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
%47 = tail call i32 (...) @test_plasma_funcitons()
ret i32 0
}