#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;
int /*<<< orphan*/ _error(char *, int);
char *_makepasswd_password(char const *, int, int);
char *crypt(char const *, char const *);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ free(char *);
char *strdup(char *);
char *_hash_des(char const *password, char const *salt) {
  char *ret;
  const char characters[] = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
                            "abcdefghijklmnopqrstuvwxyz";
  char *p = NULL;
  if (salt != NULL) {
    if (salt[0] == '$' || salt[0] == '_') {
      errno = EINVAL;
      _error("des", 1);
      return NULL;
    }
  } else if ((p = _makepasswd_password(characters, 2, 2)) == NULL)
    return NULL;
  else
    salt = p;
  ret = crypt(password, salt);
  free(p);
  if (ret == NULL) {
    _error("crypt", 1);
    return NULL;
  }
  if ((ret = strdup(ret)) == NULL)
    _error("malloc", 1);
  return ret;
}


x86 assembly (clang, -O0):
<_hash_des>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    -0x70(%rbp),%rdi
lea    0xe82(%rip),%rsi
mov    $0x41,%edx
call   1060 <memcpy@plt>
movq   $0x0,-0x78(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11f0 <_hash_des+0x90>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x24,%eax
je     11bb <_hash_des+0x5b>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5f,%eax
jne    11eb <_hash_des+0x8b>
mov    0x2e16(%rip),%rax
mov    (%rax),%ecx
mov    0x2e15(%rip),%rax
mov    %ecx,(%rax)
lea    0xe6d(%rip),%rdi
mov    $0x1,%esi
call   1070 <_error@plt>
movq   $0x0,-0x8(%rbp)
jmp    129b <_hash_des+0x13b>
jmp    1228 <_hash_des+0xc8>
lea    -0x70(%rbp),%rdi
mov    $0x2,%edx
mov    %edx,%esi
call   1040 <_makepasswd_password@plt>
mov    %rax,-0x78(%rbp)
cmp    $0x0,%rax
jne    121b <_hash_des+0xbb>
movq   $0x0,-0x8(%rbp)
jmp    129b <_hash_des+0x13b>
mov    -0x78(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    1228 <_hash_des+0xc8>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <crypt@plt>
mov    %rax,-0x20(%rbp)
mov    -0x78(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x20(%rbp)
jne    126b <_hash_des+0x10b>
lea    0xdf1(%rip),%rdi
mov    $0x1,%esi
call   1070 <_error@plt>
movq   $0x0,-0x8(%rbp)
jmp    129b <_hash_des+0x13b>
mov    -0x20(%rbp),%rdi
call   1080 <strdup@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1293 <_hash_des+0x133>
lea    0xdc2(%rip),%rdi
mov    $0x1,%esi
call   1070 <_error@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_hash_des>:
push   %r15
push   %r14
push   %rbx
sub    $0x50,%rsp
mov    %rdi,%r14
movaps 0xecd(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xeb1(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xe95(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xe79(%rip),%xmm0
movaps %xmm0,(%rsp)
movb   $0x0,0x40(%rsp)
test   %rsi,%rsi
je     11ba <_hash_des+0x6a>
mov    (%rsi),%al
cmp    $0x5f,%al
je     119f <_hash_des+0x4f>
cmp    $0x24,%al
jne    11d9 <_hash_des+0x89>
mov    0x2e32(%rip),%rax
mov    (%rax),%eax
mov    0x2e31(%rip),%rcx
mov    %eax,(%rcx)
lea    0xe89(%rip),%rdi
jmp    1211 <_hash_des+0xc1>
mov    %rsp,%rdi
mov    $0x2,%esi
mov    $0x2,%edx
call   1040 <_makepasswd_password@plt>
mov    %rax,%rsi
mov    %rax,%r15
test   %rax,%rax
jne    11dc <_hash_des+0x8c>
jmp    121b <_hash_des+0xcb>
xor    %r15d,%r15d
mov    %r14,%rdi
call   1050 <crypt@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1030 <free@plt>
test   %rbx,%rbx
je     120a <_hash_des+0xba>
mov    %rbx,%rdi
call   1070 <strdup@plt>
test   %rax,%rax
jne    121d <_hash_des+0xcd>
lea    0xe43(%rip),%rdi
jmp    1211 <_hash_des+0xc1>
lea    0xe34(%rip),%rdi
mov    $0x1,%esi
call   1060 <_error@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const._hash_des.characters = [65 x i8] c"./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\00"
@EINVAL = global i32 0
@errno = global i32 0
@.str = [4 x i8] c"des\00"
@.str.1 = [6 x i8] c"crypt\00"
@.str.2 = [7 x i8] c"malloc\00"
define i8* @_hash_des(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca [65 x i8]
%8 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%9 = bitcast [65 x i8]* %7 to i8*
store i8* null, i8** %8
%10 = load i8*, i8** %5
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %28
12: ; preds = %2
%13 = load i8*, i8** %5
%14 = getelementptr inbounds i8, i8* %13, i64 0
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp eq i32 %16, 36
br i1 %17, label %24, label %18
18: ; preds = %12
%19 = load i8*, i8** %5
%20 = getelementptr inbounds i8, i8* %19, i64 0
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp eq i32 %22, 95
br i1 %23, label %24, label %27
24: ; preds = %18, %12
%25 = load i32, i32* @EINVAL
store i32 %25, i32* @errno
%26 = call i32 @_error(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 1)
store i8* null, i8** %3
br label %54
27: ; preds = %18
br label %36
28: ; preds = %2
%29 = getelementptr inbounds [65 x i8], [65 x i8]* %7, i64 0, i64 0
%30 = call i8* @_makepasswd_password(i8* %29, i32 2, i32 2)
store i8* %30, i8** %8
%31 = icmp eq i8* %30, null
br i1 %31, label %32, label %33
32: ; preds = %28
store i8* null, i8** %3
br label %54
33: ; preds = %28
%34 = load i8*, i8** %8
store i8* %34, i8** %5
br label %35
35: ; preds = %33
br label %36
36: ; preds = %35, %27
%37 = load i8*, i8** %4
%38 = load i8*, i8** %5
%39 = call i8* @crypt(i8* %37, i8* %38)
store i8* %39, i8** %6
%40 = load i8*, i8** %8
%41 = call i32 @free(i8* %40)
%42 = load i8*, i8** %6
%43 = icmp eq i8* %42, null
br i1 %43, label %44, label %46
44: ; preds = %36
%45 = call i32 @_error(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 1)
store i8* null, i8** %3
br label %54
46: ; preds = %36
%47 = load i8*, i8** %6
%48 = call i8* @strdup(i8* %47)
store i8* %48, i8** %6
%49 = icmp eq i8* %48, null
br i1 %49, label %50, label %52
50: ; preds = %46
%51 = call i32 @_error(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 1)
br label %52
52: ; preds = %50, %46
%53 = load i8*, i8** %6
store i8* %53, i8** %3
br label %54
54: ; preds = %52, %44, %32, %24
%55 = load i8*, i8** %3
ret i8* %55
}

LLVM IR (-O2):
@__const._hash_des.characters = [65 x i8] c"./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\00"
@EINVAL = global i32 0
@errno = global i32 0
@.str = [4 x i8] c"des\00"
@.str.1 = [6 x i8] c"crypt\00"
@.str.2 = [7 x i8] c"malloc\00"
define noalias i8* @_hash_des(i8* %0, i8* %1) {
%3 = alloca [65 x i8]
%4 = getelementptr inbounds [65 x i8], [65 x i8]* %3, i64 0, i64 0
%5 = icmp eq i8* %1, null
br i1 %5, label %11, label %6
6: ; preds = %2
%7 = load i8, i8* %1
switch i8 %7, label %14 [
i8 36, label %8
i8 95, label %8
]
8: ; preds = %6, %6
%9 = load i32, i32* @EINVAL
store i32 %9, i32* @errno
%10 = tail call i32 @_error(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 1)
br label %27
11: ; preds = %2
%12 = call i8* @_makepasswd_password(i8* %4, i32 2, i32 2)
%13 = icmp eq i8* %12, null
br i1 %13, label %27, label %14
14: ; preds = %11, %6
%15 = phi i8* [ %1, %6 ], [ %12, %11 ]
%16 = phi i8* [ null, %6 ], [ %12, %11 ]
%17 = call i8* @crypt(i8* %0, i8* %15)
%18 = call i32 @free(i8* %16)
%19 = icmp eq i8* %17, null
br i1 %19, label %20, label %22
20: ; preds = %14
%21 = call i32 @_error(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 1)
br label %27
22: ; preds = %14
%23 = call i8* @strdup(i8* %17)
%24 = icmp eq i8* %23, null
br i1 %24, label %25, label %27
25: ; preds = %22
%26 = call i32 @_error(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 1)
br label %27
27: ; preds = %22, %25, %11, %20, %8
%28 = phi i8* [ null, %8 ], [ null, %20 ], [ null, %11 ], [ null, %25 ], [ %23, %22 ]
ret i8* %28
}