#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 */
typedef int /*<<< orphan*/ text;

/* Variables and functions */
int /*<<< orphan*/ CHECK(int, int, int, int, int /*<<< orphan*/, char *);
int /*<<< orphan*/ printf(char *);
int serial_close(int, int);
int serial_data_available(int, int);
int serial_open(int, char *, int, int /*<<< orphan*/);
int serial_read(int, int, char *, int);
int serial_read_byte(int, int);
int serial_write(int, int, char *, int);
int serial_write_byte(int, int, int);
int strcmp(char *, char *);
int strlen(char *);
int /*<<< orphan*/ time_sleep(double);
void ta(int pi) {
  int h, b, e;
  char *TEXT;
  char text[2048];
  printf("Serial link tests.\n");
  h = serial_open(pi, "/dev/ttyAMA0", 57600, 0);
  CHECK(10, 1, h, 0, 0, "serial open");
  time_sleep(0.1);
  b = serial_read(pi, h, text, sizeof(text));
  b = serial_data_available(pi, h);
  CHECK(10, 2, b, 0, 0, "serial data available");
  TEXT = "To be, or not to be, that is the question-Whether 'tis Nobler in the "
         "mind to sufferThe Slings and Arrows of outrageous Fortune,Or to take "
         "Arms against a Sea of troubles,";
  e = serial_write(pi, h, TEXT, strlen(TEXT));
  CHECK(10, 3, e, 0, 0, "serial write");
  e = serial_write_byte(pi, h, 0xAA);
  e = serial_write_byte(pi, h, 0x55);
  e = serial_write_byte(pi, h, 0x00);
  e = serial_write_byte(pi, h, 0xFF);
  CHECK(10, 4, e, 0, 0, "serial write byte");
  time_sleep(0.1);
  b = serial_data_available(pi, h);
  CHECK(10, 5, b, strlen(TEXT) + 4, 0, "serial data available");
  b = serial_read(pi, h, text, strlen(TEXT));
  CHECK(10, 6, b, strlen(TEXT), 0, "serial read");
  if (b >= 0)
    text[b] = 0;
  CHECK(10, 7, strcmp(TEXT, text), 0, 0, "serial read");
  b = serial_read_byte(pi, h);
  CHECK(10, 8, b, 0xAA, 0, "serial read byte");
  b = serial_read_byte(pi, h);
  CHECK(10, 9, b, 0x55, 0, "serial read byte");
  b = serial_read_byte(pi, h);
  CHECK(10, 10, b, 0x00, 0, "serial read byte");
  b = serial_read_byte(pi, h);
  CHECK(10, 11, b, 0xFF, 0, "serial read byte");
  b = serial_data_available(pi, h);
  CHECK(10, 12, b, 0, 0, "serial data availabe");
  e = serial_close(pi, h);
  CHECK(10, 13, e, 0, 0, "serial close");
}


x86 assembly (clang, -O0):
<ta>:
push   %rbp
mov    %rsp,%rbp
sub    $0x850,%rsp
mov    %edi,-0x4(%rbp)
lea    0xe33(%rip),%rdi
call   1050 <printf@plt>
mov    -0x4(%rbp),%edi
lea    0xe38(%rip),%rsi
mov    $0xe100,%edx
xor    %ecx,%ecx
call   1080 <serial_open@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edx
mov    $0xa,%edi
mov    $0x1,%esi
xor    %r8d,%r8d
lea    0xe1f(%rip),%r9
mov    %r8d,%ecx
call   1030 <CHECK@plt>
movsd  0xde6(%rip),%xmm0
call   10e0 <time_sleep@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
lea    -0x820(%rbp),%rdx
mov    $0x800,%ecx
call   10d0 <serial_read@plt>
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   10b0 <serial_data_available@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edx
mov    $0xa,%edi
mov    $0x2,%esi
xor    %r8d,%r8d
lea    0xdd7(%rip),%r9
mov    %r8d,%ecx
call   1030 <CHECK@plt>
lea    0xdde(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x850(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x84c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x848(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x850(%rbp),%edi
mov    -0x84c(%rbp),%esi
mov    -0x848(%rbp),%rdx
mov    %eax,%ecx
call   10c0 <serial_write@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%edx
mov    $0xa,%edi
mov    $0x3,%esi
xor    %r8d,%r8d
lea    0xe2a(%rip),%r9
mov    %r8d,%ecx
call   1030 <CHECK@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    $0xaa,%edx
call   10a0 <serial_write_byte@plt>
mov    %eax,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    $0x55,%edx
call   10a0 <serial_write_byte@plt>
mov    %eax,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
xor    %edx,%edx
call   10a0 <serial_write_byte@plt>
mov    %eax,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    $0xff,%edx
call   10a0 <serial_write_byte@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%edx
mov    $0xa,%edi
mov    $0x4,%esi
xor    %r8d,%r8d
lea    0xdcf(%rip),%r9
mov    %r8d,%ecx
call   1030 <CHECK@plt>
movsd  0xcbd(%rip),%xmm0
call   10e0 <time_sleep@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   10b0 <serial_data_available@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x83c(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x83c(%rbp),%edx
mov    %eax,%ecx
add    $0x4,%ecx
mov    $0xa,%edi
mov    $0x5,%esi
xor    %r8d,%r8d
lea    0xcae(%rip),%r9
call   1030 <CHECK@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x838(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x834(%rbp)
lea    -0x820(%rbp),%rax
mov    %rax,-0x830(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x838(%rbp),%edi
mov    -0x834(%rbp),%esi
mov    -0x830(%rbp),%rdx
mov    %eax,%ecx
call   10d0 <serial_read@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x824(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x824(%rbp),%edx
mov    %eax,%ecx
mov    $0xa,%edi
mov    $0x6,%esi
xor    %r8d,%r8d
lea    0xd14(%rip),%r9
call   1030 <CHECK@plt>
cmpl   $0x0,-0xc(%rbp)
jl     141b <ta+0x25b>
movslq -0xc(%rbp),%rax
movb   $0x0,-0x820(%rbp,%rax,1)
mov    -0x18(%rbp),%rdi
lea    -0x820(%rbp),%rsi
call   1060 <strcmp@plt>
mov    %eax,%edx
mov    $0xa,%edi
mov    $0x7,%esi
xor    %r8d,%r8d
lea    0xcd3(%rip),%r9
mov    %r8d,%ecx
call   1030 <CHECK@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1090 <serial_read_byte@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edx
mov    $0xa,%edi
mov    $0x8,%esi
mov    $0xaa,%ecx
xor    %r8d,%r8d
lea    0xcad(%rip),%r9
call   1030 <CHECK@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1090 <serial_read_byte@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edx
mov    $0xa,%edi
mov    $0x9,%esi
mov    $0x55,%ecx
xor    %r8d,%r8d
lea    0xc7e(%rip),%r9
call   1030 <CHECK@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1090 <serial_read_byte@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edx
mov    $0xa,%esi
xor    %r8d,%r8d
lea    0xc59(%rip),%r9
mov    %esi,%edi
mov    %r8d,%ecx
call   1030 <CHECK@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1090 <serial_read_byte@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edx
mov    $0xa,%edi
mov    $0xb,%esi
mov    $0xff,%ecx
xor    %r8d,%r8d
lea    0xc25(%rip),%r9
call   1030 <CHECK@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   10b0 <serial_data_available@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edx
mov    $0xa,%edi
mov    $0xc,%esi
xor    %r8d,%r8d
lea    0xc0c(%rip),%r9
mov    %r8d,%ecx
call   1030 <CHECK@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1070 <serial_close@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%edx
mov    $0xa,%edi
mov    $0xd,%esi
xor    %r8d,%r8d
lea    0xbf4(%rip),%r9
mov    %r8d,%ecx
call   1030 <CHECK@plt>
add    $0x850,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ta>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x808,%rsp
mov    %edi,%r13d
lea    0xf64(%rip),%rdi
call   1040 <puts@plt>
lea    0xe21(%rip),%rsi
mov    %r13d,%edi
mov    $0xe100,%edx
xor    %ecx,%ecx
call   1080 <serial_open@plt>
mov    %eax,%ebp
lea    0xe16(%rip),%r9
mov    $0xa,%edi
mov    $0x1,%esi
mov    %eax,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1030 <CHECK@plt>
movsd  0xde3(%rip),%xmm0
call   10e0 <time_sleep@plt>
mov    %rsp,%r14
mov    %r13d,%edi
mov    %ebp,%esi
mov    %r14,%rdx
mov    $0x800,%ecx
call   10d0 <serial_read@plt>
mov    %r13d,%edi
mov    %ebp,%esi
call   10b0 <serial_data_available@plt>
lea    0xdd9(%rip),%r12
mov    $0xa,%edi
mov    $0x2,%esi
mov    %eax,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
mov    %r12,%r9
call   1030 <CHECK@plt>
lea    0xdcf(%rip),%r15
mov    %r15,%rdi
call   1050 <strlen@plt>
mov    %r13d,%edi
mov    %ebp,%esi
mov    %r15,%rdx
mov    %eax,%ecx
call   10c0 <serial_write@plt>
lea    0xe5b(%rip),%r9
mov    $0xa,%edi
mov    $0x3,%esi
mov    %eax,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1030 <CHECK@plt>
mov    %r13d,%edi
mov    %ebp,%esi
mov    $0xaa,%edx
call   10a0 <serial_write_byte@plt>
mov    %r13d,%edi
mov    %ebp,%esi
mov    $0x55,%edx
call   10a0 <serial_write_byte@plt>
mov    %r13d,%edi
mov    %ebp,%esi
xor    %edx,%edx
call   10a0 <serial_write_byte@plt>
mov    %r13d,%edi
mov    %ebp,%esi
mov    $0xff,%edx
call   10a0 <serial_write_byte@plt>
lea    0xe12(%rip),%r9
mov    $0xa,%edi
mov    $0x4,%esi
mov    %eax,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1030 <CHECK@plt>
movsd  0xd06(%rip),%xmm0
call   10e0 <time_sleep@plt>
mov    %r13d,%edi
mov    %ebp,%esi
call   10b0 <serial_data_available@plt>
mov    %eax,%ebx
mov    %r15,%rdi
call   1050 <strlen@plt>
lea    0x4(%rax),%ecx
mov    $0xa,%edi
mov    $0x5,%esi
mov    %ebx,%edx
xor    %r8d,%r8d
mov    %r12,%r9
call   1030 <CHECK@plt>
mov    %r15,%rdi
call   1050 <strlen@plt>
mov    %r13d,%edi
mov    %ebp,%esi
mov    %r14,%rdx
mov    %eax,%ecx
call   10d0 <serial_read@plt>
mov    %eax,%ebx
mov    %r15,%rdi
call   1050 <strlen@plt>
lea    0xdab(%rip),%r9
mov    $0xa,%edi
mov    $0x6,%esi
mov    %ebx,%edx
mov    %eax,%ecx
xor    %r8d,%r8d
call   1030 <CHECK@plt>
test   %ebx,%ebx
js     1375 <ta+0x1b5>
mov    %ebx,%eax
movb   $0x0,(%rsp,%rax,1)
lea    0xcbb(%rip),%rdi
mov    %rsp,%rsi
call   1060 <strcmp@plt>
lea    0xd75(%rip),%r9
mov    $0xa,%edi
mov    $0x7,%esi
mov    %eax,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1030 <CHECK@plt>
mov    %r13d,%edi
mov    %ebp,%esi
call   1090 <serial_read_byte@plt>
lea    0xd5a(%rip),%r14
mov    $0xa,%edi
mov    $0x8,%esi
mov    %eax,%edx
mov    $0xaa,%ecx
xor    %r8d,%r8d
mov    %r14,%r9
call   1030 <CHECK@plt>
mov    %r13d,%edi
mov    %ebp,%esi
call   1090 <serial_read_byte@plt>
mov    $0xa,%edi
mov    $0x9,%esi
mov    %eax,%edx
mov    $0x55,%ecx
xor    %r8d,%r8d
mov    %r14,%r9
call   1030 <CHECK@plt>
mov    %r13d,%edi
mov    %ebp,%esi
call   1090 <serial_read_byte@plt>
mov    $0xa,%edi
mov    $0xa,%esi
mov    %eax,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
mov    %r14,%r9
call   1030 <CHECK@plt>
mov    %r13d,%edi
mov    %ebp,%esi
call   1090 <serial_read_byte@plt>
mov    $0xa,%edi
mov    $0xb,%esi
mov    %eax,%edx
mov    $0xff,%ecx
xor    %r8d,%r8d
mov    %r14,%r9
call   1030 <CHECK@plt>
mov    %r13d,%edi
mov    %ebp,%esi
call   10b0 <serial_data_available@plt>
lea    0xccf(%rip),%r9
mov    $0xa,%edi
mov    $0xc,%esi
mov    %eax,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1030 <CHECK@plt>
mov    %r13d,%edi
mov    %ebp,%esi
call   1070 <serial_close@plt>
lea    0xcbd(%rip),%r9
mov    $0xa,%edi
mov    $0xd,%esi
mov    %eax,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1030 <CHECK@plt>
add    $0x808,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [20 x i8] c"Serial link tests.\0A\00"
@.str.1 = [13 x i8] c"/dev/ttyAMA0\00"
@.str.2 = [12 x i8] c"serial open\00"
@.str.3 = [22 x i8] c"serial data available\00"
@.str.4 = [170 x i8] c"To be, or not to be, that is the question-Whether 'tis Nobler in the mind to sufferThe Slings and Arrows of outrageous Fortune,Or to take Arms against a Sea of troubles,\00"
@.str.5 = [13 x i8] c"serial write\00"
@.str.6 = [18 x i8] c"serial write byte\00"
@.str.7 = [12 x i8] c"serial read\00"
@.str.8 = [17 x i8] c"serial read byte\00"
@.str.9 = [21 x i8] c"serial data availabe\00"
@.str.10 = [13 x i8] c"serial close\00"
define void @ta(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca [2048 x i8]
store i32 %0, i32* %2
%8 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* %2
%10 = call i32 @serial_open(i32 %9, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 57600, i32 0)
store i32 %10, i32* %3
%11 = load i32, i32* %3
%12 = call i32 @CHECK(i32 10, i32 1, i32 %11, i32 0, i32 0, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%13 = call i32 @time_sleep(double 1.000000e-01)
%14 = load i32, i32* %2
%15 = load i32, i32* %3
%16 = getelementptr inbounds [2048 x i8], [2048 x i8]* %7, i64 0, i64 0
%17 = call i32 @serial_read(i32 %14, i32 %15, i8* %16, i32 2048)
store i32 %17, i32* %4
%18 = load i32, i32* %2
%19 = load i32, i32* %3
%20 = call i32 @serial_data_available(i32 %18, i32 %19)
store i32 %20, i32* %4
%21 = load i32, i32* %4
%22 = call i32 @CHECK(i32 10, i32 2, i32 %21, i32 0, i32 0, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
store i8* getelementptr inbounds ([170 x i8], [170 x i8]* @.str.4, i64 0, i64 0), i8** %6
%23 = load i32, i32* %2
%24 = load i32, i32* %3
%25 = load i8*, i8** %6
%26 = load i8*, i8** %6
%27 = call i32 @strlen(i8* %26)
%28 = call i32 @serial_write(i32 %23, i32 %24, i8* %25, i32 %27)
store i32 %28, i32* %5
%29 = load i32, i32* %5
%30 = call i32 @CHECK(i32 10, i32 3, i32 %29, i32 0, i32 0, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
%31 = load i32, i32* %2
%32 = load i32, i32* %3
%33 = call i32 @serial_write_byte(i32 %31, i32 %32, i32 170)
store i32 %33, i32* %5
%34 = load i32, i32* %2
%35 = load i32, i32* %3
%36 = call i32 @serial_write_byte(i32 %34, i32 %35, i32 85)
store i32 %36, i32* %5
%37 = load i32, i32* %2
%38 = load i32, i32* %3
%39 = call i32 @serial_write_byte(i32 %37, i32 %38, i32 0)
store i32 %39, i32* %5
%40 = load i32, i32* %2
%41 = load i32, i32* %3
%42 = call i32 @serial_write_byte(i32 %40, i32 %41, i32 255)
store i32 %42, i32* %5
%43 = load i32, i32* %5
%44 = call i32 @CHECK(i32 10, i32 4, i32 %43, i32 0, i32 0, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0))
%45 = call i32 @time_sleep(double 1.000000e-01)
%46 = load i32, i32* %2
%47 = load i32, i32* %3
%48 = call i32 @serial_data_available(i32 %46, i32 %47)
store i32 %48, i32* %4
%49 = load i32, i32* %4
%50 = load i8*, i8** %6
%51 = call i32 @strlen(i8* %50)
%52 = add nsw i32 %51, 4
%53 = call i32 @CHECK(i32 10, i32 5, i32 %49, i32 %52, i32 0, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
%54 = load i32, i32* %2
%55 = load i32, i32* %3
%56 = getelementptr inbounds [2048 x i8], [2048 x i8]* %7, i64 0, i64 0
%57 = load i8*, i8** %6
%58 = call i32 @strlen(i8* %57)
%59 = call i32 @serial_read(i32 %54, i32 %55, i8* %56, i32 %58)
store i32 %59, i32* %4
%60 = load i32, i32* %4
%61 = load i8*, i8** %6
%62 = call i32 @strlen(i8* %61)
%63 = call i32 @CHECK(i32 10, i32 6, i32 %60, i32 %62, i32 0, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0))
%64 = load i32, i32* %4
%65 = icmp sge i32 %64, 0
br i1 %65, label %66, label %70
66: ; preds = %1
%67 = load i32, i32* %4
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds [2048 x i8], [2048 x i8]* %7, i64 0, i64 %68
store i8 0, i8* %69
br label %70
70: ; preds = %66, %1
%71 = load i8*, i8** %6
%72 = getelementptr inbounds [2048 x i8], [2048 x i8]* %7, i64 0, i64 0
%73 = call i32 @strcmp(i8* %71, i8* %72)
%74 = call i32 @CHECK(i32 10, i32 7, i32 %73, i32 0, i32 0, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0))
%75 = load i32, i32* %2
%76 = load i32, i32* %3
%77 = call i32 @serial_read_byte(i32 %75, i32 %76)
store i32 %77, i32* %4
%78 = load i32, i32* %4
%79 = call i32 @CHECK(i32 10, i32 8, i32 %78, i32 170, i32 0, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.8, i64 0, i64 0))
%80 = load i32, i32* %2
%81 = load i32, i32* %3
%82 = call i32 @serial_read_byte(i32 %80, i32 %81)
store i32 %82, i32* %4
%83 = load i32, i32* %4
%84 = call i32 @CHECK(i32 10, i32 9, i32 %83, i32 85, i32 0, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.8, i64 0, i64 0))
%85 = load i32, i32* %2
%86 = load i32, i32* %3
%87 = call i32 @serial_read_byte(i32 %85, i32 %86)
store i32 %87, i32* %4
%88 = load i32, i32* %4
%89 = call i32 @CHECK(i32 10, i32 10, i32 %88, i32 0, i32 0, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.8, i64 0, i64 0))
%90 = load i32, i32* %2
%91 = load i32, i32* %3
%92 = call i32 @serial_read_byte(i32 %90, i32 %91)
store i32 %92, i32* %4
%93 = load i32, i32* %4
%94 = call i32 @CHECK(i32 10, i32 11, i32 %93, i32 255, i32 0, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.8, i64 0, i64 0))
%95 = load i32, i32* %2
%96 = load i32, i32* %3
%97 = call i32 @serial_data_available(i32 %95, i32 %96)
store i32 %97, i32* %4
%98 = load i32, i32* %4
%99 = call i32 @CHECK(i32 10, i32 12, i32 %98, i32 0, i32 0, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.9, i64 0, i64 0))
%100 = load i32, i32* %2
%101 = load i32, i32* %3
%102 = call i32 @serial_close(i32 %100, i32 %101)
store i32 %102, i32* %5
%103 = load i32, i32* %5
%104 = call i32 @CHECK(i32 10, i32 13, i32 %103, i32 0, i32 0, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.10, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str.1 = [13 x i8] c"/dev/ttyAMA0\00"
@.str.2 = [12 x i8] c"serial open\00"
@.str.3 = [22 x i8] c"serial data available\00"
@.str.4 = [170 x i8] c"To be, or not to be, that is the question-Whether 'tis Nobler in the mind to sufferThe Slings and Arrows of outrageous Fortune,Or to take Arms against a Sea of troubles,\00"
@.str.5 = [13 x i8] c"serial write\00"
@.str.6 = [18 x i8] c"serial write byte\00"
@.str.7 = [12 x i8] c"serial read\00"
@.str.8 = [17 x i8] c"serial read byte\00"
@.str.9 = [21 x i8] c"serial data availabe\00"
@.str.10 = [13 x i8] c"serial close\00"
@str = [19 x i8] c"Serial link tests.\00"
define void @ta(i32 %0) {
%2 = alloca [2048 x i8]
%3 = getelementptr inbounds [2048 x i8], [2048 x i8]* %2, i64 0, i64 0
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
%5 = tail call i32 @serial_open(i32 %0, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 57600, i32 0)
%6 = tail call i32 @CHECK(i32 10, i32 1, i32 %5, i32 0, i32 0, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%7 = tail call i32 @time_sleep(double 1.000000e-01)
%8 = call i32 @serial_read(i32 %0, i32 %5, i8* %3, i32 2048)
%9 = call i32 @serial_data_available(i32 %0, i32 %5)
%10 = call i32 @CHECK(i32 10, i32 2, i32 %9, i32 0, i32 0, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
%11 = call i32 @strlen(i8* getelementptr inbounds ([170 x i8], [170 x i8]* @.str.4, i64 0, i64 0))
%12 = call i32 @serial_write(i32 %0, i32 %5, i8* getelementptr inbounds ([170 x i8], [170 x i8]* @.str.4, i64 0, i64 0), i32 %11)
%13 = call i32 @CHECK(i32 10, i32 3, i32 %12, i32 0, i32 0, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
%14 = call i32 @serial_write_byte(i32 %0, i32 %5, i32 170)
%15 = call i32 @serial_write_byte(i32 %0, i32 %5, i32 85)
%16 = call i32 @serial_write_byte(i32 %0, i32 %5, i32 0)
%17 = call i32 @serial_write_byte(i32 %0, i32 %5, i32 255)
%18 = call i32 @CHECK(i32 10, i32 4, i32 %17, i32 0, i32 0, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0))
%19 = call i32 @time_sleep(double 1.000000e-01)
%20 = call i32 @serial_data_available(i32 %0, i32 %5)
%21 = call i32 @strlen(i8* getelementptr inbounds ([170 x i8], [170 x i8]* @.str.4, i64 0, i64 0))
%22 = add nsw i32 %21, 4
%23 = call i32 @CHECK(i32 10, i32 5, i32 %20, i32 %22, i32 0, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
%24 = call i32 @strlen(i8* getelementptr inbounds ([170 x i8], [170 x i8]* @.str.4, i64 0, i64 0))
%25 = call i32 @serial_read(i32 %0, i32 %5, i8* %3, i32 %24)
%26 = call i32 @strlen(i8* getelementptr inbounds ([170 x i8], [170 x i8]* @.str.4, i64 0, i64 0))
%27 = call i32 @CHECK(i32 10, i32 6, i32 %25, i32 %26, i32 0, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0))
%28 = icmp sgt i32 %25, -1
br i1 %28, label %29, label %32
29: ; preds = %1
%30 = zext i32 %25 to i64
%31 = getelementptr inbounds [2048 x i8], [2048 x i8]* %2, i64 0, i64 %30
store i8 0, i8* %31
br label %32
32: ; preds = %29, %1
%33 = call i32 @strcmp(i8* dereferenceable(170) getelementptr inbounds ([170 x i8], [170 x i8]* @.str.4, i64 0, i64 0), i8* %3)
%34 = call i32 @CHECK(i32 10, i32 7, i32 %33, i32 0, i32 0, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0))
%35 = call i32 @serial_read_byte(i32 %0, i32 %5)
%36 = call i32 @CHECK(i32 10, i32 8, i32 %35, i32 170, i32 0, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.8, i64 0, i64 0))
%37 = call i32 @serial_read_byte(i32 %0, i32 %5)
%38 = call i32 @CHECK(i32 10, i32 9, i32 %37, i32 85, i32 0, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.8, i64 0, i64 0))
%39 = call i32 @serial_read_byte(i32 %0, i32 %5)
%40 = call i32 @CHECK(i32 10, i32 10, i32 %39, i32 0, i32 0, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.8, i64 0, i64 0))
%41 = call i32 @serial_read_byte(i32 %0, i32 %5)
%42 = call i32 @CHECK(i32 10, i32 11, i32 %41, i32 255, i32 0, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.8, i64 0, i64 0))
%43 = call i32 @serial_data_available(i32 %0, i32 %5)
%44 = call i32 @CHECK(i32 10, i32 12, i32 %43, i32 0, i32 0, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.9, i64 0, i64 0))
%45 = call i32 @serial_close(i32 %0, i32 %5)
%46 = call i32 @CHECK(i32 10, i32 13, i32 %45, i32 0, i32 0, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.10, i64 0, i64 0))
ret void
}