#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*/ MD5(unsigned char *, size_t, unsigned char *);
size_t MD5_DIGEST_LENGTH;
int /*<<< orphan*/ free(unsigned char *);
unsigned char *malloc(size_t);
int /*<<< orphan*/ memcpy(void *, void *, size_t);
unsigned char *get_derived_key(unsigned char *md5, unsigned char *pass,
                               size_t pass_len, unsigned char *salt,
                               size_t salt_len) {
  unsigned char *buf = malloc(((pass_len + salt_len) > (MD5_DIGEST_LENGTH)
                                   ? (pass_len + salt_len)
                                   : (MD5_DIGEST_LENGTH)));
  int i;
  if ((md5 == NULL) || (pass == NULL) || (salt == NULL)) {
    do {
    } while (0);
    free(buf);
    return NULL;
  }
  if (buf == NULL) {
    do {
    } while (0);
    return NULL;
  }
  memcpy(buf, pass, pass_len);
  memcpy(buf + pass_len, salt, salt_len);
  MD5(buf, pass_len + salt_len, md5);
  memcpy((void *)buf, (void *)md5, MD5_DIGEST_LENGTH);
  for (i = 0; i < 1000 - 1; i++) {
    MD5(buf, MD5_DIGEST_LENGTH, md5);
    memcpy((void *)buf, (void *)md5, MD5_DIGEST_LENGTH);
  }
  free(buf);
  return md5;
}


x86 assembly (clang, -O0):
<get_derived_key>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    -0x20(%rbp),%rax
add    -0x30(%rbp),%rax
mov    0x2e75(%rip),%rcx
cmp    (%rcx),%rax
jbe    1185 <get_derived_key+0x45>
mov    -0x20(%rbp),%rax
add    -0x30(%rbp),%rax
mov    %rax,-0x48(%rbp)
jmp    1193 <get_derived_key+0x53>
mov    0x2e54(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rdi
call   1050 <malloc@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11c1 <get_derived_key+0x81>
cmpq   $0x0,-0x18(%rbp)
je     11c1 <get_derived_key+0x81>
cmpq   $0x0,-0x28(%rbp)
jne    11e1 <get_derived_key+0xa1>
jmp    11c6 <get_derived_key+0x86>
jmp    11cb <get_derived_key+0x8b>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    12b6 <get_derived_key+0x176>
cmpq   $0x0,-0x38(%rbp)
jne    1203 <get_derived_key+0xc3>
jmp    11f1 <get_derived_key+0xb1>
jmp    11f6 <get_derived_key+0xb6>
movq   $0x0,-0x8(%rbp)
jmp    12b6 <get_derived_key+0x176>
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1040 <memcpy@plt>
mov    -0x38(%rbp),%rdi
add    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1040 <memcpy@plt>
mov    -0x38(%rbp),%rdi
mov    -0x20(%rbp),%rsi
add    -0x30(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1060 <MD5@plt>
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    0x2d93(%rip),%rax
mov    (%rax),%rdx
call   1040 <memcpy@plt>
movl   $0x0,-0x3c(%rbp)
cmpl   $0x3e7,-0x3c(%rbp)
jge    12a5 <get_derived_key+0x165>
mov    -0x38(%rbp),%rdi
mov    0x2d6c(%rip),%rax
mov    (%rax),%rsi
mov    -0x10(%rbp),%rdx
call   1060 <MD5@plt>
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    0x2d51(%rip),%rax
mov    (%rax),%rdx
call   1040 <memcpy@plt>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    125c <get_derived_key+0x11c>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_derived_key>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,0x8(%rsp)
mov    %rdx,%rbp
mov    %rsi,%r13
mov    %rdi,%r14
mov    %r8,0x10(%rsp)
lea    (%r8,%rdx,1),%r15
mov    0x2e74(%rip),%r12
mov    (%r12),%rdi
cmp    %rdi,%r15
cmova  %r15,%rdi
call   1050 <malloc@plt>
mov    %rax,%rbx
test   %r14,%r14
je     121d <get_derived_key+0xdd>
test   %r13,%r13
je     121d <get_derived_key+0xdd>
cmpq   $0x0,0x8(%rsp)
je     121d <get_derived_key+0xdd>
test   %rbx,%rbx
je     1225 <get_derived_key+0xe5>
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %rbp,%rdx
call   1040 <memcpy@plt>
mov    %rbx,%rdi
add    %rbp,%rdi
mov    0x8(%rsp),%rsi
mov    0x10(%rsp),%rdx
call   1040 <memcpy@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1060 <MD5@plt>
mov    (%r12),%rdx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <memcpy@plt>
mov    $0x3e7,%ebp
nopl   0x0(%rax,%rax,1)
mov    (%r12),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
call   1060 <MD5@plt>
mov    (%r12),%rdx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <memcpy@plt>
add    $0xffffffff,%ebp
jne    11f0 <get_derived_key+0xb0>
mov    %rbx,%rdi
call   1030 <free@plt>
jmp    1228 <get_derived_key+0xe8>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@MD5_DIGEST_LENGTH = global i64 0
define i8* @get_derived_key(i8* %0, i8* %1, i64 %2, i8* %3, i64 %4) {
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i8*
%13 = alloca i32
store i8* %0, i8** %7
store i8* %1, i8** %8
store i64 %2, i64* %9
store i8* %3, i8** %10
store i64 %4, i64* %11
%14 = load i64, i64* %9
%15 = load i64, i64* %11
%16 = add i64 %14, %15
%17 = load i64, i64* @MD5_DIGEST_LENGTH
%18 = icmp ugt i64 %16, %17
br i1 %18, label %19, label %23
19: ; preds = %5
%20 = load i64, i64* %9
%21 = load i64, i64* %11
%22 = add i64 %20, %21
br label %25
23: ; preds = %5
%24 = load i64, i64* @MD5_DIGEST_LENGTH
br label %25
25: ; preds = %23, %19
%26 = phi i64 [ %22, %19 ], [ %24, %23 ]
%27 = call i8* @malloc(i64 %26)
store i8* %27, i8** %12
%28 = load i8*, i8** %7
%29 = icmp eq i8* %28, null
br i1 %29, label %36, label %30
30: ; preds = %25
%31 = load i8*, i8** %8
%32 = icmp eq i8* %31, null
br i1 %32, label %36, label %33
33: ; preds = %30
%34 = load i8*, i8** %10
%35 = icmp eq i8* %34, null
br i1 %35, label %36, label %41
36: ; preds = %33, %30, %25
br label %37
37: ; preds = %36
br label %38
38: ; preds = %37
%39 = load i8*, i8** %12
%40 = call i32 @free(i8* %39)
store i8* null, i8** %6
br label %87
41: ; preds = %33
%42 = load i8*, i8** %12
%43 = icmp eq i8* %42, null
br i1 %43, label %44, label %47
44: ; preds = %41
br label %45
45: ; preds = %44
br label %46
46: ; preds = %45
store i8* null, i8** %6
br label %87
47: ; preds = %41
%48 = load i8*, i8** %12
%49 = load i8*, i8** %8
%50 = load i64, i64* %9
%51 = call i32 @memcpy(i8* %48, i8* %49, i64 %50)
%52 = load i8*, i8** %12
%53 = load i64, i64* %9
%54 = getelementptr inbounds i8, i8* %52, i64 %53
%55 = load i8*, i8** %10
%56 = load i64, i64* %11
%57 = call i32 @memcpy(i8* %54, i8* %55, i64 %56)
%58 = load i8*, i8** %12
%59 = load i64, i64* %9
%60 = load i64, i64* %11
%61 = add i64 %59, %60
%62 = load i8*, i8** %7
%63 = call i32 @MD5(i8* %58, i64 %61, i8* %62)
%64 = load i8*, i8** %12
%65 = load i8*, i8** %7
%66 = load i64, i64* @MD5_DIGEST_LENGTH
%67 = call i32 @memcpy(i8* %64, i8* %65, i64 %66)
store i32 0, i32* %13
br label %68
68: ; preds = %80, %47
%69 = load i32, i32* %13
%70 = icmp slt i32 %69, 999
br i1 %70, label %71, label %83
71: ; preds = %68
%72 = load i8*, i8** %12
%73 = load i64, i64* @MD5_DIGEST_LENGTH
%74 = load i8*, i8** %7
%75 = call i32 @MD5(i8* %72, i64 %73, i8* %74)
%76 = load i8*, i8** %12
%77 = load i8*, i8** %7
%78 = load i64, i64* @MD5_DIGEST_LENGTH
%79 = call i32 @memcpy(i8* %76, i8* %77, i64 %78)
br label %80
80: ; preds = %71
%81 = load i32, i32* %13
%82 = add nsw i32 %81, 1
store i32 %82, i32* %13
br label %68
83: ; preds = %68
%84 = load i8*, i8** %12
%85 = call i32 @free(i8* %84)
%86 = load i8*, i8** %7
store i8* %86, i8** %6
br label %87
87: ; preds = %83, %46, %38
%88 = load i8*, i8** %6
ret i8* %88
}

LLVM IR (-O2):
@MD5_DIGEST_LENGTH = global i64 0
define i8* @get_derived_key(i8* %0, i8* %1, i64 %2, i8* %3, i64 %4) {
%6 = add i64 %4, %2
%7 = load i64, i64* @MD5_DIGEST_LENGTH
%8 = icmp ugt i64 %6, %7
%9 = select i1 %8, i64 %6, i64 %7
%10 = tail call i8* @malloc(i64 %9)
%11 = icmp eq i8* %0, null
%12 = icmp eq i8* %1, null
%13 = or i1 %11, %12
%14 = icmp eq i8* %3, null
%15 = or i1 %13, %14
br i1 %15, label %16, label %18
16: ; preds = %5
%17 = tail call i32 @free(i8* %10)
br label %37
18: ; preds = %5
%19 = icmp eq i8* %10, null
br i1 %19, label %37, label %20
20: ; preds = %18
%21 = tail call i32 @memcpy(i8* %10, i8* %1, i64 %2)
%22 = getelementptr inbounds i8, i8* %10, i64 %2
%23 = tail call i32 @memcpy(i8* %22, i8* %3, i64 %4)
%24 = tail call i32 @MD5(i8* %10, i64 %6, i8* %0)
%25 = load i64, i64* @MD5_DIGEST_LENGTH
%26 = tail call i32 @memcpy(i8* %10, i8* %0, i64 %25)
br label %27
27: ; preds = %20, %27
%28 = phi i32 [ 0, %20 ], [ %33, %27 ]
%29 = load i64, i64* @MD5_DIGEST_LENGTH
%30 = tail call i32 @MD5(i8* %10, i64 %29, i8* %0)
%31 = load i64, i64* @MD5_DIGEST_LENGTH
%32 = tail call i32 @memcpy(i8* %10, i8* %0, i64 %31)
%33 = add nuw nsw i32 %28, 1
%34 = icmp eq i32 %33, 999
br i1 %34, label %35, label %27
35: ; preds = %27
%36 = tail call i32 @free(i8* %10)
br label %37
37: ; preds = %18, %35, %16
%38 = phi i8* [ null, %16 ], [ %0, %35 ], [ null, %18 ]
ret i8* %38
}