void puts(const char *s) {
  while (*s) {
    while ((*(volatile unsigned char *)0x206098) & (1 << (14)))
      barrier();
    (*(volatile unsigned char *)0x206040) = *s;
    if (*s == '\n') {
      while ((*(volatile unsigned char *)0x206098) & (1 << (14)))
        barrier();
      (*(volatile unsigned char *)0x206040) = '\r';
    }
    s++;
  }
  while ((*(volatile unsigned char *)0x206098) & (1 << (14)))
    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     11b1 <puts+0xa1>
jmp    112e <puts+0x1e>
mov    $0x206098,%eax
mov    (%rax),%al
movzbl %al,%eax
and    $0x4000,%eax
cmp    $0x0,%eax
je     1152 <puts+0x42>
mov    $0x0,%al
call   1030 <barrier@plt>
jmp    112e <puts+0x1e>
mov    -0x8(%rbp),%rax
mov    (%rax),%cl
mov    $0x206040,%eax
mov    %cl,(%rax)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
jne    11a0 <puts+0x90>
jmp    1174 <puts+0x64>
mov    $0x206098,%eax
mov    (%rax),%al
movzbl %al,%eax
and    $0x4000,%eax
cmp    $0x0,%eax
je     1198 <puts+0x88>
mov    $0x0,%al
call   1030 <barrier@plt>
jmp    1174 <puts+0x64>
mov    $0x206040,%eax
movb   $0xd,(%rax)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    111c <puts+0xc>
jmp    11b6 <puts+0xa6>
mov    $0x206098,%eax
mov    (%rax),%al
movzbl %al,%eax
and    $0x4000,%eax
cmp    $0x0,%eax
je     11da <puts+0xca>
mov    $0x0,%al
call   1030 <barrier@plt>
jmp    11b6 <puts+0xa6>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<puts>:
mov    (%rdi),%al
test   %al,%al
je     1142 <puts+0x42>
add    $0x1,%rdi
jmp    111b <puts+0x1b>
nopl   0x0(%rax)
movzbl (%rdi),%eax
add    $0x1,%rdi
test   %al,%al
je     1142 <puts+0x42>
movzbl 0x206098,%ecx
mov    %al,0x206040
cmpb   $0xa,-0x1(%rdi)
jne    1110 <puts+0x10>
movzbl 0x206098,%eax
movb   $0xd,0x206040
0d
jmp    1110 <puts+0x10>
mov    0x206098,%al
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 2121880 to i8*)
%10 = zext i8 %9 to i32
%11 = and i32 %10, 16384
%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 2121792 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 2121880 to i8*)
%25 = zext i8 %24 to i32
%26 = and i32 %25, 16384
%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 2121792 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 2121880 to i8*)
%37 = zext i8 %36 to i32
%38 = and i32 %37, 16384
%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 %16, label %4
4: ; preds = %1, %12
%5 = phi i8 [ %14, %12 ], [ %2, %1 ]
%6 = phi i8* [ %13, %12 ], [ %0, %1 ]
%7 = load volatile i8, i8* inttoptr (i64 2121880 to i8*)
store volatile i8 %5, i8* inttoptr (i64 2121792 to i8*)
%8 = load i8, i8* %6
%9 = icmp eq i8 %8, 10
br i1 %9, label %10, label %12
10: ; preds = %4
%11 = load volatile i8, i8* inttoptr (i64 2121880 to i8*)
store volatile i8 13, i8* inttoptr (i64 2121792 to i8*)
br label %12
12: ; preds = %10, %4
%13 = getelementptr inbounds i8, i8* %6, i64 1
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 0
br i1 %15, label %16, label %4
16: ; preds = %12, %1
%17 = load volatile i8, i8* inttoptr (i64 2121880 to i8*)
ret void
}