#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*/ serial_write(int, char const);
int serial_device_write(int unit, const void *data, int length, int offset) {
  int i;
  const char *cdata = data;
  for (i = 0; i < length; i++) {
    serial_write(unit, cdata[i]);
  }
  return length;
}


x86 assembly (clang, -O0):
<serial_device_write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1162 <serial_device_write+0x52>
mov    -0x4(%rbp),%edi
mov    -0x28(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
call   1030 <serial_write@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1134 <serial_device_write+0x24>
mov    -0x14(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<serial_device_write>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r14d
test   %edx,%edx
jle    1146 <serial_device_write+0x36>
mov    %rsi,%r15
mov    %edi,%r12d
mov    %r14d,%ebx
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
movsbl (%r15,%rbp,1),%esi
mov    %r12d,%edi
call   1030 <serial_write@plt>
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    1130 <serial_device_write+0x20>
mov    %r14d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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