#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*/ exit(int);
int /*<<< orphan*/ printf(char *, int);
int read(int, unsigned char *, int);
int /*<<< orphan*/ setBaud(int, int);
int write(int, unsigned char *, int);
void OW_WriteByte(int fd, unsigned char dataByte) {
  int i, res;
  unsigned char out;
  unsigned char inBuf[64];
  setBaud(fd, 115200);
  for (i = 0; i < 8; i++) {
    out = (dataByte & 0x01) ? 0xff : 0xc0;
    res = write(fd, &out, 1);
    if (res == -1) {
      printf("Failed to write (%d)\n", i);
      exit(-1);
    }
    dataByte >>= 1;
  }
  while (1) {
    i = read(fd, inBuf, 64);
    if (i <= 0)
      break;
  }
}


x86 assembly (clang, -O0):
<OW_WriteByte>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %sil,%al
mov    %edi,-0x4(%rbp)
mov    %al,-0x5(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x1c200,%esi
call   1070 <setBaud@plt>
movl   $0x0,-0xc(%rbp)
cmpl   $0x8,-0xc(%rbp)
jge    11e8 <OW_WriteByte+0x98>
movzbl -0x5(%rbp),%edx
and    $0x1,%edx
mov    $0xc0,%eax
mov    $0xff,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %al,-0x11(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x11(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0xffffffff,-0x10(%rbp)
jne    11d0 <OW_WriteByte+0x80>
mov    -0xc(%rbp),%esi
lea    0xe3f(%rip),%rdi
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>
movzbl -0x5(%rbp),%eax
sar    $0x1,%eax
mov    %al,-0x5(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1175 <OW_WriteByte+0x25>
jmp    11ed <OW_WriteByte+0x9d>
mov    -0x4(%rbp),%edi
lea    -0x60(%rbp),%rsi
mov    $0x40,%edx
call   1050 <read@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jg     1210 <OW_WriteByte+0xc0>
jmp    1215 <OW_WriteByte+0xc5>
jmp    11ed <OW_WriteByte+0x9d>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<OW_WriteByte>:
push   %rbp
push   %r14
push   %rbx
sub    $0x50,%rsp
mov    %esi,%ebp
mov    %edi,%ebx
mov    $0x1c200,%esi
call   1070 <setBaud@plt>
mov    %ebp,%eax
and    $0x1,%al
neg    %al
sbb    %eax,%eax
or     $0xc0,%al
mov    %al,0xf(%rsp)
lea    0xf(%rsp),%rsi
mov    $0x1,%r14d
mov    %ebx,%edi
mov    $0x1,%edx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
je     12cc <OW_WriteByte+0x17c>
mov    %ebp,%eax
and    $0x2,%al
neg    %al
sbb    %eax,%eax
or     $0xc0,%al
mov    %al,0xf(%rsp)
lea    0xf(%rsp),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
je     12ff <OW_WriteByte+0x1af>
mov    %ebp,%eax
and    $0x4,%al
neg    %al
sbb    %eax,%eax
or     $0xc0,%al
mov    %al,0xf(%rsp)
lea    0xf(%rsp),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
je     12d1 <OW_WriteByte+0x181>
mov    %ebp,%eax
and    $0x8,%al
neg    %al
sbb    %eax,%eax
or     $0xc0,%al
mov    %al,0xf(%rsp)
lea    0xf(%rsp),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
je     12d9 <OW_WriteByte+0x189>
mov    %ebp,%eax
and    $0x10,%al
neg    %al
sbb    %eax,%eax
or     $0xc0,%al
mov    %al,0xf(%rsp)
lea    0xf(%rsp),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
je     12e1 <OW_WriteByte+0x191>
mov    %ebp,%eax
and    $0x20,%al
neg    %al
sbb    %eax,%eax
or     $0xc0,%al
mov    %al,0xf(%rsp)
lea    0xf(%rsp),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
je     12e9 <OW_WriteByte+0x199>
mov    %ebp,%eax
and    $0x40,%al
neg    %al
sbb    %eax,%eax
or     $0xc0,%al
mov    %al,0xf(%rsp)
lea    0xf(%rsp),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
je     12f1 <OW_WriteByte+0x1a1>
sar    $0x7,%bpl
or     $0xc0,%bpl
mov    %bpl,0xf(%rsp)
lea    0xf(%rsp),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
je     12f9 <OW_WriteByte+0x1a9>
lea    0x10(%rsp),%rbp
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x40,%edx
call   1050 <read@plt>
test   %eax,%eax
jg     12b0 <OW_WriteByte+0x160>
add    $0x50,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
xor    %r14d,%r14d
jmp    12ff <OW_WriteByte+0x1af>
mov    $0x2,%r14d
jmp    12ff <OW_WriteByte+0x1af>
mov    $0x3,%r14d
jmp    12ff <OW_WriteByte+0x1af>
mov    $0x4,%r14d
jmp    12ff <OW_WriteByte+0x1af>
mov    $0x5,%r14d
jmp    12ff <OW_WriteByte+0x1af>
mov    $0x6,%r14d
jmp    12ff <OW_WriteByte+0x1af>
mov    $0x7,%r14d
lea    0xcfa(%rip),%rdi
mov    %r14d,%esi
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [22 x i8] c"Failed to write (%d)\0A\00"
define void @OW_WriteByte(i32 %0, i8 zeroext %1) {
%3 = alloca i32
%4 = alloca i8
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8
%8 = alloca [64 x i8]
store i32 %0, i32* %3
store i8 %1, i8* %4
%9 = load i32, i32* %3
%10 = call i32 @setBaud(i32 %9, i32 115200)
store i32 0, i32* %5
br label %11
11: ; preds = %35, %2
%12 = load i32, i32* %5
%13 = icmp slt i32 %12, 8
br i1 %13, label %14, label %38
14: ; preds = %11
%15 = load i8, i8* %4
%16 = zext i8 %15 to i32
%17 = and i32 %16, 1
%18 = icmp ne i32 %17, 0
%19 = zext i1 %18 to i64
%20 = select i1 %18, i32 255, i32 192
%21 = trunc i32 %20 to i8
store i8 %21, i8* %7
%22 = load i32, i32* %3
%23 = call i32 @write(i32 %22, i8* %7, i32 1)
store i32 %23, i32* %6
%24 = load i32, i32* %6
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %30
26: ; preds = %14
%27 = load i32, i32* %5
%28 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %27)
%29 = call i32 @exit(i32 -1)
unreachable
30: ; preds = %14
%31 = load i8, i8* %4
%32 = zext i8 %31 to i32
%33 = ashr i32 %32, 1
%34 = trunc i32 %33 to i8
store i8 %34, i8* %4
br label %35
35: ; preds = %30
%36 = load i32, i32* %5
%37 = add nsw i32 %36, 1
store i32 %37, i32* %5
br label %11
38: ; preds = %11
br label %39
39: ; preds = %38, %46
%40 = load i32, i32* %3
%41 = getelementptr inbounds [64 x i8], [64 x i8]* %8, i64 0, i64 0
%42 = call i32 @read(i32 %40, i8* %41, i32 64)
store i32 %42, i32* %5
%43 = load i32, i32* %5
%44 = icmp sle i32 %43, 0
br i1 %44, label %45, label %46
45: ; preds = %39
br label %47
46: ; preds = %39
br label %39
47: ; preds = %45
ret void
}

LLVM IR (-O2):
@.str = [22 x i8] c"Failed to write (%d)\0A\00"
define void @OW_WriteByte(i32 %0, i8 zeroext %1) {
%3 = alloca i8
%4 = alloca [64 x i8]
%5 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%6 = tail call i32 @setBaud(i32 %0, i32 115200)
%7 = and i8 %1, 1
%8 = icmp eq i8 %7, 0
%9 = select i1 %8, i8 -64, i8 -1
store i8 %9, i8* %3
%10 = call i32 @write(i32 %0, i8* %3, i32 1)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %16
12: ; preds = %52, %46, %40, %34, %28, %22, %16, %2
%13 = phi i32 [ 0, %2 ], [ 1, %16 ], [ 2, %22 ], [ 3, %28 ], [ 4, %34 ], [ 5, %40 ], [ 6, %46 ], [ 7, %52 ]
%14 = tail call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = tail call i32 @exit(i32 -1)
unreachable
16: ; preds = %2
%17 = and i8 %1, 2
%18 = icmp eq i8 %17, 0
%19 = select i1 %18, i8 -64, i8 -1
store i8 %19, i8* %3
%20 = call i32 @write(i32 %0, i8* %3, i32 1)
%21 = icmp eq i32 %20, -1
br i1 %21, label %12, label %22
22: ; preds = %16
%23 = and i8 %1, 4
%24 = icmp eq i8 %23, 0
%25 = select i1 %24, i8 -64, i8 -1
store i8 %25, i8* %3
%26 = call i32 @write(i32 %0, i8* %3, i32 1)
%27 = icmp eq i32 %26, -1
br i1 %27, label %12, label %28
28: ; preds = %22
%29 = and i8 %1, 8
%30 = icmp eq i8 %29, 0
%31 = select i1 %30, i8 -64, i8 -1
store i8 %31, i8* %3
%32 = call i32 @write(i32 %0, i8* %3, i32 1)
%33 = icmp eq i32 %32, -1
br i1 %33, label %12, label %34
34: ; preds = %28
%35 = and i8 %1, 16
%36 = icmp eq i8 %35, 0
%37 = select i1 %36, i8 -64, i8 -1
store i8 %37, i8* %3
%38 = call i32 @write(i32 %0, i8* %3, i32 1)
%39 = icmp eq i32 %38, -1
br i1 %39, label %12, label %40
40: ; preds = %34
%41 = and i8 %1, 32
%42 = icmp eq i8 %41, 0
%43 = select i1 %42, i8 -64, i8 -1
store i8 %43, i8* %3
%44 = call i32 @write(i32 %0, i8* %3, i32 1)
%45 = icmp eq i32 %44, -1
br i1 %45, label %12, label %46
46: ; preds = %40
%47 = and i8 %1, 64
%48 = icmp eq i8 %47, 0
%49 = select i1 %48, i8 -64, i8 -1
store i8 %49, i8* %3
%50 = call i32 @write(i32 %0, i8* %3, i32 1)
%51 = icmp eq i32 %50, -1
br i1 %51, label %12, label %52
52: ; preds = %46
%53 = icmp sgt i8 %1, -1
%54 = select i1 %53, i8 -64, i8 -1
store i8 %54, i8* %3
%55 = call i32 @write(i32 %0, i8* %3, i32 1)
%56 = icmp eq i32 %55, -1
br i1 %56, label %12, label %57
57: ; preds = %52, %57
%58 = call i32 @read(i32 %0, i8* %5, i32 64)
%59 = icmp slt i32 %58, 1
br i1 %59, label %60, label %57
60: ; preds = %57
ret void
}