#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_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ BIO_free_all(int /*<<< orphan*/ *);
int /*<<< orphan*/ *BIO_pop(int /*<<< orphan*/ *);
void do_free_upto(BIO *f, BIO *upto) {
  if (upto) {
    BIO *tbio;
    do {
      tbio = BIO_pop(f);
      BIO_free(f);
      f = tbio;
    } while (f && f != upto);
  } else
    BIO_free_all(f);
}


x86 assembly (clang, -O0):
<do_free_upto>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     119c <do_free_upto+0x6c>
jmp    1150 <do_free_upto+0x20>
mov    -0x8(%rbp),%rdi
call   1030 <BIO_pop@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <BIO_free@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x8(%rbp)
mov    %al,-0x19(%rbp)
je     118c <do_free_upto+0x5c>
mov    -0x8(%rbp),%rax
cmp    -0x10(%rbp),%rax
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    1150 <do_free_upto+0x20>
jmp    11a5 <do_free_upto+0x75>
mov    -0x8(%rbp),%rdi
call   1050 <BIO_free_all@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_free_upto>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r15
test   %rsi,%rsi
je     1166 <do_free_upto+0x36>
mov    %rsi,%r14
mov    %r15,%rdi
call   1030 <BIO_pop@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1040 <BIO_free@plt>
test   %rbx,%rbx
je     1160 <do_free_upto+0x30>
mov    %rbx,%r15
cmp    %r14,%rbx
jne    1140 <do_free_upto+0x10>
pop    %rbx
pop    %r14
pop    %r15
ret
mov    %r15,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1050 <BIO_free_all@plt>

LLVM IR (-O0):
define void @do_free_upto(i32* %0, i32* %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32*
store i32* %0, i32** %3
store i32* %1, i32** %4
%6 = load i32*, i32** %4
%7 = icmp ne i32* %6, null
br i1 %7, label %8, label %25
8: ; preds = %2
br label %9
9: ; preds = %22, %8
%10 = load i32*, i32** %3
%11 = call i32* @BIO_pop(i32* %10)
store i32* %11, i32** %5
%12 = load i32*, i32** %3
%13 = call i32 @BIO_free(i32* %12)
%14 = load i32*, i32** %5
store i32* %14, i32** %3
br label %15
15: ; preds = %9
%16 = load i32*, i32** %3
%17 = icmp ne i32* %16, null
br i1 %17, label %18, label %22
18: ; preds = %15
%19 = load i32*, i32** %3
%20 = load i32*, i32** %4
%21 = icmp ne i32* %19, %20
br label %22
22: ; preds = %18, %15
%23 = phi i1 [ false, %15 ], [ %21, %18 ]
br i1 %23, label %9, label %24
24: ; preds = %22
br label %28
25: ; preds = %2
%26 = load i32*, i32** %3
%27 = call i32 @BIO_free_all(i32* %26)
br label %28
28: ; preds = %25, %24
ret void
}

LLVM IR (-O2):
define void @do_free_upto(i32* %0, i32* readnone %1) {
%3 = icmp eq i32* %1, null
br i1 %3, label %11, label %4
4: ; preds = %2, %4
%5 = phi i32* [ %6, %4 ], [ %0, %2 ]
%6 = tail call i32* @BIO_pop(i32* %5)
%7 = tail call i32 @BIO_free(i32* %5)
%8 = icmp ne i32* %6, null
%9 = icmp ne i32* %6, %1
%10 = and i1 %8, %9
br i1 %10, label %4, label %13
11: ; preds = %2
%12 = tail call i32 @BIO_free_all(i32* %0)
br label %13
13: ; preds = %4, %11
ret void
}