#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*/ md5_crypt_redhat(char const *, char const *);
int /*<<< orphan*/ md5_hash_courier(char const *);
int strcmp(char const *, int /*<<< orphan*/);
scalar_t__ strncasecmp(char const *, char *, int);
scalar_t__ strncmp(char const *, char *, int);
int authcheckpasswordmd5(const char *password, const char *encrypted_password) {
  if (strncmp(encrypted_password, "$1$", 3) == 0) {
    return (strcmp(encrypted_password,
                   md5_crypt_redhat(password, encrypted_password)));
  }
  if (strncasecmp(encrypted_password, "{MD5}", 5) == 0) {
    return (strcmp(encrypted_password + 5, md5_hash_courier(password)));
  }
  return (-1);
}


x86 assembly (clang, -O0):
<authcheckpasswordmd5>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe95(%rip),%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    11a7 <authcheckpasswordmd5+0x57>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <md5_crypt_redhat@plt>
mov    -0x20(%rbp),%rdi
mov    %eax,%esi
call   1050 <strcmp@plt>
mov    %eax,-0x4(%rbp)
jmp    11f5 <authcheckpasswordmd5+0xa5>
mov    -0x18(%rbp),%rdi
lea    0xe52(%rip),%rsi
mov    $0x5,%edx
call   1060 <strncasecmp@plt>
cmp    $0x0,%rax
jne    11ee <authcheckpasswordmd5+0x9e>
mov    -0x18(%rbp),%rax
add    $0x5,%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <md5_hash_courier@plt>
mov    -0x28(%rbp),%rdi
mov    %eax,%esi
call   1050 <strcmp@plt>
mov    %eax,-0x4(%rbp)
jmp    11f5 <authcheckpasswordmd5+0xa5>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<authcheckpasswordmd5>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0xe9f(%rip),%rsi
mov    %rbx,%rdi
mov    $0x3,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1199 <authcheckpasswordmd5+0x49>
lea    0xe8a(%rip),%rsi
mov    %rbx,%rdi
mov    $0x5,%edx
call   1060 <strncasecmp@plt>
test   %rax,%rax
je     11a6 <authcheckpasswordmd5+0x56>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <md5_crypt_redhat@plt>
jmp    11b2 <authcheckpasswordmd5+0x62>
add    $0x5,%rbx
mov    %r14,%rdi
call   1070 <md5_hash_courier@plt>
mov    %rbx,%rdi
mov    %eax,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <strcmp@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"$1$\00"
@.str.1 = [6 x i8] c"{MD5}\00"
define i32 @authcheckpasswordmd5(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%6 = load i8*, i8** %5
%7 = call i64 @strncmp(i8* %6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 3)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %15
9: ; preds = %2
%10 = load i8*, i8** %5
%11 = load i8*, i8** %4
%12 = load i8*, i8** %5
%13 = call i32 @md5_crypt_redhat(i8* %11, i8* %12)
%14 = call i32 @strcmp(i8* %10, i32 %13)
store i32 %14, i32* %3
br label %26
15: ; preds = %2
%16 = load i8*, i8** %5
%17 = call i64 @strncasecmp(i8* %16, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 5)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %25
19: ; preds = %15
%20 = load i8*, i8** %5
%21 = getelementptr inbounds i8, i8* %20, i64 5
%22 = load i8*, i8** %4
%23 = call i32 @md5_hash_courier(i8* %22)
%24 = call i32 @strcmp(i8* %21, i32 %23)
store i32 %24, i32* %3
br label %26
25: ; preds = %15
store i32 -1, i32* %3
br label %26
26: ; preds = %25, %19, %9
%27 = load i32, i32* %3
ret i32 %27
}

LLVM IR (-O2):
@.str = [4 x i8] c"$1$\00"
@.str.1 = [6 x i8] c"{MD5}\00"
define i32 @authcheckpasswordmd5(i8* %0, i8* %1) {
%3 = tail call i64 @strncmp(i8* %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 3)
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = tail call i32 @md5_crypt_redhat(i8* %0, i8* %1)
%7 = tail call i32 @strcmp(i8* %1, i32 %6)
br label %15
8: ; preds = %2
%9 = tail call i64 @strncasecmp(i8* %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 5)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %8
%12 = getelementptr inbounds i8, i8* %1, i64 5
%13 = tail call i32 @md5_hash_courier(i8* %0)
%14 = tail call i32 @strcmp(i8* %12, i32 %13)
br label %15
15: ; preds = %8, %11, %5
%16 = phi i32 [ %7, %5 ], [ %14, %11 ], [ -1, %8 ]
ret i32 %16
}