#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*/ size;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sleep(int);
int strlen(unsigned char *);
int write(int, ...);
void UARTwrite(unsigned char *buffer, int uart_descriptor) {
  int size = strlen(buffer);
  int count = write(uart_descriptor, &size, sizeof(size));
  printf("[Send] %s", buffer);
  sleep(1);
  count = write(uart_descriptor, buffer, size);
  if (count < 0) {
    printf("UART TX error\n");
  }
}


x86 assembly (clang, -O0):
<UARTwrite>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x10(%rbp),%rsi
mov    $0x4,%edx
mov    $0x0,%al
call   1030 <write@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xe84(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   1060 <sleep@plt>
mov    -0xc(%rbp),%edi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%edx
mov    $0x0,%al
call   1030 <write@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11b9 <UARTwrite+0x79>
lea    0xe58(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<UARTwrite>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
call   1050 <strlen@plt>
mov    %eax,0x4(%rsp)
lea    0x4(%rsp),%rsi
mov    $0x4,%edx
mov    %ebp,%edi
xor    %eax,%eax
call   1040 <write@plt>
lea    0xe85(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%edi
call   1070 <sleep@plt>
mov    0x4(%rsp),%edx
mov    %ebp,%edi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <write@plt>
test   %eax,%eax
jns    11af <UARTwrite+0x5f>
lea    0xe60(%rip),%rdi
call   1030 <puts@plt>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"[Send] %s\00"
@.str.1 = [15 x i8] c"UART TX error\0A\00"
define void @UARTwrite(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%7 = load i8*, i8** %3
%8 = call i32 @strlen(i8* %7)
store i32 %8, i32* %5
%9 = load i32, i32* %4
%10 = call i32 (i32, ...) @write(i32 %9, i32* %5, i64 4)
store i32 %10, i32* %6
%11 = load i8*, i8** %3
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = call i32 @sleep(i32 1)
%14 = load i32, i32* %4
%15 = load i8*, i8** %3
%16 = load i32, i32* %5
%17 = call i32 (i32, ...) @write(i32 %14, i8* %15, i32 %16)
store i32 %17, i32* %6
%18 = load i32, i32* %6
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %2
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %22
22: ; preds = %20, %2
ret void
}

LLVM IR (-O2):
@.str = [10 x i8] c"[Send] %s\00"
@str = [14 x i8] c"UART TX error\00"
define void @UARTwrite(i8* %0, i32 %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = tail call i32 @strlen(i8* %0)
store i32 %5, i32* %3
%6 = call i32 (i32, ...) @write(i32 %1, i32* %3, i64 4)
%7 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %0)
%8 = call i32 @sleep(i32 1)
%9 = load i32, i32* %3
%10 = call i32 (i32, ...) @write(i32 %1, i8* %0, i32 %9)
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
br label %14
14: ; preds = %12, %2
ret void
}