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

/* Variables and functions */
int EVP_DecodeBlock(unsigned char *, unsigned char *, int);
int EVP_EncodeBlock(unsigned char *, unsigned char *, int);
int /*<<< orphan*/ EVP_md5();
int /*<<< orphan*/ HMAC(int /*<<< orphan*/, char const *, int, unsigned char *,
                        int, unsigned char *, unsigned int *);
int /*<<< orphan*/ assert(int);
char *calloc(int, int);
int /*<<< orphan*/ free(char *);
char hexchar(char);
char *malloc(int);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *, char *);
int strlen(char const *);
char *cram(const char *challenge, const char *user, const char *pass) {
  char hash[16];
  char hex[33];
  int i;
  unsigned int hashlen = sizeof(hash);
  char buf[256];
  int len = strlen(challenge);
  char *response = calloc(1, 1 + len);
  char *final;
  len = EVP_DecodeBlock((unsigned char *)response, (unsigned char *)challenge,
                        strlen(challenge));
  HMAC(EVP_md5(), pass, strlen(pass), (unsigned char *)response,
       strlen(response), (unsigned char *)hash, &hashlen);
  assert(hashlen == sizeof(hash));
  free(response);
  hex[32] = 0;
  for (i = 0; i < 16; i++) {
    hex[2 * i] = hexchar((hash[i] >> 4) & 0xf);
    hex[2 * i + 1] = hexchar(hash[i] & 0xf);
  }
  snprintf(buf, sizeof(buf), "%s %s", user, hex);
  len = strlen(buf);
  len = (4 * ((len + 2) / 3)) + 1;
  final = malloc(len);
  final[len - 1] = 0;
  assert(EVP_EncodeBlock((unsigned char *) final, (unsigned char *)buf,
                         strlen(buf)) == len - 1);
  return final;
}


x86 assembly (clang, -O0):
<cram>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1d0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x10,-0x68(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x174(%rbp)
mov    -0x174(%rbp),%esi
add    $0x1,%esi
mov    $0x1,%edi
call   1080 <calloc@plt>
mov    %rax,-0x180(%rbp)
mov    -0x180(%rbp),%rax
mov    %rax,-0x1b8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x1b0(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x1b8(%rbp),%rdi
mov    -0x1b0(%rbp),%rsi
mov    %eax,%edx
call   1050 <EVP_DecodeBlock@plt>
mov    %eax,-0x174(%rbp)
mov    $0x0,%al
call   1040 <EVP_md5@plt>
mov    %eax,-0x1a4(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x1a0(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x194(%rbp)
mov    -0x180(%rbp),%rax
mov    %rax,-0x190(%rbp)
mov    -0x180(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x1a4(%rbp),%edi
mov    -0x1a0(%rbp),%rsi
mov    -0x194(%rbp),%edx
mov    -0x190(%rbp),%rcx
mov    %eax,%r8d
lea    -0x30(%rbp),%r9
lea    -0x68(%rbp),%rax
mov    %rax,(%rsp)
call   10a0 <HMAC@plt>
mov    -0x68(%rbp),%eax
cmp    $0x10,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1090 <assert@plt>
mov    -0x180(%rbp),%rdi
call   1030 <free@plt>
movb   $0x0,-0x40(%rbp)
movl   $0x0,-0x64(%rbp)
cmpl   $0x10,-0x64(%rbp)
jge    1330 <cram+0x180>
movslq -0x64(%rbp),%rax
movsbl -0x30(%rbp,%rax,1),%eax
sar    $0x4,%eax
and    $0xf,%eax
movsbl %al,%edi
call   10c0 <hexchar@plt>
mov    %al,%cl
mov    -0x64(%rbp),%eax
shl    $0x1,%eax
cltq
mov    %cl,-0x60(%rbp,%rax,1)
movslq -0x64(%rbp),%rax
movsbl -0x30(%rbp,%rax,1),%eax
and    $0xf,%eax
movsbl %al,%edi
call   10c0 <hexchar@plt>
mov    %al,%cl
mov    -0x64(%rbp),%eax
shl    $0x1,%eax
add    $0x1,%eax
cltq
mov    %cl,-0x60(%rbp,%rax,1)
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    12ce <cram+0x11e>
lea    -0x170(%rbp),%rdi
mov    -0x10(%rbp),%rcx
lea    -0x60(%rbp),%r8
mov    $0x100,%esi
lea    0xcb5(%rip),%rdx
call   1070 <snprintf@plt>
lea    -0x170(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x174(%rbp)
mov    -0x174(%rbp),%eax
add    $0x2,%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
shl    $0x2,%eax
add    $0x1,%eax
mov    %eax,-0x174(%rbp)
mov    -0x174(%rbp),%edi
call   10b0 <malloc@plt>
mov    %rax,-0x188(%rbp)
mov    -0x188(%rbp),%rax
mov    -0x174(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x188(%rbp),%rax
mov    %rax,-0x1c8(%rbp)
lea    -0x170(%rbp),%rax
mov    %rax,-0x1c0(%rbp)
lea    -0x170(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x1c8(%rbp),%rdi
mov    -0x1c0(%rbp),%rsi
mov    %eax,%edx
call   10d0 <EVP_EncodeBlock@plt>
mov    -0x174(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1090 <assert@plt>
mov    -0x188(%rbp),%rax
add    $0x1d0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cram>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x158,%rsp
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%rbx
movl   $0x10,0xc(%rsp)
call   1060 <strlen@plt>
lea    0x1(%rax),%esi
mov    $0x1,%edi
call   1080 <calloc@plt>
mov    %rax,%r12
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1050 <EVP_DecodeBlock@plt>
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <EVP_md5@plt>
mov    %eax,%r13d
mov    %r15,%rdi
call   1060 <strlen@plt>
mov    %eax,%ebp
mov    %r12,%rdi
call   1060 <strlen@plt>
lea    0xc(%rsp),%rcx
mov    %rcx,(%rsp)
lea    0x10(%rsp),%r9
mov    %r13d,%edi
mov    %r15,%rsi
mov    %ebp,%edx
mov    %r12,%rcx
mov    %eax,%r8d
call   10a0 <HMAC@plt>
xor    %edi,%edi
cmpl   $0x10,0xc(%rsp)
sete   %dil
call   1090 <assert@plt>
mov    %r12,%rdi
call   1030 <free@plt>
movb   $0x0,0x40(%rsp)
nopl   0x0(%rax,%rax,1)
movzbl 0x10(%rsp,%rbx,1),%eax
shr    $0x4,%al
movzbl %al,%edi
call   10c0 <hexchar@plt>
mov    %al,0x20(%rsp,%rbx,2)
movzbl 0x10(%rsp,%rbx,1),%edi
and    $0xf,%edi
call   10c0 <hexchar@plt>
mov    %al,0x21(%rsp,%rbx,2)
add    $0x1,%rbx
cmp    $0x10,%rbx
jne    1260 <cram+0xb0>
lea    0xd6a(%rip),%rdx
lea    0x50(%rsp),%r15
lea    0x20(%rsp),%r8
mov    %r15,%rdi
mov    $0x100,%esi
mov    %r14,%rcx
call   1070 <snprintf@plt>
mov    %r15,%rdi
call   1060 <strlen@plt>
add    $0x2,%eax
cltq
imul   $0x55555556,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
shr    $0x20,%rax
add    %ecx,%eax
movslq %eax,%rbx
lea    0x0(,%rbx,4),%r14
lea    0x1(%r14),%edi
call   10b0 <malloc@plt>
mov    %rax,%rbp
movb   $0x0,(%rax,%rbx,4)
mov    %r15,%rdi
call   1060 <strlen@plt>
mov    %rbp,%rdi
mov    %r15,%rsi
mov    %eax,%edx
call   10d0 <EVP_EncodeBlock@plt>
xor    %edi,%edi
cmp    %r14d,%eax
sete   %dil
call   1090 <assert@plt>
mov    %rbp,%rax
add    $0x158,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%s %s\00"
define i8* @cram(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca [16 x i8]
%8 = alloca [33 x i8]
%9 = alloca i32
%10 = alloca i32
%11 = alloca [256 x i8]
%12 = alloca i32
%13 = alloca i8*
%14 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
store i32 16, i32* %10
%15 = load i8*, i8** %4
%16 = call i32 @strlen(i8* %15)
store i32 %16, i32* %12
%17 = load i32, i32* %12
%18 = add nsw i32 1, %17
%19 = call i8* @calloc(i32 1, i32 %18)
store i8* %19, i8** %13
%20 = load i8*, i8** %13
%21 = load i8*, i8** %4
%22 = load i8*, i8** %4
%23 = call i32 @strlen(i8* %22)
%24 = call i32 @EVP_DecodeBlock(i8* %20, i8* %21, i32 %23)
store i32 %24, i32* %12
%25 = call i32 (...) @EVP_md5()
%26 = load i8*, i8** %6
%27 = load i8*, i8** %6
%28 = call i32 @strlen(i8* %27)
%29 = load i8*, i8** %13
%30 = load i8*, i8** %13
%31 = call i32 @strlen(i8* %30)
%32 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 0
%33 = call i32 @HMAC(i32 %25, i8* %26, i32 %28, i8* %29, i32 %31, i8* %32, i32* %10)
%34 = load i32, i32* %10
%35 = zext i32 %34 to i64
%36 = icmp eq i64 %35, 16
%37 = zext i1 %36 to i32
%38 = call i32 @assert(i32 %37)
%39 = load i8*, i8** %13
%40 = call i32 @free(i8* %39)
%41 = getelementptr inbounds [33 x i8], [33 x i8]* %8, i64 0, i64 32
store i8 0, i8* %41
store i32 0, i32* %9
br label %42
42: ; preds = %72, %3
%43 = load i32, i32* %9
%44 = icmp slt i32 %43, 16
br i1 %44, label %45, label %75
45: ; preds = %42
%46 = load i32, i32* %9
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 %47
%49 = load i8, i8* %48
%50 = sext i8 %49 to i32
%51 = ashr i32 %50, 4
%52 = and i32 %51, 15
%53 = trunc i32 %52 to i8
%54 = call signext i8 @hexchar(i8 signext %53)
%55 = load i32, i32* %9
%56 = mul nsw i32 2, %55
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds [33 x i8], [33 x i8]* %8, i64 0, i64 %57
store i8 %54, i8* %58
%59 = load i32, i32* %9
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 %60
%62 = load i8, i8* %61
%63 = sext i8 %62 to i32
%64 = and i32 %63, 15
%65 = trunc i32 %64 to i8
%66 = call signext i8 @hexchar(i8 signext %65)
%67 = load i32, i32* %9
%68 = mul nsw i32 2, %67
%69 = add nsw i32 %68, 1
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds [33 x i8], [33 x i8]* %8, i64 0, i64 %70
store i8 %66, i8* %71
br label %72
72: ; preds = %45
%73 = load i32, i32* %9
%74 = add nsw i32 %73, 1
store i32 %74, i32* %9
br label %42
75: ; preds = %42
%76 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%77 = load i8*, i8** %5
%78 = getelementptr inbounds [33 x i8], [33 x i8]* %8, i64 0, i64 0
%79 = call i32 @snprintf(i8* %76, i32 256, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %77, i8* %78)
%80 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%81 = call i32 @strlen(i8* %80)
store i32 %81, i32* %12
%82 = load i32, i32* %12
%83 = add nsw i32 %82, 2
%84 = sdiv i32 %83, 3
%85 = mul nsw i32 4, %84
%86 = add nsw i32 %85, 1
store i32 %86, i32* %12
%87 = load i32, i32* %12
%88 = call i8* @malloc(i32 %87)
store i8* %88, i8** %14
%89 = load i8*, i8** %14
%90 = load i32, i32* %12
%91 = sub nsw i32 %90, 1
%92 = sext i32 %91 to i64
%93 = getelementptr inbounds i8, i8* %89, i64 %92
store i8 0, i8* %93
%94 = load i8*, i8** %14
%95 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%96 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%97 = call i32 @strlen(i8* %96)
%98 = call i32 @EVP_EncodeBlock(i8* %94, i8* %95, i32 %97)
%99 = load i32, i32* %12
%100 = sub nsw i32 %99, 1
%101 = icmp eq i32 %98, %100
%102 = zext i1 %101 to i32
%103 = call i32 @assert(i32 %102)
%104 = load i8*, i8** %14
ret i8* %104
}

LLVM IR (-O2):
@.str = [6 x i8] c"%s %s\00"
define i8* @cram(i8* %0, i8* %1, i8* %2) {
%4 = alloca [16 x i8]
%5 = alloca [33 x i8]
%6 = alloca i32
%7 = alloca [256 x i8]
%8 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%9 = getelementptr inbounds [33 x i8], [33 x i8]* %5, i64 0, i64 0
%10 = bitcast i32* %6 to i8*
store i32 16, i32* %6
%11 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%12 = tail call i32 @strlen(i8* %0)
%13 = add nsw i32 %12, 1
%14 = tail call i8* @calloc(i32 1, i32 %13)
%15 = tail call i32 @strlen(i8* %0)
%16 = tail call i32 @EVP_DecodeBlock(i8* %14, i8* %0, i32 %15)
%17 = tail call i32 (...) @EVP_md5()
%18 = tail call i32 @strlen(i8* %2)
%19 = tail call i32 @strlen(i8* %14)
%20 = call i32 @HMAC(i32 %17, i8* %2, i32 %18, i8* %14, i32 %19, i8* %8, i32* %6)
%21 = load i32, i32* %6
%22 = icmp eq i32 %21, 16
%23 = zext i1 %22 to i32
%24 = call i32 @assert(i32 %23)
%25 = call i32 @free(i8* %14)
%26 = getelementptr inbounds [33 x i8], [33 x i8]* %5, i64 0, i64 32
store i8 0, i8* %26
br label %27
27: ; preds = %3, %27
%28 = phi i64 [ 0, %3 ], [ %40, %27 ]
%29 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 %28
%30 = load i8, i8* %29
%31 = lshr i8 %30, 4
%32 = call signext i8 @hexchar(i8 signext %31)
%33 = shl nuw nsw i64 %28, 1
%34 = getelementptr inbounds [33 x i8], [33 x i8]* %5, i64 0, i64 %33
store i8 %32, i8* %34
%35 = load i8, i8* %29
%36 = and i8 %35, 15
%37 = call signext i8 @hexchar(i8 signext %36)
%38 = or i64 %33, 1
%39 = getelementptr inbounds [33 x i8], [33 x i8]* %5, i64 0, i64 %38
store i8 %37, i8* %39
%40 = add nuw nsw i64 %28, 1
%41 = icmp eq i64 %40, 16
br i1 %41, label %42, label %27
42: ; preds = %27
%43 = call i32 @snprintf(i8* %11, i32 256, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %1, i8* %9)
%44 = call i32 @strlen(i8* %11)
%45 = add nsw i32 %44, 2
%46 = sdiv i32 %45, 3
%47 = shl nsw i32 %46, 2
%48 = or i32 %47, 1
%49 = call i8* @malloc(i32 %48)
%50 = sext i32 %47 to i64
%51 = getelementptr inbounds i8, i8* %49, i64 %50
store i8 0, i8* %51
%52 = call i32 @strlen(i8* %11)
%53 = call i32 @EVP_EncodeBlock(i8* %49, i8* %11, i32 %52)
%54 = icmp eq i32 %53, %47
%55 = zext i1 %54 to i32
%56 = call i32 @assert(i32 %55)
ret i8* %49
}