#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*/ *);
int /*<<< orphan*/ MD5_Update(int /*<<< orphan*/ *, char const *, int);
scalar_t__ malloc(int);
int /*<<< orphan*/ snprintf(char *, int, char *, unsigned int);
int strlen(char const *);
char *get_hash(const char *str) {
  int n, len = strlen(str);
  MD5_CTX c;
  unsigned char digest[16];
  char *out = (char *)malloc(33);
  MD5_Init(&c);
  while (len > 0) {
    if (len > 512) {
      MD5_Update(&c, str, 512);
    } else {
      MD5_Update(&c, str, len);
    }
    len -= 512;
    str += 512;
  }
  MD5_Final(digest, &c);
  for (n = 0; n < 16; ++n) {
    snprintf(&(out[n * 2]), 16 * 2, "%02x", (unsigned int)digest[n]);
  }
  return out;
}


x86 assembly (clang, -O0):
<get_hash>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x10(%rbp)
mov    $0x21,%edi
call   1060 <malloc@plt>
mov    %rax,-0x38(%rbp)
lea    -0x14(%rbp),%rdi
call   1070 <MD5_Init@plt>
cmpl   $0x0,-0x10(%rbp)
jle    11eb <get_hash+0x8b>
cmpl   $0x200,-0x10(%rbp)
jle    11bd <get_hash+0x5d>
mov    -0x8(%rbp),%rsi
lea    -0x14(%rbp),%rdi
mov    $0x200,%edx
call   1080 <MD5_Update@plt>
jmp    11cd <get_hash+0x6d>
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%edx
lea    -0x14(%rbp),%rdi
call   1080 <MD5_Update@plt>
mov    -0x10(%rbp),%eax
sub    $0x200,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
add    $0x200,%rax
mov    %rax,-0x8(%rbp)
jmp    118f <get_hash+0x2f>
lea    -0x30(%rbp),%rdi
lea    -0x14(%rbp),%rsi
call   1030 <MD5_Final@plt>
movl   $0x0,-0xc(%rbp)
cmpl   $0x10,-0xc(%rbp)
jge    1240 <get_hash+0xe0>
mov    -0x38(%rbp),%rdi
mov    -0xc(%rbp),%eax
shl    $0x1,%eax
cltq
add    %rax,%rdi
movslq -0xc(%rbp),%rax
movzbl -0x30(%rbp,%rax,1),%ecx
mov    $0x20,%esi
lea    0xdd3(%rip),%rdx
call   1050 <snprintf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11ff <get_hash+0x9f>
mov    -0x38(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_hash>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    $0x21,%edi
call   1060 <malloc@plt>
mov    %rax,%r15
lea    0x14(%rsp),%rdi
call   1070 <MD5_Init@plt>
test   %ebp,%ebp
jle    11d4 <get_hash+0x74>
cmp    $0x201,%ebp
jb     11c5 <get_hash+0x65>
lea    0x14(%rsp),%r14
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x200,%edx
call   1080 <MD5_Update@plt>
add    $0xfffffe00,%ebp
add    $0x200,%rbx
cmp    $0x200,%ebp
ja     11a0 <get_hash+0x40>
lea    0x14(%rsp),%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1080 <MD5_Update@plt>
mov    %rsp,%rdi
lea    0x14(%rsp),%rsi
call   1030 <MD5_Final@plt>
movzbl (%rsp),%ecx
lea    0xe14(%rip),%r14
mov    %r15,%rdi
mov    $0x20,%esi
mov    %r14,%rdx
call   1050 <snprintf@plt>
lea    0x2(%r15),%rdi
movzbl 0x1(%rsp),%ecx
mov    $0x20,%esi
mov    %r14,%rdx
call   1050 <snprintf@plt>
lea    0x4(%r15),%rdi
movzbl 0x2(%rsp),%ecx
mov    $0x20,%esi
mov    %r14,%rdx
call   1050 <snprintf@plt>
lea    0x6(%r15),%rdi
movzbl 0x3(%rsp),%ecx
mov    $0x20,%esi
mov    %r14,%rdx
call   1050 <snprintf@plt>
lea    0x8(%r15),%rdi
movzbl 0x4(%rsp),%ecx
mov    $0x20,%esi
mov    %r14,%rdx
call   1050 <snprintf@plt>
lea    0xa(%r15),%rdi
movzbl 0x5(%rsp),%ecx
mov    $0x20,%esi
mov    %r14,%rdx
call   1050 <snprintf@plt>
lea    0xc(%r15),%rdi
movzbl 0x6(%rsp),%ecx
mov    $0x20,%esi
mov    %r14,%rdx
call   1050 <snprintf@plt>
lea    0xe(%r15),%rdi
movzbl 0x7(%rsp),%ecx
mov    $0x20,%esi
mov    %r14,%rdx
call   1050 <snprintf@plt>
lea    0x10(%r15),%rdi
movzbl 0x8(%rsp),%ecx
mov    $0x20,%esi
mov    %r14,%rdx
call   1050 <snprintf@plt>
lea    0x12(%r15),%rdi
movzbl 0x9(%rsp),%ecx
mov    $0x20,%esi
mov    %r14,%rdx
call   1050 <snprintf@plt>
lea    0x14(%r15),%rdi
movzbl 0xa(%rsp),%ecx
mov    $0x20,%esi
mov    %r14,%rdx
call   1050 <snprintf@plt>
lea    0x16(%r15),%rdi
movzbl 0xb(%rsp),%ecx
mov    $0x20,%esi
mov    %r14,%rdx
call   1050 <snprintf@plt>
lea    0x18(%r15),%rdi
movzbl 0xc(%rsp),%ecx
mov    $0x20,%esi
mov    %r14,%rdx
call   1050 <snprintf@plt>
lea    0x1a(%r15),%rdi
movzbl 0xd(%rsp),%ecx
mov    $0x20,%esi
mov    %r14,%rdx
call   1050 <snprintf@plt>
lea    0x1c(%r15),%rdi
movzbl 0xe(%rsp),%ecx
mov    $0x20,%esi
mov    %r14,%rdx
call   1050 <snprintf@plt>
mov    %r15,%rdi
add    $0x1e,%rdi
movzbl 0xf(%rsp),%ecx
mov    $0x20,%esi
mov    %r14,%rdx
call   1050 <snprintf@plt>
mov    %r15,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%02x\00"
define i8* @get_hash(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [16 x i8]
%7 = alloca i8*
store i8* %0, i8** %2
%8 = load i8*, i8** %2
%9 = call i32 @strlen(i8* %8)
store i32 %9, i32* %4
%10 = call i64 @malloc(i32 33)
%11 = inttoptr i64 %10 to i8*
store i8* %11, i8** %7
%12 = call i32 @MD5_Init(i32* %5)
br label %13
13: ; preds = %26, %1
%14 = load i32, i32* %4
%15 = icmp sgt i32 %14, 0
br i1 %15, label %16, label %31
16: ; preds = %13
%17 = load i32, i32* %4
%18 = icmp sgt i32 %17, 512
br i1 %18, label %19, label %22
19: ; preds = %16
%20 = load i8*, i8** %2
%21 = call i32 @MD5_Update(i32* %5, i8* %20, i32 512)
br label %26
22: ; preds = %16
%23 = load i8*, i8** %2
%24 = load i32, i32* %4
%25 = call i32 @MD5_Update(i32* %5, i8* %23, i32 %24)
br label %26
26: ; preds = %22, %19
%27 = load i32, i32* %4
%28 = sub nsw i32 %27, 512
store i32 %28, i32* %4
%29 = load i8*, i8** %2
%30 = getelementptr inbounds i8, i8* %29, i64 512
store i8* %30, i8** %2
br label %13
31: ; preds = %13
%32 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%33 = call i32 @MD5_Final(i8* %32, i32* %5)
store i32 0, i32* %3
br label %34
34: ; preds = %49, %31
%35 = load i32, i32* %3
%36 = icmp slt i32 %35, 16
br i1 %36, label %37, label %52
37: ; preds = %34
%38 = load i8*, i8** %7
%39 = load i32, i32* %3
%40 = mul nsw i32 %39, 2
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %38, i64 %41
%43 = load i32, i32* %3
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 %44
%46 = load i8, i8* %45
%47 = zext i8 %46 to i32
%48 = call i32 @snprintf(i8* %42, i32 32, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %47)
br label %49
49: ; preds = %37
%50 = load i32, i32* %3
%51 = add nsw i32 %50, 1
store i32 %51, i32* %3
br label %34
52: ; preds = %34
%53 = load i8*, i8** %7
ret i8* %53
}

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