#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_get_fd(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
scalar_t__ BIO_get_init(int /*<<< orphan*/ *);
scalar_t__ BIO_get_shutdown(int /*<<< orphan*/ *);
int /*<<< orphan*/ BIO_set_flags(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ BIO_set_init(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ tou_close(int /*<<< orphan*/);
int tou_socket_free(BIO *a) {
  if (a == NULL)
    return (0);
  if (BIO_get_shutdown(a)) {
    if (BIO_get_init(a)) {
      tou_close(BIO_get_fd(a, NULL));
    }
    BIO_set_init(a, 0);
    BIO_set_flags(a, 0);
  }
  return (1);
}


x86 assembly (clang, -O0):
<tou_socket_free>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1183 <tou_socket_free+0x23>
movl   $0x0,-0x4(%rbp)
jmp    11da <tou_socket_free+0x7a>
mov    -0x10(%rbp),%rdi
call   1070 <BIO_get_shutdown@plt>
cmp    $0x0,%rax
je     11d3 <tou_socket_free+0x73>
mov    -0x10(%rbp),%rdi
call   1050 <BIO_get_init@plt>
cmp    $0x0,%rax
je     11bd <tou_socket_free+0x5d>
mov    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1080 <BIO_get_fd@plt>
mov    %eax,%edi
call   1060 <tou_close@plt>
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
call   1030 <BIO_set_init@plt>
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
call   1040 <BIO_set_flags@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tou_socket_free>:
push   %rbp
push   %rbx
push   %rax
test   %rdi,%rdi
je     11ae <tou_socket_free+0x4e>
mov    %rdi,%rbx
call   1070 <BIO_get_shutdown@plt>
mov    $0x1,%ebp
test   %rax,%rax
je     11b0 <tou_socket_free+0x50>
mov    %rbx,%rdi
call   1050 <BIO_get_init@plt>
test   %rax,%rax
je     1198 <tou_socket_free+0x38>
mov    %rbx,%rdi
xor    %esi,%esi
call   1080 <BIO_get_fd@plt>
mov    %eax,%edi
call   1060 <tou_close@plt>
mov    %rbx,%rdi
xor    %esi,%esi
call   1030 <BIO_set_init@plt>
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <BIO_set_flags@plt>
jmp    11b0 <tou_socket_free+0x50>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @tou_socket_free(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
store i32* %0, i32** %3
%4 = load i32*, i32** %3
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %7
6: ; preds = %1
store i32 0, i32* %2
br label %25
7: ; preds = %1
%8 = load i32*, i32** %3
%9 = call i64 @BIO_get_shutdown(i32* %8)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %24
11: ; preds = %7
%12 = load i32*, i32** %3
%13 = call i64 @BIO_get_init(i32* %12)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %11
%16 = load i32*, i32** %3
%17 = call i32 @BIO_get_fd(i32* %16, i32* null)
%18 = call i32 @tou_close(i32 %17)
br label %19
19: ; preds = %15, %11
%20 = load i32*, i32** %3
%21 = call i32 @BIO_set_init(i32* %20, i32 0)
%22 = load i32*, i32** %3
%23 = call i32 @BIO_set_flags(i32* %22, i32 0)
br label %24
24: ; preds = %19, %7
store i32 1, i32* %2
br label %25
25: ; preds = %24, %6
%26 = load i32, i32* %2
ret i32 %26
}

LLVM IR (-O2):
define i32 @tou_socket_free(i32* %0) {
%2 = icmp eq i32* %0, null
br i1 %2, label %15, label %3
3: ; preds = %1
%4 = tail call i64 @BIO_get_shutdown(i32* %0)
%5 = icmp eq i64 %4, 0
br i1 %5, label %15, label %6
6: ; preds = %3
%7 = tail call i64 @BIO_get_init(i32* %0)
%8 = icmp eq i64 %7, 0
br i1 %8, label %12, label %9
9: ; preds = %6
%10 = tail call i32 @BIO_get_fd(i32* %0, i32* null)
%11 = tail call i32 @tou_close(i32 %10)
br label %12
12: ; preds = %9, %6
%13 = tail call i32 @BIO_set_init(i32* %0, i32 0)
%14 = tail call i32 @BIO_set_flags(i32* %0, i32 0)
br label %15
15: ; preds = %3, %12, %1
%16 = phi i32 [ 0, %1 ], [ 1, %12 ], [ 1, %3 ]
ret i32 %16
}