#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*/ TCOFLUSH;
int /*<<< orphan*/ tcflush(int, int /*<<< orphan*/);
int /*<<< orphan*/ write(int, char *, int);
int UART_Send(int fd, char *send_buf, int data_len) {
  for (int i = 0; i < data_len; i++) {
    write(fd, send_buf + i, 1);
    tcflush(fd, TCOFLUSH);
  }
}


x86 assembly (clang, -O0):
<UART_Send>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    117c <UART_Send+0x5c>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
movslq -0x18(%rbp),%rax
add    %rax,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    -0x8(%rbp),%edi
mov    0x2e89(%rip),%rax
mov    (%rax),%esi
call   1040 <tcflush@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1139 <UART_Send+0x19>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<UART_Send>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %edx,%edx
jle    1165 <UART_Send+0x45>
mov    %rsi,%rbx
mov    %edi,%r14d
mov    %edx,%ebp
mov    0x2eb6(%rip),%r15
nopw   0x0(%rax,%rax,1)
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    (%r15),%esi
mov    %r14d,%edi
call   1040 <tcflush@plt>
add    $0x1,%rbx
add    $0xffffffffffffffff,%rbp
jne    1140 <UART_Send+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@TCOFLUSH = global i32 0
define i32 @UART_Send(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32 0, i32* %8
br label %9
9: ; preds = %23, %3
%10 = load i32, i32* %8
%11 = load i32, i32* %7
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %26
13: ; preds = %9
%14 = load i32, i32* %5
%15 = load i8*, i8** %6
%16 = load i32, i32* %8
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %15, i64 %17
%19 = call i32 @write(i32 %14, i8* %18, i32 1)
%20 = load i32, i32* %5
%21 = load i32, i32* @TCOFLUSH
%22 = call i32 @tcflush(i32 %20, i32 %21)
br label %23
23: ; preds = %13
%24 = load i32, i32* %8
%25 = add nsw i32 %24, 1
store i32 %25, i32* %8
br label %9
26: ; preds = %9
%27 = load i32, i32* %4
ret i32 %27
}

LLVM IR (-O2):
@TCOFLUSH = global i32 0
define i32 @UART_Send(i32 %0, i8* nocapture %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %5, label %7
5: ; preds = %3
%6 = zext i32 %2 to i64
br label %8
7: ; preds = %8, %3
ret i32 undef
8: ; preds = %5, %8
%9 = phi i64 [ 0, %5 ], [ %14, %8 ]
%10 = getelementptr inbounds i8, i8* %1, i64 %9
%11 = tail call i32 @write(i32 %0, i8* %10, i32 1)
%12 = load i32, i32* @TCOFLUSH
%13 = tail call i32 @tcflush(i32 %0, i32 %12)
%14 = add nuw nsw i64 %9, 1
%15 = icmp eq i64 %14, %6
br i1 %15, label %7, label %8
}