void puts(const char *s) {
  while (*s) {
    while ((*(volatile unsigned char *)0x16000018) & (1 << 5))
      barrier();
    (*(volatile unsigned char *)0x16000000) = *s;
    if (*s == '\n') {
      while ((*(volatile unsigned char *)0x16000018) & (1 << 5))
        barrier();
      (*(volatile unsigned char *)0x16000000) = '\r';
    }
    s++;
  }
  while ((*(volatile unsigned char *)0x16000018) & (1 << 3))
    ;
}


x86 assembly (clang, -O0):
<puts>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     11ad <puts+0x9d>
jmp    112e <puts+0x1e>
mov    $0x16000018,%eax
mov    (%rax),%al
movzbl %al,%eax
and    $0x20,%eax
cmp    $0x0,%eax
je     1150 <puts+0x40>
mov    $0x0,%al
call   1030 <barrier@plt>
jmp    112e <puts+0x1e>
mov    -0x8(%rbp),%rax
mov    (%rax),%cl
mov    $0x16000000,%eax
mov    %cl,(%rax)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
jne    119c <puts+0x8c>
jmp    1172 <puts+0x62>
mov    $0x16000018,%eax
mov    (%rax),%al
movzbl %al,%eax
and    $0x20,%eax
cmp    $0x0,%eax
je     1194 <puts+0x84>
mov    $0x0,%al
call   1030 <barrier@plt>
jmp    1172 <puts+0x62>
mov    $0x16000000,%eax
movb   $0xd,(%rax)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    111c <puts+0xc>
jmp    11b2 <puts+0xa2>
mov    $0x16000018,%eax
mov    (%rax),%al
movzbl %al,%eax
and    $0x8,%eax
cmp    $0x0,%eax
je     11cd <puts+0xbd>
jmp    11b2 <puts+0xa2>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<puts>:
push   %rbx
mov    (%rdi),%al
test   %al,%al
je     1180 <puts+0x70>
mov    %rdi,%rbx
jmp    1133 <puts+0x23>
nopl   0x0(%rax)
movb   $0xd,0x16000000
0d
mov    0x1(%rbx),%al
add    $0x1,%rbx
test   %al,%al
je     1180 <puts+0x70>
testb  $0x20,0x16000018
20
je     1153 <puts+0x43>
nopl   (%rax)
xor    %eax,%eax
call   1030 <barrier@plt>
testb  $0x20,0x16000018
20
jne    1140 <puts+0x30>
mov    (%rbx),%al
mov    %al,0x16000000
cmpb   $0xa,(%rbx)
jne    1128 <puts+0x18>
nop
testb  $0x20,0x16000018
20
je     1120 <puts+0x10>
xor    %eax,%eax
call   1030 <barrier@plt>
testb  $0x20,0x16000018
20
jne    116a <puts+0x5a>
jmp    1120 <puts+0x10>
nopl   (%rax)
testb  $0x8,0x16000018
08
jne    1180 <puts+0x70>
pop    %rbx
ret

LLVM IR (-O0):
define void @puts(i8* %0) {
%2 = alloca i8*
store i8* %0, i8** %2
br label %3
3: ; preds = %31, %1
%4 = load i8*, i8** %2
%5 = load i8, i8* %4
%6 = icmp ne i8 %5, 0
br i1 %6, label %7, label %34
7: ; preds = %3
br label %8
8: ; preds = %13, %7
%9 = load volatile i8, i8* inttoptr (i64 369098776 to i8*)
%10 = zext i8 %9 to i32
%11 = and i32 %10, 32
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %8
%14 = call i32 (...) @barrier()
br label %8
15: ; preds = %8
%16 = load i8*, i8** %2
%17 = load i8, i8* %16
store volatile i8 %17, i8* inttoptr (i64 369098752 to i8*)
%18 = load i8*, i8** %2
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %20, 10
br i1 %21, label %22, label %31
22: ; preds = %15
br label %23
23: ; preds = %28, %22
%24 = load volatile i8, i8* inttoptr (i64 369098776 to i8*)
%25 = zext i8 %24 to i32
%26 = and i32 %25, 32
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %23
%29 = call i32 (...) @barrier()
br label %23
30: ; preds = %23
store volatile i8 13, i8* inttoptr (i64 369098752 to i8*)
br label %31
31: ; preds = %30, %15
%32 = load i8*, i8** %2
%33 = getelementptr inbounds i8, i8* %32, i32 1
store i8* %33, i8** %2
br label %3
34: ; preds = %3
br label %35
35: ; preds = %40, %34
%36 = load volatile i8, i8* inttoptr (i64 369098776 to i8*)
%37 = zext i8 %36 to i32
%38 = and i32 %37, 8
%39 = icmp ne i32 %38, 0
br i1 %39, label %40, label %41
40: ; preds = %35
br label %35
41: ; preds = %35
ret void
}

LLVM IR (-O2):
define void @puts(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 0
br i1 %3, label %35, label %4
4: ; preds = %1, %31
%5 = phi i8 [ %33, %31 ], [ %2, %1 ]
%6 = phi i8* [ %32, %31 ], [ %0, %1 ]
%7 = load volatile i8, i8* inttoptr (i64 369098776 to i8*)
%8 = and i8 %7, 32
%9 = icmp eq i8 %8, 0
br i1 %9, label %17, label %10
10: ; preds = %4, %10
%11 = tail call i32 (...) @barrier()
%12 = load volatile i8, i8* inttoptr (i64 369098776 to i8*)
%13 = and i8 %12, 32
%14 = icmp eq i8 %13, 0
br i1 %14, label %15, label %10
15: ; preds = %10
%16 = load i8, i8* %6
br label %17
17: ; preds = %15, %4
%18 = phi i8 [ %16, %15 ], [ %5, %4 ]
store volatile i8 %18, i8* inttoptr (i64 369098752 to i8*)
%19 = load i8, i8* %6
%20 = icmp eq i8 %19, 10
br i1 %20, label %21, label %31
21: ; preds = %17
%22 = load volatile i8, i8* inttoptr (i64 369098776 to i8*)
%23 = and i8 %22, 32
%24 = icmp eq i8 %23, 0
br i1 %24, label %30, label %25
25: ; preds = %21, %25
%26 = tail call i32 (...) @barrier()
%27 = load volatile i8, i8* inttoptr (i64 369098776 to i8*)
%28 = and i8 %27, 32
%29 = icmp eq i8 %28, 0
br i1 %29, label %30, label %25
30: ; preds = %25, %21
store volatile i8 13, i8* inttoptr (i64 369098752 to i8*)
br label %31
31: ; preds = %30, %17
%32 = getelementptr inbounds i8, i8* %6, i64 1
%33 = load i8, i8* %32
%34 = icmp eq i8 %33, 0
br i1 %34, label %35, label %4
35: ; preds = %31, %1
br label %36
36: ; preds = %35, %36
%37 = load volatile i8, i8* inttoptr (i64 369098776 to i8*)
%38 = and i8 %37, 8
%39 = icmp eq i8 %38, 0
br i1 %39, label %40, label %36
40: ; preds = %36
ret void
}