#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*/ get_version(char *);
int my_decrypt(unsigned char *, unsigned char *, int);
int my_encrypt(unsigned char *, unsigned char *, int);
int /*<<< orphan*/ my_randomize(unsigned char *, int);
int read_data(int, char *, int);
int send(int, unsigned char *, int, int /*<<< orphan*/);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int server_verify_version(int fd) {
  int len, flag = 0;
  char tmp[32], tmp2[32];
  unsigned char buf[128], msg[128];
  if (read_data(fd, (char *)buf, 128) != 128)
    return -1;
  if (my_decrypt(buf, msg, 128) == -1)
    return -1;
  if (msg[50] != 'o' || msg[80] != 'k')
    return -1;
  strcpy(tmp2, (char *)msg + 25);
  my_randomize(buf, 128);
  get_version(tmp);
  if (strcmp(tmp, tmp2) == 0) {
    buf[50] = 'o';
    buf[80] = 'k';
  } else {
    buf[50] = 'O';
    buf[80] = 'K';
    flag = -1;
  }
  strcpy((char *)buf + 25, tmp);
  if (my_encrypt(buf, msg, 128) == -1)
    return -1;
  if (send(fd, msg, 128, 0) != 128)
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<server_verify_version>:
push   %rbp
mov    %rsp,%rbp
sub    $0x150,%rsp
mov    %edi,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%edi
lea    -0xd0(%rbp),%rsi
mov    $0x80,%edx
call   1030 <read_data@plt>
cmp    $0x80,%eax
je     11c0 <server_verify_version+0x40>
movl   $0xffffffff,-0x4(%rbp)
jmp    12f5 <server_verify_version+0x175>
lea    -0xd0(%rbp),%rdi
lea    -0x150(%rbp),%rsi
mov    $0x80,%edx
call   1090 <my_decrypt@plt>
cmp    $0xffffffff,%eax
jne    11ed <server_verify_version+0x6d>
movl   $0xffffffff,-0x4(%rbp)
jmp    12f5 <server_verify_version+0x175>
movzbl -0x11e(%rbp),%eax
cmp    $0x6f,%eax
jne    120d <server_verify_version+0x8d>
movzbl -0x100(%rbp),%eax
cmp    $0x6b,%eax
je     1219 <server_verify_version+0x99>
movl   $0xffffffff,-0x4(%rbp)
jmp    12f5 <server_verify_version+0x175>
lea    -0x50(%rbp),%rdi
lea    -0x150(%rbp),%rsi
add    $0x19,%rsi
call   1040 <strcpy@plt>
lea    -0xd0(%rbp),%rdi
mov    $0x80,%esi
call   1050 <my_randomize@plt>
lea    -0x30(%rbp),%rdi
call   10a0 <get_version@plt>
lea    -0x30(%rbp),%rdi
lea    -0x50(%rbp),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    126e <server_verify_version+0xee>
movb   $0x6f,-0x9e(%rbp)
movb   $0x6b,-0x80(%rbp)
jmp    1280 <server_verify_version+0x100>
movb   $0x4f,-0x9e(%rbp)
movb   $0x4b,-0x80(%rbp)
movl   $0xffffffff,-0x10(%rbp)
lea    -0xd0(%rbp),%rdi
add    $0x19,%rdi
lea    -0x30(%rbp),%rsi
call   1040 <strcpy@plt>
lea    -0xd0(%rbp),%rdi
lea    -0x150(%rbp),%rsi
mov    $0x80,%edx
call   1070 <my_encrypt@plt>
cmp    $0xffffffff,%eax
jne    12c1 <server_verify_version+0x141>
movl   $0xffffffff,-0x4(%rbp)
jmp    12f5 <server_verify_version+0x175>
mov    -0x8(%rbp),%edi
lea    -0x150(%rbp),%rsi
mov    $0x80,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
cmp    $0x80,%eax
je     12ee <server_verify_version+0x16e>
movl   $0xffffffff,-0x4(%rbp)
jmp    12f5 <server_verify_version+0x175>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x150,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<server_verify_version>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x140,%rsp
mov    %edi,%ebp
lea    0x80(%rsp),%rsi
mov    $0x80,%edx
call   1030 <read_data@plt>
mov    $0xffffffff,%ebx
cmp    $0x80,%eax
jne    128a <server_verify_version+0x10a>
lea    0x80(%rsp),%rdi
mov    %rsp,%rsi
mov    $0x80,%edx
call   1090 <my_decrypt@plt>
cmp    $0xffffffff,%eax
je     128a <server_verify_version+0x10a>
cmpb   $0x6f,0x32(%rsp)
jne    128a <server_verify_version+0x10a>
cmpb   $0x6b,0x50(%rsp)
jne    128a <server_verify_version+0x10a>
lea    0x19(%rsp),%rsi
lea    0x100(%rsp),%r15
mov    %r15,%rdi
call   1040 <strcpy@plt>
lea    0x80(%rsp),%r14
mov    %r14,%rdi
mov    $0x80,%esi
call   1050 <my_randomize@plt>
lea    0x120(%rsp),%r12
mov    %r12,%rdi
call   10a0 <get_version@plt>
mov    %r12,%rdi
mov    %r15,%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
sete   %al
shl    $0x5,%al
lea    0x4f(%rax),%ecx
or     $0x4b,%al
mov    %cl,0xb2(%rsp)
mov    %al,0xd0(%rsp)
lea    0x99(%rsp),%rdi
mov    %r12,%rsi
call   1040 <strcpy@plt>
mov    %rsp,%rsi
mov    %r14,%rdi
mov    $0x80,%edx
call   1070 <my_encrypt@plt>
cmp    $0xffffffff,%eax
je     128a <server_verify_version+0x10a>
mov    %rsp,%rsi
mov    %ebp,%edi
mov    $0x80,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
xor    %ebx,%ebx
cmp    $0x80,%eax
setne  %bl
neg    %ebx
mov    %ebx,%eax
add    $0x140,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @server_verify_version(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [32 x i8]
%7 = alloca [32 x i8]
%8 = alloca [128 x i8]
%9 = alloca [128 x i8]
store i32 %0, i32* %3
store i32 0, i32* %5
%10 = load i32, i32* %3
%11 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%12 = call i32 @read_data(i32 %10, i8* %11, i32 128)
%13 = icmp ne i32 %12, 128
br i1 %13, label %14, label %15
14: ; preds = %1
store i32 -1, i32* %2
br label %68
15: ; preds = %1
%16 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%17 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%18 = call i32 @my_decrypt(i8* %16, i8* %17, i32 128)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %21
20: ; preds = %15
store i32 -1, i32* %2
br label %68
21: ; preds = %15
%22 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 50
%23 = load i8, i8* %22
%24 = zext i8 %23 to i32
%25 = icmp ne i32 %24, 111
br i1 %25, label %31, label %26
26: ; preds = %21
%27 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 80
%28 = load i8, i8* %27
%29 = zext i8 %28 to i32
%30 = icmp ne i32 %29, 107
br i1 %30, label %31, label %32
31: ; preds = %26, %21
store i32 -1, i32* %2
br label %68
32: ; preds = %26
%33 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%34 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%35 = getelementptr inbounds i8, i8* %34, i64 25
%36 = call i32 @strcpy(i8* %33, i8* %35)
%37 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%38 = call i32 @my_randomize(i8* %37, i32 128)
%39 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%40 = call i32 @get_version(i8* %39)
%41 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%42 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%43 = call i64 @strcmp(i8* %41, i8* %42)
%44 = icmp eq i64 %43, 0
br i1 %44, label %45, label %48
45: ; preds = %32
%46 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 50
store i8 111, i8* %46
%47 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 80
store i8 107, i8* %47
br label %51
48: ; preds = %32
%49 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 50
store i8 79, i8* %49
%50 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 80
store i8 75, i8* %50
store i32 -1, i32* %5
br label %51
51: ; preds = %48, %45
%52 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%53 = getelementptr inbounds i8, i8* %52, i64 25
%54 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%55 = call i32 @strcpy(i8* %53, i8* %54)
%56 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%57 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%58 = call i32 @my_encrypt(i8* %56, i8* %57, i32 128)
%59 = icmp eq i32 %58, -1
br i1 %59, label %60, label %61
60: ; preds = %51
store i32 -1, i32* %2
br label %68
61: ; preds = %51
%62 = load i32, i32* %3
%63 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%64 = call i32 @send(i32 %62, i8* %63, i32 128, i32 0)
%65 = icmp ne i32 %64, 128
br i1 %65, label %66, label %67
66: ; preds = %61
store i32 -1, i32* %2
br label %68
67: ; preds = %61
store i32 0, i32* %2
br label %68
68: ; preds = %67, %66, %60, %31, %20, %14
%69 = load i32, i32* %2
ret i32 %69
}

LLVM IR (-O2):
define i32 @server_verify_version(i32 %0) {
%2 = alloca [32 x i8]
%3 = alloca [32 x i8]
%4 = alloca [128 x i8]
%5 = alloca [128 x i8]
%6 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%7 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%8 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%9 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%10 = call i32 @read_data(i32 %0, i8* %8, i32 128)
%11 = icmp eq i32 %10, 128
br i1 %11, label %12, label %42
12: ; preds = %1
%13 = call i32 @my_decrypt(i8* %8, i8* %9, i32 128)
%14 = icmp eq i32 %13, -1
br i1 %14, label %42, label %15
15: ; preds = %12
%16 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 50
%17 = load i8, i8* %16
%18 = icmp ne i8 %17, 111
%19 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 80
%20 = load i8, i8* %19
%21 = icmp ne i8 %20, 107
%22 = select i1 %18, i1 true, i1 %21
br i1 %22, label %42, label %23
23: ; preds = %15
%24 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 25
%25 = call i32 @strcpy(i8* %7, i8* %24)
%26 = call i32 @my_randomize(i8* %8, i32 128)
%27 = call i32 @get_version(i8* %6)
%28 = call i64 @strcmp(i8* %6, i8* %7)
%29 = icmp eq i64 %28, 0
%30 = select i1 %29, i8 111, i8 79
%31 = select i1 %29, i8 107, i8 75
%32 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 50
store i8 %30, i8* %32
%33 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 80
store i8 %31, i8* %33
%34 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 25
%35 = call i32 @strcpy(i8* %34, i8* %6)
%36 = call i32 @my_encrypt(i8* %8, i8* %9, i32 128)
%37 = icmp eq i32 %36, -1
br i1 %37, label %42, label %38
38: ; preds = %23
%39 = call i32 @send(i32 %0, i8* %9, i32 128, i32 0)
%40 = icmp ne i32 %39, 128
%41 = sext i1 %40 to i32
br label %42
42: ; preds = %38, %23, %15, %12, %1
%43 = phi i32 [ -1, %1 ], [ -1, %12 ], [ -1, %15 ], [ -1, %23 ], [ %41, %38 ]
ret i32 %43
}