#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*/ memmove(char *, char *, int);
scalar_t__ pserver_crypt_password(char const *, char *, int);
int strlen(char *);
int pserver_decrypt_password(const char *str, char *s, int s_max) {
  if (str[0] != 'A')
    return -1;
  if (pserver_crypt_password(str + 1, s, s_max))
    return -1;
  memmove(s, s + 1, strlen(s + 1));
  s[strlen(s) - 1] = '\0';
  return 0;
}


x86 assembly (clang, -O0):
<pserver_decrypt_password>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x41,%eax
je     115f <pserver_decrypt_password+0x2f>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e1 <pserver_decrypt_password+0xb1>
mov    -0x10(%rbp),%rdi
add    $0x1,%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1050 <pserver_crypt_password@plt>
cmp    $0x0,%rax
je     1189 <pserver_decrypt_password+0x59>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e1 <pserver_decrypt_password+0xb1>
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
add    $0x1,%rdi
call   1030 <strlen@plt>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    %eax,%edx
call   1040 <memmove@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pserver_decrypt_password>:
push   %rbp
push   %rbx
push   %rax
mov    $0xffffffff,%ebp
cmpb   $0x41,(%rdi)
jne    1178 <pserver_decrypt_password+0x48>
mov    %rsi,%rbx
add    $0x1,%rdi
call   1050 <pserver_crypt_password@plt>
test   %rax,%rax
jne    1178 <pserver_decrypt_password+0x48>
lea    0x1(%rbx),%rbp
mov    %rbp,%rdi
call   1030 <strlen@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %eax,%edx
call   1040 <memmove@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @pserver_decrypt_password(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%8 = load i8*, i8** %5
%9 = getelementptr inbounds i8, i8* %8, i64 0
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = icmp ne i32 %11, 65
br i1 %12, label %13, label %14
13: ; preds = %3
store i32 -1, i32* %4
br label %36
14: ; preds = %3
%15 = load i8*, i8** %5
%16 = getelementptr inbounds i8, i8* %15, i64 1
%17 = load i8*, i8** %6
%18 = load i32, i32* %7
%19 = call i64 @pserver_crypt_password(i8* %16, i8* %17, i32 %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %14
store i32 -1, i32* %4
br label %36
22: ; preds = %14
%23 = load i8*, i8** %6
%24 = load i8*, i8** %6
%25 = getelementptr inbounds i8, i8* %24, i64 1
%26 = load i8*, i8** %6
%27 = getelementptr inbounds i8, i8* %26, i64 1
%28 = call i32 @strlen(i8* %27)
%29 = call i32 @memmove(i8* %23, i8* %25, i32 %28)
%30 = load i8*, i8** %6
%31 = load i8*, i8** %6
%32 = call i32 @strlen(i8* %31)
%33 = sub nsw i32 %32, 1
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %30, i64 %34
store i8 0, i8* %35
store i32 0, i32* %4
br label %36
36: ; preds = %22, %21, %13
%37 = load i32, i32* %4
ret i32 %37
}

LLVM IR (-O2):
define i32 @pserver_decrypt_password(i8* %0, i8* %1, i32 %2) {
%4 = load i8, i8* %0
%5 = icmp eq i8 %4, 65
br i1 %5, label %6, label %18
6: ; preds = %3
%7 = getelementptr inbounds i8, i8* %0, i64 1
%8 = tail call i64 @pserver_crypt_password(i8* %7, i8* %1, i32 %2)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %18
10: ; preds = %6
%11 = getelementptr inbounds i8, i8* %1, i64 1
%12 = tail call i32 @strlen(i8* %11)
%13 = tail call i32 @memmove(i8* %1, i8* %11, i32 %12)
%14 = tail call i32 @strlen(i8* %1)
%15 = add nsw i32 %14, -1
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %1, i64 %16
store i8 0, i8* %17
br label %18
18: ; preds = %6, %3, %10
%19 = phi i32 [ 0, %10 ], [ -1, %3 ], [ -1, %6 ]
ret i32 %19
}