void *test1_coro(void *arg) {
  int idx = 0;
  char buf[1024];
  char *s;
  idx = snprintf(buf + idx, sizeof(buf) - idx, "%s ", (char *)arg);
  s = coro_yield("works!");
  idx = snprintf(buf + idx, sizeof(buf) - idx, "%s\n", (char *)s);
  printf("%s", buf);
  return "done";
}


x86 assembly (clang, -O0):
<test1_coro>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
lea    -0x410(%rbp),%rdi
movslq -0xc(%rbp),%rax
add    %rax,%rdi
movslq -0xc(%rbp),%rax
mov    $0x400,%esi
sub    %rax,%rsi
mov    -0x8(%rbp),%rcx
lea    0xe95(%rip),%rdx
mov    $0x0,%al
call   1050 <snprintf@plt>
mov    %eax,-0xc(%rbp)
lea    0xe88(%rip),%rdi
mov    $0x0,%al
call   1030 <coro_yield@plt>
cltq
mov    %rax,-0x418(%rbp)
lea    -0x410(%rbp),%rdi
movslq -0xc(%rbp),%rax
add    %rax,%rdi
movslq -0xc(%rbp),%rax
mov    $0x400,%esi
sub    %rax,%rsi
mov    -0x418(%rbp),%rcx
lea    0xe57(%rip),%rdx
mov    $0x0,%al
call   1050 <snprintf@plt>
mov    %eax,-0xc(%rbp)
lea    -0x410(%rbp),%rsi
lea    0xe43(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe38(%rip),%rax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test1_coro>:
push   %rbp
push   %r14
push   %rbx
sub    $0x400,%rsp
mov    %rdi,%rcx
lea    0xebb(%rip),%rdx
mov    %rsp,%r14
mov    $0x400,%ebx
mov    $0x400,%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <snprintf@plt>
mov    %eax,%ebp
lea    0xe9f(%rip),%rdi
xor    %eax,%eax
call   1030 <coro_yield@plt>
movslq %eax,%rcx
movslq %ebp,%rax
lea    (%rsp,%rax,1),%rdi
sub    %rax,%rbx
lea    0xe8b(%rip),%rdx
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <snprintf@plt>
lea    0xe7e(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe70(%rip),%rax
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%s \00"
@.str.1 = [7 x i8] c"works!\00"
@.str.2 = [4 x i8] c"%s\0A\00"
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [5 x i8] c"done\00"
define i8* @test1_coro(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca [1024 x i8]
%5 = alloca i8*
store i8* %0, i8** %2
store i32 0, i32* %3
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%7 = load i32, i32* %3
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds i8, i8* %6, i64 %8
%10 = load i32, i32* %3
%11 = sext i32 %10 to i64
%12 = sub i64 1024, %11
%13 = load i8*, i8** %2
%14 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %9, i64 %12, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %13)
store i32 %14, i32* %3
%15 = call i32 (i8*, ...) bitcast (i32 (...)* @coro_yield to i32 (i8*, ...)*)(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%16 = sext i32 %15 to i64
%17 = inttoptr i64 %16 to i8*
store i8* %17, i8** %5
%18 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%19 = load i32, i32* %3
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %18, i64 %20
%22 = load i32, i32* %3
%23 = sext i32 %22 to i64
%24 = sub i64 1024, %23
%25 = load i8*, i8** %5
%26 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %21, i64 %24, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %25)
store i32 %26, i32* %3
%27 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %27)
ret i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0)
}

LLVM IR (-O2):
@.str = [4 x i8] c"%s \00"
@.str.1 = [7 x i8] c"works!\00"
@.str.2 = [4 x i8] c"%s\0A\00"
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [5 x i8] c"done\00"
define i8* @test1_coro(i8* %0) {
%2 = alloca [1024 x i8]
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%4 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %3, i64 1024, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %0)
%5 = tail call i32 (i8*, ...) bitcast (i32 (...)* @coro_yield to i32 (i8*, ...)*)(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%6 = sext i32 %5 to i64
%7 = inttoptr i64 %6 to i8*
%8 = sext i32 %4 to i64
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 %8
%10 = sub nsw i64 1024, %8
%11 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %9, i64 %10, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %7)
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %3)
ret i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0)
}