#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int /*<<< orphan*/ BIO;

/* Variables and functions */
int /*<<< orphan*/ BIO_flush(int /*<<< orphan*/ *);
int /*<<< orphan*/ BIO_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *BIO_new(int /*<<< orphan*/);
int /*<<< orphan*/ BIO_read(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ BIO_s_mem();
int /*<<< orphan*/ BIO_write(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ printf(char *, char *);
int main(void) {
  BIO *mem = NULL;
  char buf[128] = {0};
  mem = BIO_new(BIO_s_mem());
  BIO_write(mem, "ABCDE", 5);
  BIO_flush(mem);
  BIO_write(mem, "XYZ", 3);
  BIO_flush(mem);
  BIO_read(mem, buf, 128);
  printf("buf = %s\n", buf);
  BIO_free(mem);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
lea    -0x90(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1050 <memset@plt>
mov    $0x0,%al
call   1090 <BIO_s_mem@plt>
mov    %eax,%edi
call   1060 <BIO_new@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe36(%rip),%rsi
mov    $0x5,%edx
call   1080 <BIO_write@plt>
mov    -0x10(%rbp),%rdi
call   10a0 <BIO_flush@plt>
mov    -0x10(%rbp),%rdi
lea    0xe1e(%rip),%rsi
mov    $0x3,%edx
call   1080 <BIO_write@plt>
mov    -0x10(%rbp),%rdi
call   10a0 <BIO_flush@plt>
mov    -0x10(%rbp),%rdi
lea    -0x90(%rbp),%rsi
mov    $0x80,%edx
call   1030 <BIO_read@plt>
lea    -0x90(%rbp),%rsi
lea    0xdec(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1070 <BIO_free@plt>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x88,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
xor    %eax,%eax
call   1080 <BIO_s_mem@plt>
mov    %eax,%edi
call   1050 <BIO_new@plt>
mov    %rax,%rbx
lea    0xe44(%rip),%rsi
mov    %rax,%rdi
mov    $0x5,%edx
call   1070 <BIO_write@plt>
mov    %rbx,%rdi
call   1090 <BIO_flush@plt>
lea    0xe2e(%rip),%rsi
mov    %rbx,%rdi
mov    $0x3,%edx
call   1070 <BIO_write@plt>
mov    %rbx,%rdi
call   1090 <BIO_flush@plt>
mov    %rsp,%r14
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x80,%edx
call   1030 <BIO_read@plt>
lea    0xe03(%rip),%rdi
mov    %r14,%rsi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1060 <BIO_free@plt>
xor    %eax,%eax
add    $0x88,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [6 x i8] c"ABCDE\00"
@.str.1 = [4 x i8] c"XYZ\00"
@.str.2 = [10 x i8] c"buf = %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [128 x i8]
store i32 0, i32* %1
store i32* null, i32** %2
%4 = bitcast [128 x i8]* %3 to i8*
%5 = call i32 (...) @BIO_s_mem()
%6 = call i32* @BIO_new(i32 %5)
store i32* %6, i32** %2
%7 = load i32*, i32** %2
%8 = call i32 @BIO_write(i32* %7, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 5)
%9 = load i32*, i32** %2
%10 = call i32 @BIO_flush(i32* %9)
%11 = load i32*, i32** %2
%12 = call i32 @BIO_write(i32* %11, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 3)
%13 = load i32*, i32** %2
%14 = call i32 @BIO_flush(i32* %13)
%15 = load i32*, i32** %2
%16 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%17 = call i32 @BIO_read(i32* %15, i8* %16, i32 128)
%18 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%19 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %18)
%20 = load i32*, i32** %2
%21 = call i32 @BIO_free(i32* %20)
ret i32 0
}

LLVM IR (-O2):
@.str = [6 x i8] c"ABCDE\00"
@.str.1 = [4 x i8] c"XYZ\00"
@.str.2 = [10 x i8] c"buf = %s\0A\00"
define i32 @main() {
%1 = alloca [128 x i8]
%2 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%3 = tail call i32 (...) @BIO_s_mem()
%4 = tail call i32* @BIO_new(i32 %3)
%5 = tail call i32 @BIO_write(i32* %4, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 5)
%6 = tail call i32 @BIO_flush(i32* %4)
%7 = tail call i32 @BIO_write(i32* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 3)
%8 = tail call i32 @BIO_flush(i32* %4)
%9 = call i32 @BIO_read(i32* %4, i8* %2, i32 128)
%10 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %2)
%11 = call i32 @BIO_free(i32* %4)
ret i32 0
}