int do_test2(const char *cmd) {
  struct prog_context *cnt = prog_exec(cmd, 0);
  struct dynamic_buffer *obuf = dynbuffer_new();
  struct dynamic_buffer *ebuf = dynbuffer_new();
  prog_communicate(cnt, "keyxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n\n", obuf,
                   ebuf, 5);
  printf("** xout: %s\n", dynbuffer_data(obuf));
  int ret = prog_wait(cnt);
  printf("** exit status: %d\n", ret);
  dynbuffer_free(obuf);
  dynbuffer_free(ebuf);
  progcnx_free(cnt);
  return 0;
}


x86 assembly (clang, -O0):
<do_test2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
mov    $0x0,%al
call   1030 <prog_exec@plt>
cltq
mov    %rax,-0x10(%rbp)
mov    $0x0,%al
call   1060 <dynbuffer_new@plt>
cltq
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   1060 <dynbuffer_new@plt>
cltq
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    0xe34(%rip),%rsi
mov    $0x5,%r8d
mov    $0x0,%al
call   1090 <prog_communicate@plt>
mov    -0x18(%rbp),%rdi
mov    $0x0,%al
call   1070 <dynbuffer_data@plt>
mov    %eax,%esi
lea    0xe3c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    $0x0,%al
call   1050 <prog_wait@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%esi
lea    0xe2a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    $0x0,%al
call   1080 <dynbuffer_free@plt>
mov    -0x20(%rbp),%rdi
mov    $0x0,%al
call   1080 <dynbuffer_free@plt>
mov    -0x10(%rbp),%rdi
mov    $0x0,%al
call   10a0 <progcnx_free@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_test2>:
push   %r15
push   %r14
push   %rbx
xor    %esi,%esi
xor    %eax,%eax
call   1030 <prog_exec@plt>
movslq %eax,%r14
xor    %eax,%eax
call   1060 <dynbuffer_new@plt>
movslq %eax,%rbx
xor    %eax,%eax
call   1060 <dynbuffer_new@plt>
movslq %eax,%r15
lea    0xe54(%rip),%rsi
mov    %r14,%rdi
mov    %rbx,%rdx
mov    %r15,%rcx
mov    $0x5,%r8d
xor    %eax,%eax
call   1090 <prog_communicate@plt>
mov    %rbx,%rdi
xor    %eax,%eax
call   1070 <dynbuffer_data@plt>
lea    0xe56(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <prog_wait@plt>
lea    0xe49(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
xor    %eax,%eax
call   1080 <dynbuffer_free@plt>
mov    %r15,%rdi
xor    %eax,%eax
call   1080 <dynbuffer_free@plt>
mov    %r14,%rdi
xor    %eax,%eax
call   10a0 <progcnx_free@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.prog_context = type opaque
%struct.dynamic_buffer = type opaque
@.str = [41 x i8] c"keyxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\0A\0A\00"
@.str.1 = [13 x i8] c"** xout: %s\0A\00"
@.str.2 = [20 x i8] c"** exit status: %d\0A\00"
define i32 @do_test2(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.prog_context*
%4 = alloca %struct.dynamic_buffer*
%5 = alloca %struct.dynamic_buffer*
%6 = alloca i32
store i8* %0, i8** %2
%7 = load i8*, i8** %2
%8 = call i32 (i8*, i32, ...) bitcast (i32 (...)* @prog_exec to i32 (i8*, i32, ...)*)(i8* %7, i32 0)
%9 = sext i32 %8 to i64
%10 = inttoptr i64 %9 to %struct.prog_context*
store %struct.prog_context* %10, %struct.prog_context** %3
%11 = call i32 (...) @dynbuffer_new()
%12 = sext i32 %11 to i64
%13 = inttoptr i64 %12 to %struct.dynamic_buffer*
store %struct.dynamic_buffer* %13, %struct.dynamic_buffer** %4
%14 = call i32 (...) @dynbuffer_new()
%15 = sext i32 %14 to i64
%16 = inttoptr i64 %15 to %struct.dynamic_buffer*
store %struct.dynamic_buffer* %16, %struct.dynamic_buffer** %5
%17 = load %struct.prog_context*, %struct.prog_context** %3
%18 = load %struct.dynamic_buffer*, %struct.dynamic_buffer** %4
%19 = load %struct.dynamic_buffer*, %struct.dynamic_buffer** %5
%20 = call i32 (%struct.prog_context*, i8*, %struct.dynamic_buffer*, %struct.dynamic_buffer*, i32, ...) bitcast (i32 (...)* @prog_communicate to i32 (%struct.prog_context*, i8*, %struct.dynamic_buffer*, %struct.dynamic_buffer*, i32, ...)*)(%struct.prog_context* %17, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), %struct.dynamic_buffer* %18, %struct.dynamic_buffer* %19, i32 5)
%21 = load %struct.dynamic_buffer*, %struct.dynamic_buffer** %4
%22 = call i32 (%struct.dynamic_buffer*, ...) bitcast (i32 (...)* @dynbuffer_data to i32 (%struct.dynamic_buffer*, ...)*)(%struct.dynamic_buffer* %21)
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %22)
%24 = load %struct.prog_context*, %struct.prog_context** %3
%25 = call i32 (%struct.prog_context*, ...) bitcast (i32 (...)* @prog_wait to i32 (%struct.prog_context*, ...)*)(%struct.prog_context* %24)
store i32 %25, i32* %6
%26 = load i32, i32* %6
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %26)
%28 = load %struct.dynamic_buffer*, %struct.dynamic_buffer** %4
%29 = call i32 (%struct.dynamic_buffer*, ...) bitcast (i32 (...)* @dynbuffer_free to i32 (%struct.dynamic_buffer*, ...)*)(%struct.dynamic_buffer* %28)
%30 = load %struct.dynamic_buffer*, %struct.dynamic_buffer** %5
%31 = call i32 (%struct.dynamic_buffer*, ...) bitcast (i32 (...)* @dynbuffer_free to i32 (%struct.dynamic_buffer*, ...)*)(%struct.dynamic_buffer* %30)
%32 = load %struct.prog_context*, %struct.prog_context** %3
%33 = call i32 (%struct.prog_context*, ...) bitcast (i32 (...)* @progcnx_free to i32 (%struct.prog_context*, ...)*)(%struct.prog_context* %32)
ret i32 0
}

LLVM IR (-O2):
%struct.prog_context = type opaque
%struct.dynamic_buffer = type opaque
@.str = [41 x i8] c"keyxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\0A\0A\00"
@.str.1 = [13 x i8] c"** xout: %s\0A\00"
@.str.2 = [20 x i8] c"** exit status: %d\0A\00"
define i32 @do_test2(i8* %0) {
%2 = tail call i32 (i8*, i32, ...) bitcast (i32 (...)* @prog_exec to i32 (i8*, i32, ...)*)(i8* %0, i32 0)
%3 = sext i32 %2 to i64
%4 = inttoptr i64 %3 to %struct.prog_context*
%5 = tail call i32 (...) @dynbuffer_new()
%6 = sext i32 %5 to i64
%7 = inttoptr i64 %6 to %struct.dynamic_buffer*
%8 = tail call i32 (...) @dynbuffer_new()
%9 = sext i32 %8 to i64
%10 = inttoptr i64 %9 to %struct.dynamic_buffer*
%11 = tail call i32 (%struct.prog_context*, i8*, %struct.dynamic_buffer*, %struct.dynamic_buffer*, i32, ...) bitcast (i32 (...)* @prog_communicate to i32 (%struct.prog_context*, i8*, %struct.dynamic_buffer*, %struct.dynamic_buffer*, i32, ...)*)(%struct.prog_context* %4, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), %struct.dynamic_buffer* %7, %struct.dynamic_buffer* %10, i32 5)
%12 = tail call i32 (%struct.dynamic_buffer*, ...) bitcast (i32 (...)* @dynbuffer_data to i32 (%struct.dynamic_buffer*, ...)*)(%struct.dynamic_buffer* %7)
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %12)
%14 = tail call i32 (%struct.prog_context*, ...) bitcast (i32 (...)* @prog_wait to i32 (%struct.prog_context*, ...)*)(%struct.prog_context* %4)
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %14)
%16 = tail call i32 (%struct.dynamic_buffer*, ...) bitcast (i32 (...)* @dynbuffer_free to i32 (%struct.dynamic_buffer*, ...)*)(%struct.dynamic_buffer* %7)
%17 = tail call i32 (%struct.dynamic_buffer*, ...) bitcast (i32 (...)* @dynbuffer_free to i32 (%struct.dynamic_buffer*, ...)*)(%struct.dynamic_buffer* %10)
%18 = tail call i32 (%struct.prog_context*, ...) bitcast (i32 (...)* @progcnx_free to i32 (%struct.prog_context*, ...)*)(%struct.prog_context* %4)
ret i32 0
}