#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 */
typedef int /*<<< orphan*/ randbuffer;

/* Variables and functions */
int /*<<< orphan*/ _pass_get_random(char *, int);
char *md5_crypt(char const *, char *);
int /*<<< orphan*/ strncpy(char *, char const *, size_t);
int changepass_md5(const char *pass, char *buffer, size_t len) {
  const char *cipher;
  char randbuffer[16];
  if (!pass || !buffer || len <= 0)
    return -1;
  _pass_get_random(randbuffer, sizeof(randbuffer));
  cipher = md5_crypt(pass, randbuffer);
  strncpy(buffer, cipher, len);
  return 0;
}


x86 assembly (clang, -O0):
<changepass_md5>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1165 <changepass_md5+0x35>
cmpq   $0x0,-0x18(%rbp)
je     1165 <changepass_md5+0x35>
cmpq   $0x0,-0x20(%rbp)
ja     1171 <changepass_md5+0x41>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a8 <changepass_md5+0x78>
lea    -0x40(%rbp),%rdi
mov    $0x10,%esi
call   1040 <_pass_get_random@plt>
mov    -0x10(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1050 <md5_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    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<changepass_md5>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    $0xffffffff,%eax
test   %rdi,%rdi
je     1183 <changepass_md5+0x53>
mov    %rsi,%r15
test   %rsi,%rsi
je     1183 <changepass_md5+0x53>
mov    %rdx,%r14
test   %rdx,%rdx
je     1183 <changepass_md5+0x53>
mov    %rdi,%rbx
mov    %rsp,%r12
mov    %r12,%rdi
mov    $0x10,%esi
call   1040 <_pass_get_random@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1050 <md5_crypt@plt>
mov    %r15,%rdi
mov    %rax,%rsi
mov    %r14,%rdx
call   1030 <strncpy@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @changepass_md5(i8* %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i8*
%9 = alloca [16 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 %29
19: ; preds = %15
%20 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
%21 = call i32 @_pass_get_random(i8* %20, i32 16)
%22 = load i8*, i8** %5
%23 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
%24 = call i8* @md5_crypt(i8* %22, i8* %23)
store i8* %24, i8** %8
%25 = load i8*, i8** %6
%26 = load i8*, i8** %8
%27 = load i64, i64* %7
%28 = call i32 @strncpy(i8* %25, i8* %26, i64 %27)
store i32 0, i32* %4
br label %29
29: ; preds = %19, %18
%30 = load i32, i32* %4
ret i32 %30
}

LLVM IR (-O2):
define i32 @changepass_md5(i8* %0, i8* %1, i64 %2) {
%4 = alloca [16 x i8]
%5 = getelementptr inbounds [16 x i8], [16 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 %15, label %11
11: ; preds = %3
%12 = call i32 @_pass_get_random(i8* %5, i32 16)
%13 = call i8* @md5_crypt(i8* %0, i8* %5)
%14 = call i32 @strncpy(i8* %1, i8* %13, i64 %2)
br label %15
15: ; preds = %3, %11
%16 = phi i32 [ 0, %11 ], [ -1, %3 ]
ret i32 %16
}