#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*/ SSL;

/* Variables and functions */
int SSL_RECEIVED_SHUTDOWN;
int SSL_SENT_SHUTDOWN;
int /*<<< orphan*/ SSL_free(int /*<<< orphan*/ *);
int SSL_get_error(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ SSL_set_shutdown(int /*<<< orphan*/ *, int);
int SSL_shutdown(int /*<<< orphan*/ *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ stderr;
void closesocks(SSL **ssl, int sock) {
  int ret;
  SSL_set_shutdown(*ssl, SSL_SENT_SHUTDOWN | SSL_RECEIVED_SHUTDOWN);
  ret = SSL_shutdown(*ssl);
  if (ret == 0) {
    ret = SSL_shutdown(*ssl);
    printf("\n %i \n", SSL_get_error(*ssl, ret));
  }
  if ((ret) < 0) {
    fprintf(stderr, "\n%s\n", "SSL shutdown error");
    exit(1);
  };
  SSL_free(*ssl);
  close(sock);
}


x86 assembly (clang, -O0):
<closesocks>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    0x2e53(%rip),%rax
mov    (%rax),%esi
mov    0x2e2a(%rip),%rax
or     (%rax),%esi
call   1060 <SSL_set_shutdown@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1080 <SSL_shutdown@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jne    11f2 <closesocks+0x72>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1080 <SSL_shutdown@plt>
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%esi
call   1030 <SSL_get_error@plt>
mov    %eax,%esi
lea    0xe13(%rip),%rdi
call   1050 <printf@plt>
cmpl   $0x0,-0x10(%rbp)
jge    1222 <closesocks+0xa2>
mov    0x2dd5(%rip),%rax
mov    (%rax),%edi
lea    0xdfb(%rip),%rsi
lea    0xdf9(%rip),%rdx
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1040 <SSL_free@plt>
mov    -0xc(%rbp),%edi
call   1070 <close@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<closesocks>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%r14d
mov    %rdi,%rbx
mov    (%rdi),%rdi
mov    0x2e5c(%rip),%rax
mov    0x2e35(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
call   1060 <SSL_set_shutdown@plt>
mov    (%rbx),%rdi
call   1080 <SSL_shutdown@plt>
mov    %eax,%ebp
test   %eax,%eax
jne    11d4 <closesocks+0x54>
mov    (%rbx),%rdi
call   1080 <SSL_shutdown@plt>
mov    %eax,%ebp
mov    (%rbx),%rdi
mov    %eax,%esi
call   1030 <SSL_get_error@plt>
lea    0xe33(%rip),%rdi
mov    %eax,%esi
call   1050 <printf@plt>
test   %ebp,%ebp
js     11ec <closesocks+0x6c>
mov    (%rbx),%rdi
call   1040 <SSL_free@plt>
mov    %r14d,%edi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1070 <close@plt>
mov    0x2de5(%rip),%rax
mov    (%rax),%edi
lea    0xe0b(%rip),%rsi
lea    0xe09(%rip),%rdx
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@SSL_SENT_SHUTDOWN = global i32 0
@SSL_RECEIVED_SHUTDOWN = global i32 0
@.str = [7 x i8] c"\0A %i \0A\00"
@stderr = global i32 0
@.str.1 = [5 x i8] c"\0A%s\0A\00"
@.str.2 = [19 x i8] c"SSL shutdown error\00"
define void @closesocks(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*** %3
%7 = load i32*, i32** %6
%8 = load i32, i32* @SSL_SENT_SHUTDOWN
%9 = load i32, i32* @SSL_RECEIVED_SHUTDOWN
%10 = or i32 %8, %9
%11 = call i32 @SSL_set_shutdown(i32* %7, i32 %10)
%12 = load i32**, i32*** %3
%13 = load i32*, i32** %12
%14 = call i32 @SSL_shutdown(i32* %13)
store i32 %14, i32* %5
%15 = load i32, i32* %5
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %26
17: ; preds = %2
%18 = load i32**, i32*** %3
%19 = load i32*, i32** %18
%20 = call i32 @SSL_shutdown(i32* %19)
store i32 %20, i32* %5
%21 = load i32**, i32*** %3
%22 = load i32*, i32** %21
%23 = load i32, i32* %5
%24 = call i32 @SSL_get_error(i32* %22, i32 %23)
%25 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %24)
br label %26
26: ; preds = %17, %2
%27 = load i32, i32* %5
%28 = icmp slt i32 %27, 0
br i1 %28, label %29, label %33
29: ; preds = %26
%30 = load i32, i32* @stderr
%31 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%32 = call i32 @exit(i32 1)
unreachable
33: ; preds = %26
%34 = load i32**, i32*** %3
%35 = load i32*, i32** %34
%36 = call i32 @SSL_free(i32* %35)
%37 = load i32, i32* %4
%38 = call i32 @close(i32 %37)
ret void
}

LLVM IR (-O2):
@SSL_SENT_SHUTDOWN = global i32 0
@SSL_RECEIVED_SHUTDOWN = global i32 0
@.str = [7 x i8] c"\0A %i \0A\00"
@stderr = global i32 0
@.str.1 = [5 x i8] c"\0A%s\0A\00"
@.str.2 = [19 x i8] c"SSL shutdown error\00"
define void @closesocks(i32** nocapture %0, i32 %1) {
%3 = load i32*, i32** %0
%4 = load i32, i32* @SSL_SENT_SHUTDOWN
%5 = load i32, i32* @SSL_RECEIVED_SHUTDOWN
%6 = or i32 %5, %4
%7 = tail call i32 @SSL_set_shutdown(i32* %3, i32 %6)
%8 = load i32*, i32** %0
%9 = tail call i32 @SSL_shutdown(i32* %8)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %17
11: ; preds = %2
%12 = load i32*, i32** %0
%13 = tail call i32 @SSL_shutdown(i32* %12)
%14 = load i32*, i32** %0
%15 = tail call i32 @SSL_get_error(i32* %14, i32 %13)
%16 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %15)
br label %17
17: ; preds = %11, %2
%18 = phi i32 [ %13, %11 ], [ %9, %2 ]
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %17
%21 = load i32, i32* @stderr
%22 = tail call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%23 = tail call i32 @exit(i32 1)
unreachable
24: ; preds = %17
%25 = load i32*, i32** %0
%26 = tail call i32 @SSL_free(i32* %25)
%27 = tail call i32 @close(i32 %1)
ret void
}