#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*/ EINVAL;
char *__des_crypt(unsigned char const *, unsigned char const *);
char *__md5_crypt(unsigned char const *, unsigned char const *);
int /*<<< orphan*/ __set_errno(int /*<<< orphan*/);
char *crypt(const char *key, const char *salt) {
  const unsigned char *ukey = (const unsigned char *)key;
  const unsigned char *usalt = (const unsigned char *)salt;
  if (salt[0] == '$') {
    if (salt[1] && salt[2] == '$') {
      if (*++salt == '1')
        return __md5_crypt(ukey, usalt);
    }
    __set_errno(EINVAL);
    return NULL;
  }
  return __des_crypt(ukey, usalt);
}


x86 assembly (clang, -O0):
<crypt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x24,%eax
jne    11d4 <crypt+0xa4>
mov    -0x18(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x0,%eax
je     11b9 <crypt+0x89>
mov    -0x18(%rbp),%rax
movsbl 0x2(%rax),%eax
cmp    $0x24,%eax
jne    11b9 <crypt+0x89>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movsbl 0x1(%rax),%eax
cmp    $0x31,%eax
jne    11b4 <crypt+0x84>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1040 <__md5_crypt@plt>
mov    %rax,-0x8(%rbp)
jmp    11e5 <crypt+0xb5>
jmp    11b9 <crypt+0x89>
mov    0x2e20(%rip),%rax
mov    (%rax),%edi
call   1030 <__set_errno@plt>
movq   $0x0,-0x8(%rbp)
jmp    11e5 <crypt+0xb5>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1050 <__des_crypt@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<crypt>:
push   %rax
cmpb   $0x24,(%rsi)
jne    114d <crypt+0x1d>
mov    0x1(%rsi),%al
test   %al,%al
je     1153 <crypt+0x23>
cmpb   $0x24,0x2(%rsi)
jne    1153 <crypt+0x23>
cmp    $0x31,%al
jne    1153 <crypt+0x23>
pop    %rax
jmp    1040 <__md5_crypt@plt>
pop    %rax
jmp    1050 <__des_crypt@plt>
mov    0x2e86(%rip),%rax
mov    (%rax),%edi
call   1030 <__set_errno@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@EINVAL = global i32 0
define i8* @crypt(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %4
store i8* %8, i8** %6
%9 = load i8*, i8** %5
store i8* %9, i8** %7
%10 = load i8*, i8** %5
%11 = getelementptr inbounds i8, i8* %10, i64 0
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp eq i32 %13, 36
br i1 %14, label %15, label %41
15: ; preds = %2
%16 = load i8*, i8** %5
%17 = getelementptr inbounds i8, i8* %16, i64 1
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %38
21: ; preds = %15
%22 = load i8*, i8** %5
%23 = getelementptr inbounds i8, i8* %22, i64 2
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %25, 36
br i1 %26, label %27, label %38
27: ; preds = %21
%28 = load i8*, i8** %5
%29 = getelementptr inbounds i8, i8* %28, i32 1
store i8* %29, i8** %5
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp eq i32 %31, 49
br i1 %32, label %33, label %37
33: ; preds = %27
%34 = load i8*, i8** %6
%35 = load i8*, i8** %7
%36 = call i8* @__md5_crypt(i8* %34, i8* %35)
store i8* %36, i8** %3
br label %45
37: ; preds = %27
br label %38
38: ; preds = %37, %21, %15
%39 = load i32, i32* @EINVAL
%40 = call i32 @__set_errno(i32 %39)
store i8* null, i8** %3
br label %45
41: ; preds = %2
%42 = load i8*, i8** %6
%43 = load i8*, i8** %7
%44 = call i8* @__des_crypt(i8* %42, i8* %43)
store i8* %44, i8** %3
br label %45
45: ; preds = %41, %38, %33
%46 = load i8*, i8** %3
ret i8* %46
}

LLVM IR (-O2):
@EINVAL = global i32 0
define i8* @crypt(i8* %0, i8* %1) {
%3 = load i8, i8* %1
%4 = icmp eq i8 %3, 36
br i1 %4, label %5, label %20
5: ; preds = %2
%6 = getelementptr inbounds i8, i8* %1, i64 1
%7 = load i8, i8* %6
%8 = icmp eq i8 %7, 0
br i1 %8, label %17, label %9
9: ; preds = %5
%10 = getelementptr inbounds i8, i8* %1, i64 2
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 36
%13 = icmp eq i8 %7, 49
%14 = select i1 %12, i1 %13, i1 false
br i1 %14, label %15, label %17
15: ; preds = %9
%16 = tail call i8* @__md5_crypt(i8* %0, i8* %1)
br label %22
17: ; preds = %9, %5
%18 = load i32, i32* @EINVAL
%19 = tail call i32 @__set_errno(i32 %18)
br label %22
20: ; preds = %2
%21 = tail call i8* @__des_crypt(i8* %0, i8* %1)
br label %22
22: ; preds = %20, %17, %15
%23 = phi i8* [ %16, %15 ], [ null, %17 ], [ %21, %20 ]
ret i8* %23
}