void task1_function(void *data) {
  char **msg = (char **)data;
  char buffer[256];
  while (1) {
    unsigned count;
    while (*msg) {
      __asm__ volatile("" ::: "memory");
      schedule();
    }
    count = serial_read(buffer, sizeof(buffer) - 1);
    buffer[count] = 0;
    if (count)
      *msg = buffer;
  }
}


x86 assembly (clang, -O0):
<task1_function>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
jmp    113c <task1_function+0x1c>
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
je     1156 <task1_function+0x36>
mov    $0x0,%al
call   1030 <schedule@plt>
jmp    113c <task1_function+0x1c>
lea    -0x110(%rbp),%rdi
mov    $0xff,%esi
mov    $0x0,%al
call   1040 <serial_read@plt>
mov    %eax,-0x114(%rbp)
mov    -0x114(%rbp),%eax
movb   $0x0,-0x110(%rbp,%rax,1)
cmpl   $0x0,-0x114(%rbp)
je     1198 <task1_function+0x78>
lea    -0x110(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
jmp    1137 <task1_function+0x17>

x86 assembly (clang, -O2):
<task1_function>:
push   %r14
push   %rbx
sub    $0x108,%rsp
mov    %rdi,%rbx
mov    %rsp,%r14
jmp    1147 <task1_function+0x27>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %eax,%eax
call   1030 <schedule@plt>
cmpq   $0x0,(%rbx)
jne    1140 <task1_function+0x20>
mov    $0xff,%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <serial_read@plt>
mov    %eax,%ecx
movb   $0x0,(%rsp,%rcx,1)
test   %eax,%eax
je     1147 <task1_function+0x27>
mov    %r14,(%rbx)
jmp    1147 <task1_function+0x27>

LLVM IR (-O0):
define void @task1_function(i8* %0) {
%2 = alloca i8*
%3 = alloca i8**
%4 = alloca [256 x i8]
%5 = alloca i32
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = bitcast i8* %6 to i8**
store i8** %7, i8*** %3
br label %8
8: ; preds = %1, %26
br label %9
9: ; preds = %13, %8
%10 = load i8**, i8*** %3
%11 = load i8*, i8** %10
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %15
13: ; preds = %9
%14 = call i32 (...) @schedule()
br label %9
15: ; preds = %9
%16 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%17 = call i32 (i8*, i64, ...) bitcast (i32 (...)* @serial_read to i32 (i8*, i64, ...)*)(i8* %16, i64 255)
store i32 %17, i32* %5
%18 = load i32, i32* %5
%19 = zext i32 %18 to i64
%20 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 %19
store i8 0, i8* %20
%21 = load i32, i32* %5
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %15
%24 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%25 = load i8**, i8*** %3
store i8* %24, i8** %25
br label %26
26: ; preds = %23, %15
br label %8
}

LLVM IR (-O2):
define void @task1_function(i8* nocapture %0) {
%2 = alloca [256 x i8]
%3 = bitcast i8* %0 to i8**
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
br label %5
5: ; preds = %18, %1
%6 = load i8*, i8** %3
%7 = icmp eq i8* %6, null
br i1 %7, label %12, label %8
8: ; preds = %5, %8
%9 = call i32 (...) @schedule()
%10 = load i8*, i8** %3
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %8
12: ; preds = %8, %5
%13 = call i32 (i8*, i64, ...) bitcast (i32 (...)* @serial_read to i32 (i8*, i64, ...)*)(i8* %4, i64 255)
%14 = zext i32 %13 to i64
%15 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 %14
store i8 0, i8* %15
%16 = icmp eq i32 %13, 0
br i1 %16, label %18, label %17
17: ; preds = %12
store i8* %4, i8** %3
br label %18
18: ; preds = %17, %12
br label %5
}