#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*/ MD5_CTX;

/* Variables and functions */
int /*<<< orphan*/ MD5_Final(unsigned char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ MD5_Init(int /*<<< orphan*/ *);
char hextoascii(unsigned char);
int /*<<< orphan*/ memset(char *, int, int);
int get_md5_token(char *token, int length) {
  unsigned char frame[(16 * 2) / 2];
  int i, j;
  MD5_CTX md5;
  if (!token || (length != (16 * 2))) {
    return -1;
  }
  memset(token, 0x00, length);
  MD5_Init(&md5);
  MD5_Final(frame, &md5);
  i = j = 0;
  for (i = 0; i < ((16 * 2) / 2); i++) {
    token[j++] = hextoascii(frame[i] >> 4);
    token[j++] = hextoascii(frame[i] & 0xF);
  }
  return 0;
}


x86 assembly (clang, -O0):
<get_md5_token>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1164 <get_md5_token+0x24>
cmpl   $0x20,-0x14(%rbp)
je     1170 <get_md5_token+0x30>
movl   $0xffffffff,-0x4(%rbp)
jmp    121e <get_md5_token+0xde>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
xor    %esi,%esi
call   1040 <memset@plt>
lea    -0x3c(%rbp),%rdi
call   1060 <MD5_Init@plt>
lea    -0x30(%rbp),%rdi
lea    -0x3c(%rbp),%rsi
call   1030 <MD5_Final@plt>
movl   $0x0,-0x38(%rbp)
movl   $0x0,-0x34(%rbp)
movl   $0x0,-0x34(%rbp)
cmpl   $0x10,-0x34(%rbp)
jge    1217 <get_md5_token+0xd7>
movslq -0x34(%rbp),%rax
movzbl -0x30(%rbp,%rax,1),%eax
sar    $0x4,%eax
movzbl %al,%edi
call   1050 <hextoascii@plt>
mov    %al,%dl
mov    -0x10(%rbp),%rax
mov    -0x38(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x38(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
movslq -0x34(%rbp),%rax
movzbl -0x30(%rbp,%rax,1),%eax
and    $0xf,%eax
movzbl %al,%edi
call   1050 <hextoascii@plt>
mov    %al,%dl
mov    -0x10(%rbp),%rax
mov    -0x38(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x38(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11a9 <get_md5_token+0x69>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_md5_token>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    $0xffffffff,%r14d
test   %rdi,%rdi
je     11c0 <get_md5_token+0x80>
cmp    $0x20,%esi
jne    11c0 <get_md5_token+0x80>
mov    %rdi,%r12
xor    %r14d,%r14d
xor    %esi,%esi
mov    $0x20,%edx
call   1040 <memset@plt>
lea    0xc(%rsp),%r15
mov    %r15,%rdi
call   1060 <MD5_Init@plt>
lea    0x10(%rsp),%rdi
mov    %r15,%rsi
call   1030 <MD5_Final@plt>
xor    %ebx,%ebx
nopl   0x0(%rax)
movzbl 0x10(%rsp,%rbx,1),%eax
shr    $0x4,%al
movzbl %al,%edi
call   1050 <hextoascii@plt>
mov    %al,(%r12,%rbx,2)
movzbl 0x10(%rsp,%rbx,1),%edi
and    $0xf,%edi
call   1050 <hextoascii@plt>
mov    %al,0x1(%r12,%rbx,2)
add    $0x1,%rbx
cmp    $0x10,%rbx
jne    1190 <get_md5_token+0x50>
mov    %r14d,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @get_md5_token(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca [16 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%10 = load i8*, i8** %4
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = load i32, i32* %5
%14 = icmp ne i32 %13, 32
br i1 %14, label %15, label %16
15: ; preds = %12, %2
store i32 -1, i32* %3
br label %57
16: ; preds = %12
%17 = load i8*, i8** %4
%18 = load i32, i32* %5
%19 = call i32 @memset(i8* %17, i32 0, i32 %18)
%20 = call i32 @MD5_Init(i32* %9)
%21 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%22 = call i32 @MD5_Final(i8* %21, i32* %9)
store i32 0, i32* %8
store i32 0, i32* %7
store i32 0, i32* %7
br label %23
23: ; preds = %53, %16
%24 = load i32, i32* %7
%25 = icmp slt i32 %24, 16
br i1 %25, label %26, label %56
26: ; preds = %23
%27 = load i32, i32* %7
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 %28
%30 = load i8, i8* %29
%31 = zext i8 %30 to i32
%32 = ashr i32 %31, 4
%33 = trunc i32 %32 to i8
%34 = call signext i8 @hextoascii(i8 zeroext %33)
%35 = load i8*, i8** %4
%36 = load i32, i32* %8
%37 = add nsw i32 %36, 1
store i32 %37, i32* %8
%38 = sext i32 %36 to i64
%39 = getelementptr inbounds i8, i8* %35, i64 %38
store i8 %34, i8* %39
%40 = load i32, i32* %7
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 %41
%43 = load i8, i8* %42
%44 = zext i8 %43 to i32
%45 = and i32 %44, 15
%46 = trunc i32 %45 to i8
%47 = call signext i8 @hextoascii(i8 zeroext %46)
%48 = load i8*, i8** %4
%49 = load i32, i32* %8
%50 = add nsw i32 %49, 1
store i32 %50, i32* %8
%51 = sext i32 %49 to i64
%52 = getelementptr inbounds i8, i8* %48, i64 %51
store i8 %47, i8* %52
br label %53
53: ; preds = %26
%54 = load i32, i32* %7
%55 = add nsw i32 %54, 1
store i32 %55, i32* %7
br label %23
56: ; preds = %23
store i32 0, i32* %3
br label %57
57: ; preds = %56, %15
%58 = load i32, i32* %3
ret i32 %58
}

LLVM IR (-O2):
define i32 @get_md5_token(i8* %0, i32 %1) {
%3 = alloca [16 x i8]
%4 = alloca i32
%5 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 0
%6 = bitcast i32* %4 to i8*
%7 = icmp eq i8* %0, null
%8 = icmp ne i32 %1, 32
%9 = or i1 %7, %8
br i1 %9, label %30, label %10
10: ; preds = %2
%11 = tail call i32 @memset(i8* %0, i32 0, i32 32)
%12 = call i32 @MD5_Init(i32* %4)
%13 = call i32 @MD5_Final(i8* %5, i32* %4)
br label %14
14: ; preds = %10, %14
%15 = phi i64 [ 0, %10 ], [ %28, %14 ]
%16 = phi i64 [ 0, %10 ], [ %26, %14 ]
%17 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 %15
%18 = load i8, i8* %17
%19 = lshr i8 %18, 4
%20 = call signext i8 @hextoascii(i8 zeroext %19)
%21 = or i64 %16, 1
%22 = getelementptr inbounds i8, i8* %0, i64 %16
store i8 %20, i8* %22
%23 = load i8, i8* %17
%24 = and i8 %23, 15
%25 = call signext i8 @hextoascii(i8 zeroext %24)
%26 = add nuw nsw i64 %16, 2
%27 = getelementptr inbounds i8, i8* %0, i64 %21
store i8 %25, i8* %27
%28 = add nuw nsw i64 %15, 1
%29 = icmp eq i64 %28, 16
br i1 %29, label %30, label %14
30: ; preds = %14, %2
%31 = phi i32 [ -1, %2 ], [ 0, %14 ]
ret i32 %31
}