#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 */
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
typedef int /*<<< orphan*/ str;
typedef int /*<<< orphan*/ buf;
struct TYPE_3__ {
  int length;
  char *data;
  int max;
};
typedef TYPE_1__ BUF_MEM;
typedef int /*<<< orphan*/ BIO;

/* Variables and functions */
int /*<<< orphan*/ BIO_FLAGS_MEM_RDONLY;
int /*<<< orphan*/ BIO_NOCLOSE;
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_set_flags(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ BIO_set_mem_buf(int /*<<< orphan*/ *, TYPE_1__ *,
                                   int /*<<< orphan*/);
int /*<<< orphan*/ test_int_eq(char *, int, char *, char *, int /*<<< orphan*/,
                               int);
int /*<<< orphan*/ test_mem_eq(char *, int, char *, char *, char *, int,
                               char const *, int);
int /*<<< orphan*/ test_ptr(char *, int, char *, int /*<<< orphan*/ *);
int test_bio_memleak(void) {
  int ok = 0;
  BIO *bio;
  BUF_MEM bufmem;
  static const char str[] = "BIO test\n";
  char buf[100];
  bio = BIO_new(BIO_s_mem());
  if (!test_ptr("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                "outputs/2022-01-22/02-19-57/repos/jens-maus/amissl/refs/heads/"
                "master/openssl/test/bio_memleak_test.c",
                27, "bio", bio))
    goto finish;
  bufmem.length = sizeof(str);
  bufmem.data = (char *)str;
  bufmem.max = bufmem.length;
  BIO_set_mem_buf(bio, &bufmem, BIO_NOCLOSE);
  BIO_set_flags(bio, BIO_FLAGS_MEM_RDONLY);
  if (!test_int_eq("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                   "outputs/2022-01-22/02-19-57/repos/jens-maus/amissl/refs/"
                   "heads/master/openssl/test/bio_memleak_test.c",
                   34, "BIO_read(bio, buf, sizeof(buf))", "sizeof(str)",
                   BIO_read(bio, buf, sizeof(buf)), sizeof(str)))
    goto finish;
  if (!test_mem_eq("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                   "outputs/2022-01-22/02-19-57/repos/jens-maus/amissl/refs/"
                   "heads/master/openssl/test/bio_memleak_test.c",
                   36, "buf", "str", buf, sizeof(str), str, sizeof(str)))
    goto finish;
  ok = 1;
finish:
  BIO_free(bio);
  return ok;
}


x86 assembly (clang, -O0):
<test_bio_memleak>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   10a0 <BIO_s_mem@plt>
mov    %eax,%edi
call   1070 <BIO_new@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rcx
lea    0xe4b(%rip),%rdi
mov    $0x1b,%esi
lea    0xedc(%rip),%rdx
call   1040 <test_ptr@plt>
cmp    $0x0,%eax
jne    11de <test_bio_memleak+0x4e>
jmp    12bd <test_bio_memleak+0x12d>
movl   $0xa,-0x28(%rbp)
lea    0xe14(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2de7(%rip),%rax
mov    (%rax),%edx
lea    -0x28(%rbp),%rsi
call   10b0 <BIO_set_mem_buf@plt>
mov    -0x10(%rbp),%rdi
mov    0x2dc1(%rip),%rax
mov    (%rax),%esi
call   1060 <BIO_set_flags@plt>
mov    -0x10(%rbp),%rdi
lea    -0x90(%rbp),%rsi
mov    $0x64,%edx
call   1030 <BIO_read@plt>
mov    %eax,%r8d
lea    0xdcd(%rip),%rdi
mov    $0x22,%esi
lea    0xe62(%rip),%rdx
lea    0xe7b(%rip),%rcx
mov    $0xa,%r9d
call   1050 <test_int_eq@plt>
cmp    $0x0,%eax
jne    1269 <test_bio_memleak+0xd9>
jmp    12bd <test_bio_memleak+0x12d>
lea    -0x90(%rbp),%r8
lea    0xd93(%rip),%rdi
mov    $0x24,%esi
lea    0xe54(%rip),%rdx
lea    0xe51(%rip),%rcx
mov    $0xa,%r9d
lea    0xd69(%rip),%rax
mov    %rax,(%rsp)
movl   $0xa,0x8(%rsp)
call   1090 <test_mem_eq@plt>
cmp    $0x0,%eax
jne    12b6 <test_bio_memleak+0x126>
jmp    12bd <test_bio_memleak+0x12d>
movl   $0x1,-0x4(%rbp)
mov    -0x10(%rbp),%rdi
call   1080 <BIO_free@plt>
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_bio_memleak>:
push   %rbp
push   %r14
push   %rbx
sub    $0x90,%rsp
xor    %ebp,%ebp
xor    %eax,%eax
call   10a0 <BIO_s_mem@plt>
mov    %eax,%edi
call   1070 <BIO_new@plt>
mov    %rax,%rbx
lea    0xe55(%rip),%rdi
lea    0xeeb(%rip),%rdx
mov    $0x1b,%esi
mov    %rax,%rcx
call   1040 <test_ptr@plt>
test   %eax,%eax
je     128c <test_bio_memleak+0xfc>
movl   $0xa,0x8(%rsp)
lea    0xe20(%rip),%r14
mov    %r14,0x10(%rsp)
movl   $0xa,0x18(%rsp)
mov    0x2df4(%rip),%rax
mov    (%rax),%edx
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   10b0 <BIO_set_mem_buf@plt>
mov    0x2dce(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1060 <BIO_set_flags@plt>
lea    0x20(%rsp),%rsi
mov    %rbx,%rdi
mov    $0x64,%edx
call   1030 <BIO_read@plt>
lea    0xddd(%rip),%rdi
lea    0xe77(%rip),%rdx
lea    0xe90(%rip),%rcx
mov    $0x22,%esi
mov    %eax,%r8d
mov    $0xa,%r9d
call   1050 <test_int_eq@plt>
test   %eax,%eax
je     128c <test_bio_memleak+0xfc>
lea    0xdb1(%rip),%rdi
lea    0xe77(%rip),%rdx
lea    0xe74(%rip),%rcx
lea    0x20(%rsp),%r8
mov    $0x24,%esi
mov    $0xa,%r9d
push   $0xa
push   %r14
call   1090 <test_mem_eq@plt>
add    $0x10,%rsp
xor    %ebp,%ebp
test   %eax,%eax
setne  %bpl
mov    %rbx,%rdi
call   1080 <BIO_free@plt>
mov    %ebp,%eax
add    $0x90,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_3__ = type { i32, i8*, i32 }
@test_bio_memleak.str = internal constant [10 x i8] c"BIO test\0A\00"
@.str = [157 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/jens-maus/amissl/refs/heads/master/openssl/test/bio_memleak_test.c\00"
@.str.1 = [4 x i8] c"bio\00"
@BIO_NOCLOSE = global i32 0
@BIO_FLAGS_MEM_RDONLY = global i32 0
@.str.2 = [32 x i8] c"BIO_read(bio, buf, sizeof(buf))\00"
@.str.3 = [12 x i8] c"sizeof(str)\00"
@.str.4 = [4 x i8] c"buf\00"
@.str.5 = [4 x i8] c"str\00"
define i32 @test_bio_memleak() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca %struct.TYPE_3__
%4 = alloca [100 x i8]
store i32 0, i32* %1
%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 @test_ptr(i8* getelementptr inbounds ([157 x i8], [157 x i8]* @.str, i64 0, i64 0), i32 27, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32* %7)
%9 = icmp ne i32 %8, 0
br i1 %9, label %11, label %10
10: ; preds = %0
br label %35
11: ; preds = %0
%12 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %3, i32 0, i32 0
store i32 10, i32* %12
%13 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %3, i32 0, i32 1
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @test_bio_memleak.str, i64 0, i64 0), i8** %13
%14 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %3, i32 0, i32 0
%15 = load i32, i32* %14
%16 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %3, i32 0, i32 2
store i32 %15, i32* %16
%17 = load i32*, i32** %2
%18 = load i32, i32* @BIO_NOCLOSE
%19 = call i32 @BIO_set_mem_buf(i32* %17, %struct.TYPE_3__* %3, i32 %18)
%20 = load i32*, i32** %2
%21 = load i32, i32* @BIO_FLAGS_MEM_RDONLY
%22 = call i32 @BIO_set_flags(i32* %20, i32 %21)
%23 = load i32*, i32** %2
%24 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%25 = call i32 @BIO_read(i32* %23, i8* %24, i32 100)
%26 = call i32 @test_int_eq(i8* getelementptr inbounds ([157 x i8], [157 x i8]* @.str, i64 0, i64 0), i32 34, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 %25, i32 10)
%27 = icmp ne i32 %26, 0
br i1 %27, label %29, label %28
28: ; preds = %11
br label %35
29: ; preds = %11
%30 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%31 = call i32 @test_mem_eq(i8* getelementptr inbounds ([157 x i8], [157 x i8]* @.str, i64 0, i64 0), i32 36, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %30, i32 10, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @test_bio_memleak.str, i64 0, i64 0), i32 10)
%32 = icmp ne i32 %31, 0
br i1 %32, label %34, label %33
33: ; preds = %29
br label %35
34: ; preds = %29
store i32 1, i32* %1
br label %35
35: ; preds = %34, %33, %28, %10
%36 = load i32*, i32** %2
%37 = call i32 @BIO_free(i32* %36)
%38 = load i32, i32* %1
ret i32 %38
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i32, i8*, i32 }
@test_bio_memleak.str = internal constant [10 x i8] c"BIO test\0A\00"
@.str = [157 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/jens-maus/amissl/refs/heads/master/openssl/test/bio_memleak_test.c\00"
@.str.1 = [4 x i8] c"bio\00"
@BIO_NOCLOSE = global i32 0
@BIO_FLAGS_MEM_RDONLY = global i32 0
@.str.2 = [32 x i8] c"BIO_read(bio, buf, sizeof(buf))\00"
@.str.3 = [12 x i8] c"sizeof(str)\00"
@.str.4 = [4 x i8] c"buf\00"
@.str.5 = [4 x i8] c"str\00"
define i32 @test_bio_memleak() {
%1 = alloca %struct.TYPE_3__
%2 = alloca [100 x i8]
%3 = bitcast %struct.TYPE_3__* %1 to i8*
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%5 = tail call i32 (...) @BIO_s_mem()
%6 = tail call i32* @BIO_new(i32 %5)
%7 = tail call i32 @test_ptr(i8* getelementptr inbounds ([157 x i8], [157 x i8]* @.str, i64 0, i64 0), i32 27, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32* %6)
%8 = icmp eq i32 %7, 0
br i1 %8, label %24, label %9
9: ; preds = %0
%10 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %1, i64 0, i32 0
store i32 10, i32* %10
%11 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %1, i64 0, i32 1
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @test_bio_memleak.str, i64 0, i64 0), i8** %11
%12 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %1, i64 0, i32 2
store i32 10, i32* %12
%13 = load i32, i32* @BIO_NOCLOSE
%14 = call i32 @BIO_set_mem_buf(i32* %6, %struct.TYPE_3__* %1, i32 %13)
%15 = load i32, i32* @BIO_FLAGS_MEM_RDONLY
%16 = call i32 @BIO_set_flags(i32* %6, i32 %15)
%17 = call i32 @BIO_read(i32* %6, i8* %4, i32 100)
%18 = call i32 @test_int_eq(i8* getelementptr inbounds ([157 x i8], [157 x i8]* @.str, i64 0, i64 0), i32 34, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 %17, i32 10)
%19 = icmp eq i32 %18, 0
br i1 %19, label %24, label %20
20: ; preds = %9
%21 = call i32 @test_mem_eq(i8* getelementptr inbounds ([157 x i8], [157 x i8]* @.str, i64 0, i64 0), i32 36, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %4, i32 10, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @test_bio_memleak.str, i64 0, i64 0), i32 10)
%22 = icmp ne i32 %21, 0
%23 = zext i1 %22 to i32
br label %24
24: ; preds = %20, %9, %0
%25 = phi i32 [ 0, %9 ], [ 0, %0 ], [ %23, %20 ]
%26 = call i32 @BIO_free(i32* %6)
ret i32 %25
}