#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 *);
int rand();
int /*<<< orphan*/ strncpy(char *, char *, size_t);
int changepass_crypt(const char *pass, char *buffer, size_t len) {
  char *cipher;
  char salt[3];
  if (!pass || !buffer || len <= 0)
    return -1;
  salt[0] = 'a' + (char)(rand() % 26);
  salt[1] = 'a' + (char)((rand() * 72 + 3) % 26);
  cipher = crypt(pass, salt);
  strncpy(buffer, cipher, len);
  return 0;
}


x86 assembly (clang, -O0):
<changepass_crypt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1165 <changepass_crypt+0x35>
cmpq   $0x0,-0x18(%rbp)
je     1165 <changepass_crypt+0x35>
cmpq   $0x0,-0x20(%rbp)
ja     1171 <changepass_crypt+0x41>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d4 <changepass_crypt+0xa4>
mov    $0x0,%al
call   1050 <rand@plt>
mov    $0x1a,%ecx
cltd
idiv   %ecx
mov    %dl,%al
movsbl %al,%eax
add    $0x61,%eax
mov    %al,-0x2b(%rbp)
mov    $0x0,%al
call   1050 <rand@plt>
imul   $0x48,%eax,%eax
add    $0x3,%eax
mov    $0x1a,%ecx
cltd
idiv   %ecx
mov    %dl,%al
movsbl %al,%eax
add    $0x61,%eax
mov    %al,-0x2a(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x2b(%rbp),%rsi
call   1040 <crypt@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <strncpy@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<changepass_crypt>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    $0xffffffff,%r15d
test   %rdi,%rdi
je     11e2 <changepass_crypt+0xb2>
mov    %rsi,%rbx
test   %rsi,%rsi
je     11e2 <changepass_crypt+0xb2>
mov    %rdx,%r14
test   %rdx,%rdx
je     11e2 <changepass_crypt+0xb2>
mov    %rdi,%rbp
xor    %r15d,%r15d
xor    %eax,%eax
call   1050 <rand@plt>
cltq
imul   $0x4ec4ec4f,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
shr    $0x23,%rcx
add    %edx,%ecx
lea    (%rcx,%rcx,4),%edx
lea    (%rdx,%rdx,4),%edx
add    %ecx,%edx
sub    %edx,%eax
add    $0x61,%al
mov    %al,0x5(%rsp)
xor    %eax,%eax
call   1050 <rand@plt>
shl    $0x3,%eax
lea    (%rax,%rax,8),%eax
or     $0x3,%eax
cltq
imul   $0x4ec4ec4f,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
shr    $0x23,%rcx
add    %edx,%ecx
lea    (%rcx,%rcx,4),%edx
lea    (%rdx,%rdx,4),%edx
add    %ecx,%edx
sub    %edx,%eax
add    $0x61,%al
mov    %al,0x6(%rsp)
lea    0x5(%rsp),%rsi
mov    %rbp,%rdi
call   1040 <crypt@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
mov    %r14,%rdx
call   1030 <strncpy@plt>
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @changepass_crypt(i8* %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i8*
%9 = alloca [3 x i8]
store i8* %0, i8** %5
store i8* %1, i8** %6
store i64 %2, i64* %7
%10 = load i8*, i8** %5
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %18
12: ; preds = %3
%13 = load i8*, i8** %6
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = load i64, i64* %7
%17 = icmp ule i64 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %15, %12, %3
store i32 -1, i32* %4
br label %43
19: ; preds = %15
%20 = call i32 (...) @rand()
%21 = srem i32 %20, 26
%22 = trunc i32 %21 to i8
%23 = sext i8 %22 to i32
%24 = add nsw i32 97, %23
%25 = trunc i32 %24 to i8
%26 = getelementptr inbounds [3 x i8], [3 x i8]* %9, i64 0, i64 0
store i8 %25, i8* %26
%27 = call i32 (...) @rand()
%28 = mul nsw i32 %27, 72
%29 = add nsw i32 %28, 3
%30 = srem i32 %29, 26
%31 = trunc i32 %30 to i8
%32 = sext i8 %31 to i32
%33 = add nsw i32 97, %32
%34 = trunc i32 %33 to i8
%35 = getelementptr inbounds [3 x i8], [3 x i8]* %9, i64 0, i64 1
store i8 %34, i8* %35
%36 = load i8*, i8** %5
%37 = getelementptr inbounds [3 x i8], [3 x i8]* %9, i64 0, i64 0
%38 = call i8* @crypt(i8* %36, i8* %37)
store i8* %38, i8** %8
%39 = load i8*, i8** %6
%40 = load i8*, i8** %8
%41 = load i64, i64* %7
%42 = call i32 @strncpy(i8* %39, i8* %40, i64 %41)
store i32 0, i32* %4
br label %43
43: ; preds = %19, %18
%44 = load i32, i32* %4
ret i32 %44
}

LLVM IR (-O2):
define i32 @changepass_crypt(i8* %0, i8* %1, i64 %2) {
%4 = alloca [3 x i8]
%5 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 0
%6 = icmp eq i8* %0, null
%7 = icmp eq i8* %1, null
%8 = or i1 %6, %7
%9 = icmp eq i64 %2, 0
%10 = or i1 %8, %9
br i1 %10, label %25, label %11
11: ; preds = %3
%12 = tail call i32 (...) @rand()
%13 = srem i32 %12, 26
%14 = trunc i32 %13 to i8
%15 = add nsw i8 %14, 97
store i8 %15, i8* %5
%16 = tail call i32 (...) @rand()
%17 = mul nsw i32 %16, 72
%18 = or i32 %17, 3
%19 = srem i32 %18, 26
%20 = trunc i32 %19 to i8
%21 = add nsw i8 %20, 97
%22 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 1
store i8 %21, i8* %22
%23 = call i8* @crypt(i8* %0, i8* %5)
%24 = call i32 @strncpy(i8* %1, i8* %23, i64 %2)
br label %25
25: ; preds = %3, %11
%26 = phi i32 [ 0, %11 ], [ -1, %3 ]
ret i32 %26
}