#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 */
scalar_t__ EAGAIN;
int /*<<< orphan*/ WaitForRobovero();
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ printf(char *);
size_t strlen(char *);
int /*<<< orphan*/ tcdrain(int);
int write(int, char *, size_t);
void TransmitCommand(char *command, int serial_if) {
  size_t command_length;
  command_length = strlen(command);
  while (command_length > 0) {
    int data_written;
    data_written = write(serial_if, command, command_length);
    if (data_written == -1) {
      if (errno == EAGAIN)
        tcdrain(serial_if);
      else {
        printf("Write failure\n");
        exit(-1);
      }
      continue;
    }
    command += data_written;
    command_length -= data_written;
  }
  WaitForRobovero();
}


x86 assembly (clang, -O0):
<TransmitCommand>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jbe    120b <TransmitCommand+0xab>
mov    -0xc(%rbp),%edi
mov    -0x8(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <write@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    11e6 <TransmitCommand+0x86>
mov    0x2e35(%rip),%rax
mov    (%rax),%rax
mov    0x2e1b(%rip),%rcx
cmp    (%rcx),%rax
jne    11cb <TransmitCommand+0x6b>
mov    -0xc(%rbp),%edi
call   1030 <tcdrain@plt>
jmp    11e1 <TransmitCommand+0x81>
lea    0xe2e(%rip),%rdi
call   1060 <printf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
jmp    117c <TransmitCommand+0x1c>
mov    -0x1c(%rbp),%ecx
mov    -0x8(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
movslq -0x1c(%rbp),%rcx
mov    -0x18(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x18(%rbp)
jmp    117c <TransmitCommand+0x1c>
mov    $0x0,%al
call   1070 <WaitForRobovero@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<TransmitCommand>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r14d
mov    %rdi,%rbx
call   1060 <strlen@plt>
test   %rax,%rax
je     11c6 <TransmitCommand+0x66>
mov    %rax,%rbp
mov    0x2e5e(%rip),%r15
mov    0x2e47(%rip),%r12
jmp    119d <TransmitCommand+0x3d>
nopl   0x0(%rax,%rax,1)
cltq
add    %rax,%rbx
sub    %rax,%rbp
test   %rbp,%rbp
je     11c6 <TransmitCommand+0x66>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %rbp,%rdx
call   1050 <write@plt>
cmp    $0xffffffff,%eax
jne    1190 <TransmitCommand+0x30>
mov    (%r15),%rax
cmp    (%r12),%rax
jne    11d5 <TransmitCommand+0x75>
mov    %r14d,%edi
call   1040 <tcdrain@plt>
test   %rbp,%rbp
jne    119d <TransmitCommand+0x3d>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <WaitForRobovero@plt>
lea    0xe24(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@errno = global i64 0
@EAGAIN = global i64 0
@.str = [15 x i8] c"Write failure\0A\00"
define void @TransmitCommand(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i64
%6 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%7 = load i8*, i8** %3
%8 = call i64 @strlen(i8* %7)
store i64 %8, i64* %5
br label %9
9: ; preds = %30, %29, %2
%10 = load i64, i64* %5
%11 = icmp ugt i64 %10, 0
br i1 %11, label %12, label %39
12: ; preds = %9
%13 = load i32, i32* %4
%14 = load i8*, i8** %3
%15 = load i64, i64* %5
%16 = call i32 @write(i32 %13, i8* %14, i64 %15)
store i32 %16, i32* %6
%17 = load i32, i32* %6
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %30
19: ; preds = %12
%20 = load i64, i64* @errno
%21 = load i64, i64* @EAGAIN
%22 = icmp eq i64 %20, %21
br i1 %22, label %23, label %26
23: ; preds = %19
%24 = load i32, i32* %4
%25 = call i32 @tcdrain(i32 %24)
br label %29
26: ; preds = %19
%27 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%28 = call i32 @exit(i32 -1)
unreachable
29: ; preds = %23
br label %9
30: ; preds = %12
%31 = load i32, i32* %6
%32 = load i8*, i8** %3
%33 = sext i32 %31 to i64
%34 = getelementptr inbounds i8, i8* %32, i64 %33
store i8* %34, i8** %3
%35 = load i32, i32* %6
%36 = sext i32 %35 to i64
%37 = load i64, i64* %5
%38 = sub i64 %37, %36
store i64 %38, i64* %5
br label %9
39: ; preds = %9
%40 = call i32 (...) @WaitForRobovero()
ret void
}

LLVM IR (-O2):
@errno = global i64 0
@EAGAIN = global i64 0
@str = [14 x i8] c"Write failure\00"
define void @TransmitCommand(i8* nocapture %0, i32 %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%4 = icmp eq i64 %3, 0
br i1 %4, label %27, label %5
5: ; preds = %2, %23
%6 = phi i8* [ %25, %23 ], [ %0, %2 ]
%7 = phi i64 [ %24, %23 ], [ %3, %2 ]
%8 = tail call i32 @write(i32 %1, i8* %6, i64 %7)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %19
10: ; preds = %5
%11 = load i64, i64* @errno
%12 = load i64, i64* @EAGAIN
%13 = icmp eq i64 %11, %12
br i1 %13, label %14, label %16
14: ; preds = %10
%15 = tail call i32 @tcdrain(i32 %1)
br label %23
16: ; preds = %10
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
%18 = tail call i32 @exit(i32 -1)
unreachable
19: ; preds = %5
%20 = sext i32 %8 to i64
%21 = getelementptr inbounds i8, i8* %6, i64 %20
%22 = sub i64 %7, %20
br label %23
23: ; preds = %19, %14
%24 = phi i64 [ %7, %14 ], [ %22, %19 ]
%25 = phi i8* [ %6, %14 ], [ %21, %19 ]
%26 = icmp eq i64 %24, 0
br i1 %26, label %27, label %5
27: ; preds = %23, %2
%28 = tail call i32 (...) @WaitForRobovero()
ret void
}