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

/* Variables and functions */
int /*<<< orphan*/ free(unsigned char *);
unsigned char *medusaReceiveRaw(int, int *);
scalar_t__ medusaSend(int, unsigned char *, int, int /*<<< orphan*/);
scalar_t__ strstr(char *, char *);
int /*<<< orphan*/ writeError(int, char *, char *);
int pcaNegCrypt(int hSocket) {
  unsigned char bufSend[] = {0x6f, 0x61, 0x00, 0x09, 0x00, 0xfe, 0x00,
                             0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00};
  int nSendBufferSize = 14;
  unsigned char *bufReceive;
  int nReceiveBufferSize = 0;
  writeError(10, "%s: Checking encryption level.", "pcanywhere.mod");
  if (medusaSend(hSocket, bufSend, nSendBufferSize, 0) < 0) {
    writeError(3, "%s failed: medusaSend was not successful", "pcanywhere.mod");
    return -1;
  }
  nReceiveBufferSize = 0;
  bufReceive = medusaReceiveRaw(hSocket, &nReceiveBufferSize);
  if (bufReceive == NULL) {
    writeError(3, "%s failed: medusaReceive returned no data.",
               "pcanywhere.mod");
    return -1;
  } else if (strstr((char *)bufReceive + 28, "Host is denying connection")) {
    writeError(3,
               "%s: PcAnywhere host denied connection. Host requires "
               "encryption which is currently not supported.",
               "pcanywhere.mod");
    if (bufReceive != NULL) {
      free(bufReceive);
      bufReceive = NULL;
    };
    return -1;
  }
  if (bufReceive != NULL) {
    free(bufReceive);
    bufReceive = NULL;
  };
  return 0;
}


x86 assembly (clang, -O0):
<pcaNegCrypt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    0xe9e(%rip),%rax
mov    %rax,-0x16(%rbp)
mov    0xe9c(%rip),%eax
mov    %eax,-0xe(%rbp)
mov    0xe96(%rip),%ax
mov    %ax,-0xa(%rbp)
movl   $0xe,-0x1c(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    $0xa,%edi
lea    0xe7a(%rip),%rsi
lea    0xe92(%rip),%rdx
call   1050 <writeError@plt>
mov    -0x8(%rbp),%edi
lea    -0x16(%rbp),%rsi
mov    -0x1c(%rbp),%edx
xor    %ecx,%ecx
call   1060 <medusaSend@plt>
cmp    $0x0,%rax
jge    11df <pcaNegCrypt+0x8f>
mov    $0x3,%edi
lea    0xe75(%rip),%rsi
lea    0xe5f(%rip),%rdx
call   1050 <writeError@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12ab <pcaNegCrypt+0x15b>
movl   $0x0,-0x2c(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x2c(%rbp),%rsi
call   1030 <medusaReceiveRaw@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1225 <pcaNegCrypt+0xd5>
mov    $0x3,%edi
lea    0xe58(%rip),%rsi
lea    0xe19(%rip),%rdx
call   1050 <writeError@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12ab <pcaNegCrypt+0x15b>
mov    -0x28(%rbp),%rdi
add    $0x1c,%rdi
lea    0xe5c(%rip),%rsi
call   1070 <strstr@plt>
cmp    $0x0,%rax
je     1283 <pcaNegCrypt+0x133>
mov    $0x3,%edi
lea    0xe5c(%rip),%rsi
lea    0xdd7(%rip),%rdx
call   1050 <writeError@plt>
cmpq   $0x0,-0x28(%rbp)
je     1277 <pcaNegCrypt+0x127>
mov    -0x28(%rbp),%rdi
call   1040 <free@plt>
movq   $0x0,-0x28(%rbp)
movl   $0xffffffff,-0x4(%rbp)
jmp    12ab <pcaNegCrypt+0x15b>
jmp    1288 <pcaNegCrypt+0x138>
cmpq   $0x0,-0x28(%rbp)
je     12a4 <pcaNegCrypt+0x154>
mov    -0x28(%rbp),%rdi
call   1040 <free@plt>
movq   $0x0,-0x28(%rbp)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pcaNegCrypt>:
push   %rbx
sub    $0x20,%rsp
mov    %edi,%ebx
mov    $0xffff0000,%eax
mov    %rax,0x16(%rsp)
movabs $0xfe000900616f,%rax
mov    %rax,0x10(%rsp)
lea    0xe97(%rip),%rsi
lea    0xeaf(%rip),%rdx
mov    $0xa,%edi
call   1050 <writeError@plt>
lea    0x10(%rsp),%rsi
mov    %ebx,%edi
mov    $0xe,%edx
xor    %ecx,%ecx
call   1060 <medusaSend@plt>
test   %rax,%rax
js     11fb <pcaNegCrypt+0xab>
movl   $0x0,0xc(%rsp)
lea    0xc(%rsp),%rsi
mov    %ebx,%edi
call   1030 <medusaReceiveRaw@plt>
test   %rax,%rax
je     1204 <pcaNegCrypt+0xb4>
mov    %rax,%rbx
mov    %rax,%rdi
add    $0x1c,%rdi
lea    0xec6(%rip),%rsi
call   1070 <strstr@plt>
test   %rax,%rax
je     1223 <pcaNegCrypt+0xd3>
lea    0xed0(%rip),%rsi
lea    0xe4b(%rip),%rdx
mov    $0x3,%edi
call   1050 <writeError@plt>
mov    %rbx,%rdi
call   1040 <free@plt>
mov    $0xffffffff,%eax
jmp    122d <pcaNegCrypt+0xdd>
lea    0xe3a(%rip),%rsi
jmp    120b <pcaNegCrypt+0xbb>
lea    0xe5a(%rip),%rsi
lea    0xe1b(%rip),%rdx
mov    $0x3,%edi
call   1050 <writeError@plt>
mov    $0xffffffff,%eax
jmp    122d <pcaNegCrypt+0xdd>
mov    %rbx,%rdi
call   1040 <free@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.pcaNegCrypt.bufSend = [14 x i8] c"oa\00\09\00\FE\00\00\FF\FF\00\00\00\00"
@.str = [31 x i8] c"%s: Checking encryption level.\00"
@.str.1 = [15 x i8] c"pcanywhere.mod\00"
@.str.2 = [41 x i8] c"%s failed: medusaSend was not successful\00"
@.str.3 = [43 x i8] c"%s failed: medusaReceive returned no data.\00"
@.str.4 = [27 x i8] c"Host is denying connection\00"
@.str.5 = [98 x i8] c"%s: PcAnywhere host denied connection. Host requires encryption which is currently not supported.\00"
define i32 @pcaNegCrypt(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [14 x i8]
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
store i32 %0, i32* %3
%8 = bitcast [14 x i8]* %4 to i8*
store i32 14, i32* %5
store i32 0, i32* %7
%9 = call i32 @writeError(i32 10, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%10 = load i32, i32* %3
%11 = getelementptr inbounds [14 x i8], [14 x i8]* %4, i64 0, i64 0
%12 = load i32, i32* %5
%13 = call i64 @medusaSend(i32 %10, i8* %11, i32 %12, i32 0)
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %1
%16 = call i32 @writeError(i32 3, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %2
br label %45
17: ; preds = %1
store i32 0, i32* %7
%18 = load i32, i32* %3
%19 = call i8* @medusaReceiveRaw(i32 %18, i32* %7)
store i8* %19, i8** %6
%20 = load i8*, i8** %6
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %24
22: ; preds = %17
%23 = call i32 @writeError(i32 3, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %2
br label %45
24: ; preds = %17
%25 = load i8*, i8** %6
%26 = getelementptr inbounds i8, i8* %25, i64 28
%27 = call i64 @strstr(i8* %26, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0))
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %37
29: ; preds = %24
%30 = call i32 @writeError(i32 3, i8* getelementptr inbounds ([98 x i8], [98 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%31 = load i8*, i8** %6
%32 = icmp ne i8* %31, null
br i1 %32, label %33, label %36
33: ; preds = %29
%34 = load i8*, i8** %6
%35 = call i32 @free(i8* %34)
store i8* null, i8** %6
br label %36
36: ; preds = %33, %29
store i32 -1, i32* %2
br label %45
37: ; preds = %24
br label %38
38: ; preds = %37
%39 = load i8*, i8** %6
%40 = icmp ne i8* %39, null
br i1 %40, label %41, label %44
41: ; preds = %38
%42 = load i8*, i8** %6
%43 = call i32 @free(i8* %42)
store i8* null, i8** %6
br label %44
44: ; preds = %41, %38
store i32 0, i32* %2
br label %45
45: ; preds = %44, %36, %22, %15
%46 = load i32, i32* %2
ret i32 %46
}

LLVM IR (-O2):
@__const.pcaNegCrypt.bufSend = [14 x i8] c"oa\00\09\00\FE\00\00\FF\FF\00\00\00\00"
@.str = [31 x i8] c"%s: Checking encryption level.\00"
@.str.1 = [15 x i8] c"pcanywhere.mod\00"
@.str.2 = [41 x i8] c"%s failed: medusaSend was not successful\00"
@.str.3 = [43 x i8] c"%s failed: medusaReceive returned no data.\00"
@.str.4 = [27 x i8] c"Host is denying connection\00"
@.str.5 = [98 x i8] c"%s: PcAnywhere host denied connection. Host requires encryption which is currently not supported.\00"
define i32 @pcaNegCrypt(i32 %0) {
%2 = alloca [14 x i8]
%3 = alloca i32
%4 = getelementptr inbounds [14 x i8], [14 x i8]* %2, i64 0, i64 0
%5 = bitcast i32* %3 to i8*
%6 = tail call i32 @writeError(i32 10, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%7 = call i64 @medusaSend(i32 %0, i8* %4, i32 14, i32 0)
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = call i32 @writeError(i32 3, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %25
11: ; preds = %1
store i32 0, i32* %3
%12 = call i8* @medusaReceiveRaw(i32 %0, i32* %3)
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %16
14: ; preds = %11
%15 = call i32 @writeError(i32 3, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %25
16: ; preds = %11
%17 = getelementptr inbounds i8, i8* %12, i64 28
%18 = call i64 @strstr(i8* %17, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
br i1 %19, label %23, label %20
20: ; preds = %16
%21 = call i32 @writeError(i32 3, i8* getelementptr inbounds ([98 x i8], [98 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%22 = call i32 @free(i8* %12)
br label %25
23: ; preds = %16
%24 = call i32 @free(i8* %12)
br label %25
25: ; preds = %23, %20, %14, %9
%26 = phi i32 [ -1, %9 ], [ -1, %14 ], [ -1, %20 ], [ 0, %23 ]
ret i32 %26
}