#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 */
int /*<<< orphan*/ check_serial_input();
int /*<<< orphan*/ set_leds(unsigned int);
void serial_out(unsigned ch) {
  check_serial_input();
  if (ch == '\n')
    serial_out('\r');
  check_serial_input();
  while ((*(volatile unsigned *)0xFF000000 != 0)) {
    set_leds(0);
    check_serial_input();
  }
  (*(volatile unsigned *)0xFF000000 = (ch));
  set_leds(ch);
}


x86 assembly (clang, -O0):
<serial_out>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x0,%al
call   1050 <check_serial_input@plt>
cmpl   $0xa,-0x4(%rbp)
jne    1156 <serial_out+0x26>
mov    $0xd,%edi
call   1030 <serial_out@plt>
mov    $0x0,%al
call   1050 <check_serial_input@plt>
mov    $0xff000000,%eax
mov    (%rax),%eax
cmp    $0x0,%eax
je     1180 <serial_out+0x50>
xor    %edi,%edi
call   1040 <set_leds@plt>
mov    $0x0,%al
call   1050 <check_serial_input@plt>
jmp    115d <serial_out+0x2d>
mov    -0x4(%rbp),%ecx
mov    $0xff000000,%eax
mov    %ecx,(%rax)
mov    -0x4(%rbp),%edi
call   1040 <set_leds@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<serial_out>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
mov    $0xff000000,%ebx
xor    %eax,%eax
call   1040 <check_serial_input@plt>
cmp    $0xa,%ebp
jne    1169 <serial_out+0x49>
xor    %eax,%eax
call   1040 <check_serial_input@plt>
nopl   (%rax)
xor    %eax,%eax
call   1040 <check_serial_input@plt>
cmpl   $0x0,(%rbx)
je     1155 <serial_out+0x35>
xor    %edi,%edi
call   1030 <set_leds@plt>
jmp    1140 <serial_out+0x20>
movl   $0xd,(%rbx)
mov    $0xd,%edi
jmp    1164 <serial_out+0x44>
xor    %edi,%edi
call   1030 <set_leds@plt>
xor    %eax,%eax
call   1040 <check_serial_input@plt>
cmpl   $0x0,(%rbx)
jne    1162 <serial_out+0x42>
mov    %ebp,(%rbx)
mov    %ebp,%edi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <set_leds@plt>

LLVM IR (-O0):
define void @serial_out(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = call i32 (...) @check_serial_input()
%4 = load i32, i32* %2
%5 = icmp eq i32 %4, 10
br i1 %5, label %6, label %7
6: ; preds = %1
br label %7
7: ; preds = %6, %1
%8 = call i32 (...) @check_serial_input()
br label %9
9: ; preds = %12, %7
%10 = load volatile i32, i32* inttoptr (i64 4278190080 to i32*)
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %9
%13 = call i32 @set_leds(i32 0)
%14 = call i32 (...) @check_serial_input()
br label %9
15: ; preds = %9
%16 = load i32, i32* %2
store volatile i32 %16, i32* inttoptr (i64 4278190080 to i32*)
%17 = load i32, i32* %2
%18 = call i32 @set_leds(i32 %17)
ret void
}

LLVM IR (-O2):
define void @serial_out(i32 %0) {
%2 = tail call i32 (...) @check_serial_input()
%3 = icmp eq i32 %0, 10
br i1 %3, label %4, label %16
4: ; preds = %1
%5 = tail call i32 (...) @check_serial_input()
%6 = tail call i32 (...) @check_serial_input()
%7 = load volatile i32, i32* inttoptr (i64 4278190080 to i32*)
%8 = icmp eq i32 %7, 0
br i1 %8, label %14, label %9
9: ; preds = %4, %9
%10 = tail call i32 @set_leds(i32 0)
%11 = tail call i32 (...) @check_serial_input()
%12 = load volatile i32, i32* inttoptr (i64 4278190080 to i32*)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %9
14: ; preds = %9, %4
store volatile i32 13, i32* inttoptr (i64 4278190080 to i32*)
%15 = tail call i32 @set_leds(i32 13)
br label %16
16: ; preds = %14, %1
%17 = tail call i32 (...) @check_serial_input()
%18 = load volatile i32, i32* inttoptr (i64 4278190080 to i32*)
%19 = icmp eq i32 %18, 0
br i1 %19, label %25, label %20
20: ; preds = %16, %20
%21 = tail call i32 @set_leds(i32 0)
%22 = tail call i32 (...) @check_serial_input()
%23 = load volatile i32, i32* inttoptr (i64 4278190080 to i32*)
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %20
25: ; preds = %20, %16
store volatile i32 %0, i32* inttoptr (i64 4278190080 to i32*)
%26 = tail call i32 @set_leds(i32 %0)
ret void
}