#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 *crypt(char const *, char const *);
int /*<<< orphan*/ strcmp(char const *, char const *);
int /*<<< orphan*/ strncasecmp(char const *, char *, int);
int /*<<< orphan*/ strncmp(char const *, char *, int);
int pass_matches(const char *pass, const char *attempt) {
  int des;
  if ((des = !strncasecmp(pass, "{crypt}", sizeof("{crypt}") - 1)))
    pass += sizeof("{crypt}") - 1;
  if (des || !strncmp(pass, "$1$", sizeof("$1$") - 1))
    attempt = crypt(attempt, pass);
  if (!attempt) {
    return 0;
  }
  return !strcmp(pass, attempt);
}


x86 assembly (clang, -O0):
<pass_matches>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea5(%rip),%rsi
mov    $0x7,%edx
call   1060 <strncasecmp@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,%cl
and    $0x1,%cl
movzbl %cl,%ecx
mov    %ecx,-0x1c(%rbp)
test   $0x1,%al
jne    1185 <pass_matches+0x45>
jmp    1191 <pass_matches+0x51>
mov    -0x10(%rbp),%rax
add    $0x7,%rax
mov    %rax,-0x10(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    11b9 <pass_matches+0x79>
mov    -0x10(%rbp),%rdi
lea    0xe62(%rip),%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    11ca <pass_matches+0x8a>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <crypt@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11e1 <pass_matches+0xa1>
movl   $0x0,-0x4(%rbp)
jmp    11fe <pass_matches+0xbe>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pass_matches>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xeae(%rip),%rsi
mov    $0x7,%edx
call   1060 <strncasecmp@plt>
lea    0x7(%rbx),%r15
test   %eax,%eax
cmovne %rbx,%r15
je     119b <pass_matches+0x5b>
lea    0xe99(%rip),%rsi
mov    %r15,%rdi
mov    $0x3,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
je     119b <pass_matches+0x5b>
test   %r14,%r14
je     11ae <pass_matches+0x6e>
mov    %r15,%rdi
mov    %r14,%rsi
call   1050 <strcmp@plt>
mov    %eax,%ecx
xor    %eax,%eax
test   %ecx,%ecx
sete   %al
jmp    11b0 <pass_matches+0x70>
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <crypt@plt>
mov    %rax,%r14
test   %r14,%r14
jne    1185 <pass_matches+0x45>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [8 x i8] c"{crypt}\00"
@.str.1 = [4 x i8] c"$1$\00"
define i32 @pass_matches(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%7 = load i8*, i8** %4
%8 = call i32 @strncasecmp(i8* %7, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 7)
%9 = icmp ne i32 %8, 0
%10 = xor i1 %9, true
%11 = zext i1 %10 to i32
store i32 %11, i32* %6
br i1 %10, label %12, label %15
12: ; preds = %2
%13 = load i8*, i8** %4
%14 = getelementptr inbounds i8, i8* %13, i64 7
store i8* %14, i8** %4
br label %15
15: ; preds = %12, %2
%16 = load i32, i32* %6
%17 = icmp ne i32 %16, 0
br i1 %17, label %22, label %18
18: ; preds = %15
%19 = load i8*, i8** %4
%20 = call i32 @strncmp(i8* %19, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 3)
%21 = icmp ne i32 %20, 0
br i1 %21, label %26, label %22
22: ; preds = %18, %15
%23 = load i8*, i8** %5
%24 = load i8*, i8** %4
%25 = call i8* @crypt(i8* %23, i8* %24)
store i8* %25, i8** %5
br label %26
26: ; preds = %22, %18
%27 = load i8*, i8** %5
%28 = icmp ne i8* %27, null
br i1 %28, label %30, label %29
29: ; preds = %26
store i32 0, i32* %3
br label %37
30: ; preds = %26
%31 = load i8*, i8** %4
%32 = load i8*, i8** %5
%33 = call i32 @strcmp(i8* %31, i8* %32)
%34 = icmp ne i32 %33, 0
%35 = xor i1 %34, true
%36 = zext i1 %35 to i32
store i32 %36, i32* %3
br label %37
37: ; preds = %30, %29
%38 = load i32, i32* %3
ret i32 %38
}

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