#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");
  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 == 1) {
          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>
mov    $0x8000,%eax
mov    (%rax),%eax
and    $0x80000000,%eax
cmp    $0x0,%eax
jne    11aa <main+0x6a>
mov    $0x7ffc,%eax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
jmp    1268 <main+0x128>
mov    $0x8000,%eax
mov    (%rax),%eax
and    $0x40000000,%eax
cmp    $0x0,%eax
jne    1263 <main+0x123>
cmpl   $0x64,-0x20(%rbp)
jae    1263 <main+0x123>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x1,-0x18(%rbp)
jne    1224 <main+0xe4>
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   $0x1,-0x14(%rbp)
jne    120e <main+0xce>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x4,-0x14(%rbp)
jne    121f <main+0xdf>
movl   $0x0,-0x14(%rbp)
jmp    125e <main+0x11e>
cmpl   $0x3,-0x18(%rbp)
jne    124e <main+0x10e>
mov    $0x7ffc,%eax
movl   $0x0,(%rax)
movl   $0x0,-0x18(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1259 <main+0x119>
mov    $0x7ffc,%eax
movl   $0xfffffff,(%rax)
jmp    125e <main+0x11e>
jmp    1263 <main+0x123>
jmp    1268 <main+0x128>
cmpl   $0x64,-0x20(%rbp)
jb     12ac <main+0x16c>
jmp    1277 <main+0x137>
mov    $0x8000,%eax
mov    (%rax),%eax
and    $0x80000000,%eax
cmp    $0x0,%eax
jne    129b <main+0x15b>
mov    $0x7ffc,%eax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
jmp    1277 <main+0x137>
lea    0xd98(%rip),%rdi
call   1060 <uart_puts@plt>
jmp    12b1 <main+0x171>
jmp    1186 <main+0x46>
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
mov    $0x2,%r15d
xor    %ebx,%ebx
xor    %eax,%eax
xor    %ebp,%ebp
jmp    118c <main+0x4c>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    0x7ffc,%ecx
cmp    $0x64,%ebp
jae    1207 <main+0xc7>
cmpl   $0x0,0x8000
jns    1180 <main+0x40>
testl  $0x40000000,0x8000
jne    1187 <main+0x47>
test   %eax,%eax
je     11bc <main+0x7c>
add    $0x1,%eax
cmp    $0x3,%eax
je     11e8 <main+0xa8>
movl   $0xfffffff,0x7ffc
ff ff ff 0f
jmp    1187 <main+0x47>
mov    %ebx,%edi
mov    $0x3,%esi
call   1040 <build_header@plt>
mov    %eax,0x7ffc
test   %ebx,%ebx
lea    0x1(%rbx),%ecx
cmove  %r15d,%ecx
cmp    $0x4,%ecx
cmove  %r14d,%ecx
mov    $0x1,%eax
mov    %ecx,%ebx
jmp    1187 <main+0x47>
movl   $0x0,0x7ffc
add    $0x1,%ebp
xor    %eax,%eax
jmp    1187 <main+0x47>
nopw   0x0(%rax,%rax,1)
mov    0x7ffc,%eax
cmpl   $0x0,0x8000
jns    1200 <main+0xc0>
lea    0xe22(%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))
br label %12
12: ; preds = %2, %67
%13 = load volatile i32, i32* inttoptr (i64 32768 to i32*)
%14 = and i32 %13, -2147483648
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %12
%17 = load volatile i32, i32* inttoptr (i64 32764 to i32*)
store i32 %17, i32* %8
br label %55
18: ; preds = %12
%19 = load volatile i32, i32* inttoptr (i64 32768 to i32*)
%20 = and i32 %19, 1073741824
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %54
22: ; preds = %18
%23 = load i32, i32* %9
%24 = icmp ult i32 %23, 100
br i1 %24, label %25, label %54
25: ; preds = %22
%26 = load i32, i32* %7
%27 = add i32 %26, 1
store i32 %27, i32* %7
%28 = load i32, i32* %7
%29 = icmp eq i32 %28, 1
br i1 %29, label %30, label %45
30: ; preds = %25
%31 = load i32, i32* %6
%32 = call i32 @build_header(i32 %31, i32 3)
store volatile i32 %32, i32* inttoptr (i64 32764 to i32*)
%33 = load i32, i32* %6
%34 = add i32 %33, 1
store i32 %34, i32* %6
%35 = load i32, i32* %6
%36 = icmp eq i32 %35, 1
br i1 %36, label %37, label %40
37: ; preds = %30
%38 = load i32, i32* %6
%39 = add i32 %38, 1
store i32 %39, i32* %6
br label %40
40: ; preds = %37, %30
%41 = load i32, i32* %6
%42 = icmp eq i32 %41, 4
br i1 %42, label %43, label %44
43: ; preds = %40
store i32 0, i32* %6
br label %44
44: ; preds = %43, %40
br label %53
45: ; preds = %25
%46 = load i32, i32* %7
%47 = icmp eq i32 %46, 3
br i1 %47, label %48, label %51
48: ; preds = %45
store volatile i32 0, i32* inttoptr (i64 32764 to i32*)
store i32 0, i32* %7
%49 = load i32, i32* %9
%50 = add i32 %49, 1
store i32 %50, i32* %9
br label %52
51: ; preds = %45
store volatile i32 268435455, i32* inttoptr (i64 32764 to i32*)
br label %52
52: ; preds = %51, %48
br label %53
53: ; preds = %52, %44
br label %54
54: ; preds = %53, %22, %18
br label %55
55: ; preds = %54, %16
%56 = load i32, i32* %9
%57 = icmp uge i32 %56, 100
br i1 %57, label %58, label %67
58: ; preds = %55
br label %59
59: ; preds = %63, %58
%60 = load volatile i32, i32* inttoptr (i64 32768 to i32*)
%61 = and i32 %60, -2147483648
%62 = icmp eq i32 %61, 0
br i1 %62, label %63, label %65
63: ; preds = %59
%64 = load volatile i32, i32* inttoptr (i64 32764 to i32*)
store i32 %64, i32* %8
br label %59
65: ; preds = %59
%66 = call i32 @uart_puts(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
br label %68
67: ; preds = %55
br label %12
68: ; preds = %65
%69 = 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))
br label %5
5: ; preds = %32, %2
%6 = phi i32 [ 0, %2 ], [ %33, %32 ]
%7 = phi i32 [ 0, %2 ], [ %34, %32 ]
%8 = phi i32 [ 0, %2 ], [ %35, %32 ]
%9 = load volatile i32, i32* inttoptr (i64 32768 to i32*)
%10 = icmp sgt i32 %9, -1
br i1 %10, label %11, label %13
11: ; preds = %5
%12 = load volatile i32, i32* inttoptr (i64 32764 to i32*)
br label %32
13: ; preds = %5
%14 = load volatile i32, i32* inttoptr (i64 32768 to i32*)
%15 = and i32 %14, 1073741824
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %32
17: ; preds = %13
%18 = add i32 %7, 1
%19 = icmp eq i32 %7, 0
br i1 %19, label %20, label %27
20: ; preds = %17
%21 = tail call i32 @build_header(i32 %6, i32 3)
store volatile i32 %21, i32* inttoptr (i64 32764 to i32*)
%22 = add i32 %6, 1
%23 = icmp eq i32 %6, 0
%24 = select i1 %23, i32 2, i32 %22
%25 = icmp eq i32 %24, 4
%26 = select i1 %25, i32 0, i32 %24
br label %32
27: ; preds = %17
%28 = icmp eq i32 %18, 3
br i1 %28, label %29, label %31
29: ; preds = %27
store volatile i32 0, i32* inttoptr (i64 32764 to i32*)
%30 = add nuw nsw i32 %8, 1
br label %32
31: ; preds = %27
store volatile i32 268435455, i32* inttoptr (i64 32764 to i32*)
br label %32
32: ; preds = %13, %29, %31, %20, %11
%33 = phi i32 [ %6, %11 ], [ %26, %20 ], [ %6, %29 ], [ %6, %31 ], [ %6, %13 ]
%34 = phi i32 [ %7, %11 ], [ 1, %20 ], [ 0, %29 ], [ %18, %31 ], [ %7, %13 ]
%35 = phi i32 [ %8, %11 ], [ %8, %20 ], [ %30, %29 ], [ %8, %31 ], [ %8, %13 ]
%36 = icmp ugt i32 %35, 99
br i1 %36, label %37, label %5
37: ; preds = %32
%38 = load volatile i32, i32* inttoptr (i64 32768 to i32*)
%39 = icmp sgt i32 %38, -1
br i1 %39, label %40, label %44
40: ; preds = %37, %40
%41 = load volatile i32, i32* inttoptr (i64 32764 to i32*)
%42 = load volatile i32, i32* inttoptr (i64 32768 to i32*)
%43 = icmp sgt i32 %42, -1
br i1 %43, label %40, label %44
44: ; preds = %40, %37
%45 = tail call i32 @uart_puts(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
%46 = tail call i32 (...) @test_plasma_funcitons()
ret i32 0
}