#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;

/* Variables and functions */
int /*<<< orphan*/ usart_tx(int, char);
int _write(void *r, uint8_t *text, int len) {
  char *p = (char *)text;
  int i;
  (void)r;
  while (*p && (p < (char *)(text + len))) {
    usart_tx((0x40004400UL), *p);
    p++;
  }
  return len;
}


x86 assembly (clang, -O0):
<_write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x25(%rbp)
je     115c <_write+0x4c>
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
movslq -0x14(%rbp),%rdx
shl    $0x2,%rdx
add    %rdx,%rcx
cmp    %rcx,%rax
setb   %al
mov    %al,-0x25(%rbp)
mov    -0x25(%rbp),%al
test   $0x1,%al
jne    116c <_write+0x5c>
jmp    118e <_write+0x7e>
mov    -0x20(%rbp),%rax
mov    $0x40004400,%edi
movsbl (%rax),%esi
call   1030 <usart_tx@plt>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    112b <_write+0x1b>
mov    -0x14(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_write>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%r14d
mov    (%rsi),%al
test   %al,%al
je     1150 <_write+0x40>
test   %r14d,%r14d
jle    1150 <_write+0x40>
mov    %rsi,%rbx
movslq %r14d,%rcx
lea    (%rsi,%rcx,4),%rbp
add    $0x1,%rbx
movsbl %al,%esi
mov    $0x40004400,%edi
call   1030 <usart_tx@plt>
movzbl (%rbx),%eax
test   %al,%al
je     1150 <_write+0x40>
lea    0x1(%rbx),%rcx
cmp    %rbp,%rbx
mov    %rcx,%rbx
jb     1130 <_write+0x20>
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @_write(i8* %0, i32* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
store i8* %0, i8** %4
store i32* %1, i32** %5
store i32 %2, i32* %6
%9 = load i32*, i32** %5
%10 = bitcast i32* %9 to i8*
store i8* %10, i8** %7
%11 = load i8*, i8** %4
br label %12
12: ; preds = %27, %3
%13 = load i8*, i8** %7
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %25
17: ; preds = %12
%18 = load i8*, i8** %7
%19 = load i32*, i32** %5
%20 = load i32, i32* %6
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i32, i32* %19, i64 %21
%23 = bitcast i32* %22 to i8*
%24 = icmp ult i8* %18, %23
br label %25
25: ; preds = %17, %12
%26 = phi i1 [ false, %12 ], [ %24, %17 ]
br i1 %26, label %27, label %33
27: ; preds = %25
%28 = load i8*, i8** %7
%29 = load i8, i8* %28
%30 = call i32 @usart_tx(i32 1073759232, i8 signext %29)
%31 = load i8*, i8** %7
%32 = getelementptr inbounds i8, i8* %31, i32 1
store i8* %32, i8** %7
br label %12
33: ; preds = %25
%34 = load i32, i32* %6
ret i32 %34
}

LLVM IR (-O2):
define i32 @_write(i8* nocapture readnone %0, i32* %1, i32 returned %2) {
%4 = bitcast i32* %1 to i8*
%5 = sext i32 %2 to i64
%6 = getelementptr inbounds i32, i32* %1, i64 %5
%7 = bitcast i32* %6 to i8*
%8 = load i8, i8* %4
%9 = icmp ne i8 %8, 0
%10 = icmp sgt i32 %2, 0
%11 = and i1 %9, %10
br i1 %11, label %12, label %21
12: ; preds = %3, %12
%13 = phi i8 [ %17, %12 ], [ %8, %3 ]
%14 = phi i8* [ %16, %12 ], [ %4, %3 ]
%15 = tail call i32 @usart_tx(i32 1073759232, i8 signext %13)
%16 = getelementptr inbounds i8, i8* %14, i64 1
%17 = load i8, i8* %16
%18 = icmp ne i8 %17, 0
%19 = icmp ult i8* %16, %7
%20 = select i1 %18, i1 %19, i1 false
br i1 %20, label %12, label %21
21: ; preds = %12, %3
ret i32 %2
}