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


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    $0x101f1018,%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    $0x101f1000,%eax
mov    %cl,(%rax)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
jne    119c <puts+0x8c>
jmp    1172 <puts+0x62>
mov    $0x101f1018,%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    $0x101f1000,%eax
movb   $0xd,(%rax)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    111c <puts+0xc>
jmp    11b2 <puts+0xa2>
mov    $0x101f1018,%eax
mov    (%rax),%al
movzbl %al,%eax
and    $0x8,%eax
cmp    $0x0,%eax
je     11d4 <puts+0xc4>
mov    $0x0,%al
call   1030 <barrier@plt>
jmp    11b2 <puts+0xa2>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<puts>:
push   %rbx
mov    (%rdi),%al
test   %al,%al
je     1187 <puts+0x77>
mov    %rdi,%rbx
jmp    1133 <puts+0x23>
nopl   0x0(%rax)
movb   $0xd,0x101f1000
0d
mov    0x1(%rbx),%al
add    $0x1,%rbx
test   %al,%al
je     1187 <puts+0x77>
testb  $0x20,0x101f1018
20
je     1153 <puts+0x43>
nopl   (%rax)
xor    %eax,%eax
call   1030 <barrier@plt>
testb  $0x20,0x101f1018
20
jne    1140 <puts+0x30>
mov    (%rbx),%al
mov    %al,0x101f1000
cmpb   $0xa,(%rbx)
jne    1128 <puts+0x18>
nop
testb  $0x20,0x101f1018
20
je     1120 <puts+0x10>
xor    %eax,%eax
call   1030 <barrier@plt>
testb  $0x20,0x101f1018
20
jne    116a <puts+0x5a>
jmp    1120 <puts+0x10>
nopl   (%rax)
xor    %eax,%eax
call   1030 <barrier@plt>
testb  $0x8,0x101f1018
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 270471192 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 270471168 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 270471192 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 270471168 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 270471192 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 %42
40: ; preds = %35
%41 = call i32 (...) @barrier()
br label %35
42: ; 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 %10, label %4
4: ; preds = %1, %35
%5 = phi i8 [ %37, %35 ], [ %2, %1 ]
%6 = phi i8* [ %36, %35 ], [ %0, %1 ]
%7 = load volatile i8, i8* inttoptr (i64 270471192 to i8*)
%8 = and i8 %7, 32
%9 = icmp eq i8 %8, 0
br i1 %9, label %21, label %14
10: ; preds = %35, %1
%11 = load volatile i8, i8* inttoptr (i64 270471192 to i8*)
%12 = and i8 %11, 8
%13 = icmp eq i8 %12, 0
br i1 %13, label %44, label %39
14: ; preds = %4, %14
%15 = tail call i32 (...) @barrier()
%16 = load volatile i8, i8* inttoptr (i64 270471192 to i8*)
%17 = and i8 %16, 32
%18 = icmp eq i8 %17, 0
br i1 %18, label %19, label %14
19: ; preds = %14
%20 = load i8, i8* %6
br label %21
21: ; preds = %19, %4
%22 = phi i8 [ %20, %19 ], [ %5, %4 ]
store volatile i8 %22, i8* inttoptr (i64 270471168 to i8*)
%23 = load i8, i8* %6
%24 = icmp eq i8 %23, 10
br i1 %24, label %25, label %35
25: ; preds = %21
%26 = load volatile i8, i8* inttoptr (i64 270471192 to i8*)
%27 = and i8 %26, 32
%28 = icmp eq i8 %27, 0
br i1 %28, label %34, label %29
29: ; preds = %25, %29
%30 = tail call i32 (...) @barrier()
%31 = load volatile i8, i8* inttoptr (i64 270471192 to i8*)
%32 = and i8 %31, 32
%33 = icmp eq i8 %32, 0
br i1 %33, label %34, label %29
34: ; preds = %29, %25
store volatile i8 13, i8* inttoptr (i64 270471168 to i8*)
br label %35
35: ; preds = %34, %21
%36 = getelementptr inbounds i8, i8* %6, i64 1
%37 = load i8, i8* %36
%38 = icmp eq i8 %37, 0
br i1 %38, label %10, label %4
39: ; preds = %10, %39
%40 = tail call i32 (...) @barrier()
%41 = load volatile i8, i8* inttoptr (i64 270471192 to i8*)
%42 = and i8 %41, 8
%43 = icmp eq i8 %42, 0
br i1 %43, label %44, label %39
44: ; preds = %39, %10
ret void
}