#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 scalar_t__ uint32_t;
typedef int ssize_t;
typedef int /*<<< orphan*/ int32_t;

/* Variables and functions */
int errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ stderr;
int write(int /*<<< orphan*/, int /*<<< orphan*/ *, scalar_t__);
bool serial_write(int32_t fd, uint8_t *buffer, uint32_t size) {
  ssize_t nbWritten;
  nbWritten = write(fd, buffer, size);
  if (nbWritten == -1) {
    fprintf(stderr, "unable to send data on serial line erro = %d\n", errno);
  } else if (size == (uint32_t)nbWritten) {
    return true;
  }
  return false;
}


x86 assembly (clang, -O0):
<serial_write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <write@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    1173 <serial_write+0x53>
mov    0x2e89(%rip),%rax
mov    (%rax),%edi
mov    0x2e78(%rip),%rax
mov    (%rax),%edx
lea    0xe97(%rip),%rsi
call   1040 <fprintf@plt>
jmp    1195 <serial_write+0x75>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
cmp    %rcx,%rax
jne    1190 <serial_write+0x70>
movl   $0x1,-0x4(%rbp)
jmp    119c <serial_write+0x7c>
jmp    1195 <serial_write+0x75>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<serial_write>:
push   %rbx
mov    %rdx,%rbx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
je     113d <serial_write+0x1d>
movslq %eax,%rcx
mov    $0x1,%eax
cmp    %rbx,%rcx
jne    115b <serial_write+0x3b>
pop    %rbx
ret
mov    0x2e9c(%rip),%rax
mov    (%rax),%edi
mov    0x2e8b(%rip),%rax
mov    (%rax),%edx
lea    0xeaa(%rip),%rsi
call   1040 <fprintf@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [46 x i8] c"unable to send data on serial line erro = %d\0A\00"
@errno = global i32 0
define i32 @serial_write(i32 %0, i32* %1, i64 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i64
%8 = alloca i32
store i32 %0, i32* %5
store i32* %1, i32** %6
store i64 %2, i64* %7
%9 = load i32, i32* %5
%10 = load i32*, i32** %6
%11 = load i64, i64* %7
%12 = call i32 @write(i32 %9, i32* %10, i64 %11)
store i32 %12, i32* %8
%13 = load i32, i32* %8
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %19
15: ; preds = %3
%16 = load i32, i32* @stderr
%17 = load i32, i32* @errno
%18 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i32 %17)
br label %26
19: ; preds = %3
%20 = load i64, i64* %7
%21 = load i32, i32* %8
%22 = sext i32 %21 to i64
%23 = icmp eq i64 %20, %22
br i1 %23, label %24, label %25
24: ; preds = %19
store i32 1, i32* %4
br label %27
25: ; preds = %19
br label %26
26: ; preds = %25, %15
store i32 0, i32* %4
br label %27
27: ; preds = %26, %24
%28 = load i32, i32* %4
ret i32 %28
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [46 x i8] c"unable to send data on serial line erro = %d\0A\00"
@errno = global i32 0
define i32 @serial_write(i32 %0, i32* nocapture %1, i64 %2) {
%4 = tail call i32 @write(i32 %0, i32* %1, i64 %2)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %10
6: ; preds = %3
%7 = load i32, i32* @stderr
%8 = load i32, i32* @errno
%9 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i32 %8)
br label %13
10: ; preds = %3
%11 = sext i32 %4 to i64
%12 = icmp eq i64 %11, %2
br i1 %12, label %14, label %13
13: ; preds = %10, %6
br label %14
14: ; preds = %10, %13
%15 = phi i32 [ 0, %13 ], [ 1, %10 ]
ret i32 %15
}