#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 */
char *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 /*<<< orphan*/ printf(char *, char *, char *);
int read_data(int, char *, int);
int send(int, unsigned char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(char *, char *);
int client_verify_version(int fd) {
  int len;
  char tmp[32];
  unsigned char buf[128], msg[128];
  my_randomize(buf, 128);
  buf[50] = 'o';
  buf[80] = 'k';
  strcpy((char *)buf + 25, get_version(tmp));
  if (my_encrypt(buf, msg, 128) == -1)
    return -1;
  if (send(fd, msg, 128, 0) != 128)
    return -1;
  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') {
    printf("version not match: local = %s, remote = %s.\n", get_version(tmp),
           (char *)msg + 25);
    return -1;
  }
  if (msg[50] != 'o' || msg[80] != 'k')
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<client_verify_version>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
mov    %edi,-0x8(%rbp)
lea    -0xb0(%rbp),%rdi
mov    $0x80,%esi
call   1050 <my_randomize@plt>
movb   $0x6f,-0x7e(%rbp)
movb   $0x6b,-0x60(%rbp)
lea    -0xb0(%rbp),%rax
add    $0x19,%rax
mov    %rax,-0x138(%rbp)
lea    -0x30(%rbp),%rdi
call   10a0 <get_version@plt>
mov    -0x138(%rbp),%rdi
mov    %rax,%rsi
call   1040 <strcpy@plt>
lea    -0xb0(%rbp),%rdi
lea    -0x130(%rbp),%rsi
mov    $0x80,%edx
call   1080 <my_encrypt@plt>
cmp    $0xffffffff,%eax
jne    11fe <client_verify_version+0x7e>
movl   $0xffffffff,-0x4(%rbp)
jmp    1305 <client_verify_version+0x185>
mov    -0x8(%rbp),%edi
lea    -0x130(%rbp),%rsi
mov    $0x80,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
cmp    $0x80,%eax
je     122b <client_verify_version+0xab>
movl   $0xffffffff,-0x4(%rbp)
jmp    1305 <client_verify_version+0x185>
mov    -0x8(%rbp),%edi
lea    -0xb0(%rbp),%rsi
mov    $0x80,%edx
call   1030 <read_data@plt>
cmp    $0x80,%eax
je     1256 <client_verify_version+0xd6>
movl   $0xffffffff,-0x4(%rbp)
jmp    1305 <client_verify_version+0x185>
lea    -0xb0(%rbp),%rdi
lea    -0x130(%rbp),%rsi
mov    $0x80,%edx
call   1090 <my_decrypt@plt>
cmp    $0xffffffff,%eax
jne    1283 <client_verify_version+0x103>
movl   $0xffffffff,-0x4(%rbp)
jmp    1305 <client_verify_version+0x185>
movzbl -0xfe(%rbp),%eax
cmp    $0x4f,%eax
jne    12d2 <client_verify_version+0x152>
movzbl -0xe0(%rbp),%eax
cmp    $0x4b,%eax
jne    12d2 <client_verify_version+0x152>
lea    -0x30(%rbp),%rdi
call   10a0 <get_version@plt>
mov    %rax,%rsi
lea    -0x130(%rbp),%rdx
add    $0x19,%rdx
lea    0xd3f(%rip),%rdi
call   1070 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1305 <client_verify_version+0x185>
movzbl -0xfe(%rbp),%eax
cmp    $0x6f,%eax
jne    12f2 <client_verify_version+0x172>
movzbl -0xe0(%rbp),%eax
cmp    $0x6b,%eax
je     12fe <client_verify_version+0x17e>
movl   $0xffffffff,-0x4(%rbp)
jmp    1305 <client_verify_version+0x185>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<client_verify_version>:
push   %rbp
push   %r14
push   %rbx
sub    $0x120,%rsp
mov    %edi,%r14d
lea    0xa0(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x80,%esi
call   1050 <my_randomize@plt>
movb   $0x6f,0xd2(%rsp)
6f
movb   $0x6b,0xf0(%rsp)
6b
lea    0xb9(%rsp),%rbp
mov    %rsp,%rdi
call   10a0 <get_version@plt>
mov    %rbp,%rdi
mov    %rax,%rsi
call   1040 <strcpy@plt>
lea    0x20(%rsp),%rsi
mov    %rbx,%rdi
mov    $0x80,%edx
call   1080 <my_encrypt@plt>
mov    $0xffffffff,%ebx
cmp    $0xffffffff,%eax
je     127e <client_verify_version+0xfe>
lea    0x20(%rsp),%rsi
mov    %r14d,%edi
mov    $0x80,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
cmp    $0x80,%eax
jne    127e <client_verify_version+0xfe>
lea    0xa0(%rsp),%rsi
mov    %r14d,%edi
mov    $0x80,%edx
call   1030 <read_data@plt>
cmp    $0x80,%eax
jne    127e <client_verify_version+0xfe>
lea    0xa0(%rsp),%rdi
lea    0x20(%rsp),%rsi
mov    $0x80,%edx
call   1090 <my_decrypt@plt>
cmp    $0xffffffff,%eax
je     127e <client_verify_version+0xfe>
mov    0x52(%rsp),%al
mov    0x70(%rsp),%cl
cmp    $0x4f,%al
jne    1270 <client_verify_version+0xf0>
cmp    $0x4b,%cl
jne    1270 <client_verify_version+0xf0>
mov    %rsp,%rdi
call   10a0 <get_version@plt>
lea    0x39(%rsp),%rdx
lea    0xd9a(%rip),%rdi
mov    %rax,%rsi
call   1070 <printf@plt>
jmp    127e <client_verify_version+0xfe>
xor    $0x6f,%al
xor    $0x6b,%cl
xor    %ebx,%ebx
or     %al,%cl
setne  %bl
neg    %ebx
mov    %ebx,%eax
add    $0x120,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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