#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*/ uint8_t;
typedef size_t ssize_t;

/* Variables and functions */
size_t write(int, int /*<<< orphan*/ *, size_t);
void _send_serial_data(int fd, uint8_t *data, size_t size) {
  ssize_t bytes_sent, bytes_to_go, nbytes;
  for (bytes_sent = 0, bytes_to_go = size; bytes_to_go > 0;) {
    if ((nbytes = write(fd, &data[bytes_sent], bytes_to_go)) > 0) {
      bytes_to_go -= nbytes;
      bytes_sent += nbytes;
    }
  }
}


x86 assembly (clang, -O0):
<_send_serial_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jbe    1187 <_send_serial_data+0x77>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
mov    -0x28(%rbp),%rdx
call   1030 <write@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jbe    1182 <_send_serial_data+0x72>
mov    -0x30(%rbp),%rcx
mov    -0x28(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x30(%rbp),%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    1133 <_send_serial_data+0x23>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_send_serial_data>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %rdx,%rdx
je     1147 <_send_serial_data+0x37>
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %edi,%r15d
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
lea    (%r14,%rbp,4),%rsi
mov    %r15d,%edi
mov    %rbx,%rdx
call   1030 <write@plt>
add    %rax,%rbp
sub    %rax,%rbx
jne    1130 <_send_serial_data+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @_send_serial_data(i32 %0, i32* %1, i64 %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
store i32 %0, i32* %4
store i32* %1, i32** %5
store i64 %2, i64* %6
store i64 0, i64* %7
%10 = load i64, i64* %6
store i64 %10, i64* %8
br label %11
11: ; preds = %29, %3
%12 = load i64, i64* %8
%13 = icmp ugt i64 %12, 0
br i1 %13, label %14, label %30
14: ; preds = %11
%15 = load i32, i32* %4
%16 = load i32*, i32** %5
%17 = load i64, i64* %7
%18 = getelementptr inbounds i32, i32* %16, i64 %17
%19 = load i64, i64* %8
%20 = call i64 @write(i32 %15, i32* %18, i64 %19)
store i64 %20, i64* %9
%21 = icmp ugt i64 %20, 0
br i1 %21, label %22, label %29
22: ; preds = %14
%23 = load i64, i64* %9
%24 = load i64, i64* %8
%25 = sub i64 %24, %23
store i64 %25, i64* %8
%26 = load i64, i64* %9
%27 = load i64, i64* %7
%28 = add i64 %27, %26
store i64 %28, i64* %7
br label %29
29: ; preds = %22, %14
br label %11
30: ; preds = %11
ret void
}

LLVM IR (-O2):
define void @_send_serial_data(i32 %0, i32* nocapture %1, i64 %2) {
%4 = icmp eq i64 %2, 0
br i1 %4, label %13, label %5
5: ; preds = %3, %5
%6 = phi i64 [ %11, %5 ], [ 0, %3 ]
%7 = phi i64 [ %10, %5 ], [ %2, %3 ]
%8 = getelementptr inbounds i32, i32* %1, i64 %6
%9 = tail call i64 @write(i32 %0, i32* %8, i64 %7)
%10 = sub i64 %7, %9
%11 = add i64 %9, %6
%12 = icmp eq i64 %10, 0
br i1 %12, label %13, label %5
13: ; preds = %5, %3
ret void
}