int $Sub$$_sys_write(unsigned int fh, const unsigned char *buf,
                     unsigned int len, int mode) {
  unsigned int volatile *uart_base = (unsigned int *)0x40600000;
  int i;
  for (i = 0; i < len; i++) {
    while (*(uart_base + 11) & (1 << 14))
      ;
    *(uart_base + 12) = buf[i];
  }
  return 0;
}


x86 assembly (clang, -O0):
<$Sub$$_sys_write>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    $0x40600000,%eax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jae    116d <$Sub$$_sys_write+0x6d>
jmp    1132 <$Sub$$_sys_write+0x32>
mov    -0x20(%rbp),%rax
mov    0x2c(%rax),%eax
and    $0x4000,%eax
cmp    $0x0,%eax
je     114c <$Sub$$_sys_write+0x4c>
jmp    1132 <$Sub$$_sys_write+0x32>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movzbl (%rax,%rcx,1),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,0x30(%rax)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1121 <$Sub$$_sys_write+0x21>
xor    %eax,%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<$Sub$$_sys_write>:
test   %edx,%edx
je     1188 <$Sub$$_sys_write+0x88>
mov    %edx,%eax
cmp    $0x1,%edx
jne    1113 <$Sub$$_sys_write+0x13>
xor    %ecx,%ecx
jmp    1161 <$Sub$$_sys_write+0x61>
mov    %eax,%edx
and    $0xfffffffe,%edx
xor    %ecx,%ecx
nopw   0x0(%rax,%rax,1)
testl  $0x4000,0x4060002c
jne    1120 <$Sub$$_sys_write+0x20>
movzbl (%rsi,%rcx,1),%edi
mov    %edi,0x40600030
mov    %rcx,%rdi
or     $0x1,%rdi
nop
testl  $0x4000,0x4060002c
jne    1140 <$Sub$$_sys_write+0x40>
movzbl (%rsi,%rdi,1),%edi
mov    %edi,0x40600030
add    $0x2,%rcx
cmp    %rdx,%rcx
jne    1120 <$Sub$$_sys_write+0x20>
test   $0x1,%al
je     1188 <$Sub$$_sys_write+0x88>
cs nopw 0x0(%rax,%rax,1)
nop
testl  $0x4000,0x4060002c
jne    1170 <$Sub$$_sys_write+0x70>
movzbl (%rsi,%rcx,1),%eax
mov    %eax,0x40600030
xor    %eax,%eax
ret

LLVM IR (-O0):
define i32 @"$Sub$$_sys_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 i32
store i32 %0, i32* %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
store i32* inttoptr (i64 1080033280 to i32*), i32** %9
store i32 0, i32* %10
br label %11
11: ; preds = %32, %4
%12 = load i32, i32* %10
%13 = load i32, i32* %7
%14 = icmp ult i32 %12, %13
br i1 %14, label %15, label %35
15: ; preds = %11
br label %16
16: ; preds = %22, %15
%17 = load i32*, i32** %9
%18 = getelementptr inbounds i32, i32* %17, i64 11
%19 = load volatile i32, i32* %18
%20 = and i32 %19, 16384
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %16
br label %16
23: ; preds = %16
%24 = load i8*, i8** %6
%25 = load i32, i32* %10
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %24, i64 %26
%28 = load i8, i8* %27
%29 = zext i8 %28 to i32
%30 = load i32*, i32** %9
%31 = getelementptr inbounds i32, i32* %30, i64 12
store volatile i32 %29, i32* %31
br label %32
32: ; preds = %23
%33 = load i32, i32* %10
%34 = add nsw i32 %33, 1
store i32 %34, i32* %10
br label %11
35: ; preds = %11
ret i32 0
}

LLVM IR (-O2):
define i32 @"$Sub$$_sys_write"(i32 %0, i8* nocapture %1, i32 %2, i32 %3) {
%5 = icmp eq i32 %2, 0
br i1 %5, label %46, label %6
6: ; preds = %4
%7 = zext i32 %2 to i64
%8 = and i64 %7, 1
%9 = icmp eq i32 %2, 1
br i1 %9, label %35, label %10
10: ; preds = %6
%11 = and i64 %7, 4294967294
br label %12
12: ; preds = %28, %10
%13 = phi i64 [ 0, %10 ], [ %32, %28 ]
%14 = phi i64 [ 0, %10 ], [ %33, %28 ]
br label %15
15: ; preds = %12, %15
%16 = load volatile i32, i32* inttoptr (i64 1080033324 to i32*)
%17 = and i32 %16, 16384
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %15
19: ; preds = %15
%20 = getelementptr inbounds i8, i8* %1, i64 %13
%21 = load i8, i8* %20
%22 = zext i8 %21 to i32
store volatile i32 %22, i32* inttoptr (i64 1080033328 to i32*)
%23 = or i64 %13, 1
br label %24
24: ; preds = %24, %19
%25 = load volatile i32, i32* inttoptr (i64 1080033324 to i32*)
%26 = and i32 %25, 16384
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %24
28: ; preds = %24
%29 = getelementptr inbounds i8, i8* %1, i64 %23
%30 = load i8, i8* %29
%31 = zext i8 %30 to i32
store volatile i32 %31, i32* inttoptr (i64 1080033328 to i32*)
%32 = add nuw nsw i64 %13, 2
%33 = add i64 %14, 2
%34 = icmp eq i64 %33, %11
br i1 %34, label %35, label %12
35: ; preds = %28, %6
%36 = phi i64 [ 0, %6 ], [ %32, %28 ]
%37 = icmp eq i64 %8, 0
br i1 %37, label %46, label %38
38: ; preds = %35, %38
%39 = load volatile i32, i32* inttoptr (i64 1080033324 to i32*)
%40 = and i32 %39, 16384
%41 = icmp eq i32 %40, 0
br i1 %41, label %42, label %38
42: ; preds = %38
%43 = getelementptr inbounds i8, i8* %1, i64 %36
%44 = load i8, i8* %43
%45 = zext i8 %44 to i32
store volatile i32 %45, i32* inttoptr (i64 1080033328 to i32*)
br label %46
46: ; preds = %42, %35, %4
ret i32 0
}