#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 */
struct md5_ctx {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ md5_finish_ctx(struct md5_ctx *, unsigned char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, size_t);
int /*<<< orphan*/ sprintf(char *, char *, unsigned long);
char *md5_get_digest_hexstr(char *digestStr, size_t dsiz,
                            struct md5_ctx *done_ctx) {
  int i;
  unsigned char digestRaw[16 + 16];
  if (dsiz < 33)
    return (NULL);
  memset(digestStr, 0, dsiz);
  md5_finish_ctx(done_ctx, digestRaw);
  for (i = 0; i < 16; i++) {
    sprintf(digestStr + (i * 2), "%02lx", (unsigned long)digestRaw[i]);
  }
  return (digestStr);
}


x86 assembly (clang, -O0):
<md5_get_digest_hexstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x21,-0x18(%rbp)
jae    115c <md5_get_digest_hexstr+0x2c>
movq   $0x0,-0x8(%rbp)
jmp    11c5 <md5_get_digest_hexstr+0x95>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
xor    %esi,%esi
call   1030 <memset@plt>
mov    -0x20(%rbp),%rdi
lea    -0x50(%rbp),%rsi
call   1040 <md5_finish_ctx@plt>
movl   $0x0,-0x24(%rbp)
cmpl   $0x10,-0x24(%rbp)
jge    11bd <md5_get_digest_hexstr+0x8d>
mov    -0x10(%rbp),%rdi
mov    -0x24(%rbp),%eax
shl    $0x1,%eax
cltq
add    %rax,%rdi
movslq -0x24(%rbp),%rax
movzbl -0x50(%rbp,%rax,1),%eax
mov    %eax,%edx
lea    0xe56(%rip),%rsi
call   1050 <sprintf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    117f <md5_get_digest_hexstr+0x4f>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<md5_get_digest_hexstr>:
push   %r14
push   %rbx
sub    $0x28,%rsp
cmp    $0x21,%rsi
jae    1144 <md5_get_digest_hexstr+0x14>
xor    %ebx,%ebx
jmp    1274 <md5_get_digest_hexstr+0x144>
mov    %rdx,%r14
mov    %rsi,%rdx
mov    %rdi,%rbx
xor    %esi,%esi
call   1030 <memset@plt>
mov    %rsp,%rsi
mov    %r14,%rdi
call   1040 <md5_finish_ctx@plt>
movzbl (%rsp),%edx
lea    0xe96(%rip),%r14
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <sprintf@plt>
lea    0x2(%rbx),%rdi
movzbl 0x1(%rsp),%edx
mov    %r14,%rsi
call   1050 <sprintf@plt>
lea    0x4(%rbx),%rdi
movzbl 0x2(%rsp),%edx
mov    %r14,%rsi
call   1050 <sprintf@plt>
lea    0x6(%rbx),%rdi
movzbl 0x3(%rsp),%edx
mov    %r14,%rsi
call   1050 <sprintf@plt>
lea    0x8(%rbx),%rdi
movzbl 0x4(%rsp),%edx
mov    %r14,%rsi
call   1050 <sprintf@plt>
lea    0xa(%rbx),%rdi
movzbl 0x5(%rsp),%edx
mov    %r14,%rsi
call   1050 <sprintf@plt>
lea    0xc(%rbx),%rdi
movzbl 0x6(%rsp),%edx
mov    %r14,%rsi
call   1050 <sprintf@plt>
lea    0xe(%rbx),%rdi
movzbl 0x7(%rsp),%edx
mov    %r14,%rsi
call   1050 <sprintf@plt>
lea    0x10(%rbx),%rdi
movzbl 0x8(%rsp),%edx
mov    %r14,%rsi
call   1050 <sprintf@plt>
lea    0x12(%rbx),%rdi
movzbl 0x9(%rsp),%edx
mov    %r14,%rsi
call   1050 <sprintf@plt>
lea    0x14(%rbx),%rdi
movzbl 0xa(%rsp),%edx
mov    %r14,%rsi
call   1050 <sprintf@plt>
lea    0x16(%rbx),%rdi
movzbl 0xb(%rsp),%edx
mov    %r14,%rsi
call   1050 <sprintf@plt>
lea    0x18(%rbx),%rdi
movzbl 0xc(%rsp),%edx
mov    %r14,%rsi
call   1050 <sprintf@plt>
lea    0x1a(%rbx),%rdi
movzbl 0xd(%rsp),%edx
mov    %r14,%rsi
call   1050 <sprintf@plt>
lea    0x1c(%rbx),%rdi
movzbl 0xe(%rsp),%edx
mov    %r14,%rsi
call   1050 <sprintf@plt>
lea    0x1e(%rbx),%rdi
movzbl 0xf(%rsp),%edx
mov    %r14,%rsi
call   1050 <sprintf@plt>
mov    %rbx,%rax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.md5_ctx = type { i32 }
@.str = [6 x i8] c"%02lx\00"
define i8* @md5_get_digest_hexstr(i8* %0, i64 %1, %struct.md5_ctx* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca %struct.md5_ctx*
%8 = alloca i32
%9 = alloca [32 x i8]
store i8* %0, i8** %5
store i64 %1, i64* %6
store %struct.md5_ctx* %2, %struct.md5_ctx** %7
%10 = load i64, i64* %6
%11 = icmp ult i64 %10, 33
br i1 %11, label %12, label %13
12: ; preds = %3
store i8* null, i8** %4
br label %40
13: ; preds = %3
%14 = load i8*, i8** %5
%15 = load i64, i64* %6
%16 = call i32 @memset(i8* %14, i32 0, i64 %15)
%17 = load %struct.md5_ctx*, %struct.md5_ctx** %7
%18 = getelementptr inbounds [32 x i8], [32 x i8]* %9, i64 0, i64 0
%19 = call i32 @md5_finish_ctx(%struct.md5_ctx* %17, i8* %18)
store i32 0, i32* %8
br label %20
20: ; preds = %35, %13
%21 = load i32, i32* %8
%22 = icmp slt i32 %21, 16
br i1 %22, label %23, label %38
23: ; preds = %20
%24 = load i8*, i8** %5
%25 = load i32, i32* %8
%26 = mul nsw i32 %25, 2
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %24, i64 %27
%29 = load i32, i32* %8
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [32 x i8], [32 x i8]* %9, i64 0, i64 %30
%32 = load i8, i8* %31
%33 = zext i8 %32 to i64
%34 = call i32 @sprintf(i8* %28, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i64 %33)
br label %35
35: ; preds = %23
%36 = load i32, i32* %8
%37 = add nsw i32 %36, 1
store i32 %37, i32* %8
br label %20
38: ; preds = %20
%39 = load i8*, i8** %5
store i8* %39, i8** %4
br label %40
40: ; preds = %38, %12
%41 = load i8*, i8** %4
ret i8* %41
}

LLVM IR (-O2):
%struct.md5_ctx = type { i32 }
@.str = [6 x i8] c"%02lx\00"
define i8* @md5_get_digest_hexstr(i8* %0, i64 %1, %struct.md5_ctx* %2) {
%4 = alloca [32 x i8]
%5 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%6 = icmp ult i64 %1, 33
br i1 %6, label %88, label %7
7: ; preds = %3
%8 = tail call i32 @memset(i8* %0, i32 0, i64 %1)
%9 = call i32 @md5_finish_ctx(%struct.md5_ctx* %2, i8* %5)
%10 = load i8, i8* %5
%11 = zext i8 %10 to i64
%12 = call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i64 %11)
%13 = getelementptr inbounds i8, i8* %0, i64 2
%14 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 1
%15 = load i8, i8* %14
%16 = zext i8 %15 to i64
%17 = call i32 @sprintf(i8* dereferenceable(1) %13, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i64 %16)
%18 = getelementptr inbounds i8, i8* %0, i64 4
%19 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 2
%20 = load i8, i8* %19
%21 = zext i8 %20 to i64
%22 = call i32 @sprintf(i8* dereferenceable(1) %18, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i64 %21)
%23 = getelementptr inbounds i8, i8* %0, i64 6
%24 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 3
%25 = load i8, i8* %24
%26 = zext i8 %25 to i64
%27 = call i32 @sprintf(i8* dereferenceable(1) %23, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i64 %26)
%28 = getelementptr inbounds i8, i8* %0, i64 8
%29 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 4
%30 = load i8, i8* %29
%31 = zext i8 %30 to i64
%32 = call i32 @sprintf(i8* dereferenceable(1) %28, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i64 %31)
%33 = getelementptr inbounds i8, i8* %0, i64 10
%34 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 5
%35 = load i8, i8* %34
%36 = zext i8 %35 to i64
%37 = call i32 @sprintf(i8* dereferenceable(1) %33, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i64 %36)
%38 = getelementptr inbounds i8, i8* %0, i64 12
%39 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 6
%40 = load i8, i8* %39
%41 = zext i8 %40 to i64
%42 = call i32 @sprintf(i8* dereferenceable(1) %38, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i64 %41)
%43 = getelementptr inbounds i8, i8* %0, i64 14
%44 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 7
%45 = load i8, i8* %44
%46 = zext i8 %45 to i64
%47 = call i32 @sprintf(i8* dereferenceable(1) %43, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i64 %46)
%48 = getelementptr inbounds i8, i8* %0, i64 16
%49 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 8
%50 = load i8, i8* %49
%51 = zext i8 %50 to i64
%52 = call i32 @sprintf(i8* dereferenceable(1) %48, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i64 %51)
%53 = getelementptr inbounds i8, i8* %0, i64 18
%54 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 9
%55 = load i8, i8* %54
%56 = zext i8 %55 to i64
%57 = call i32 @sprintf(i8* dereferenceable(1) %53, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i64 %56)
%58 = getelementptr inbounds i8, i8* %0, i64 20
%59 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 10
%60 = load i8, i8* %59
%61 = zext i8 %60 to i64
%62 = call i32 @sprintf(i8* dereferenceable(1) %58, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i64 %61)
%63 = getelementptr inbounds i8, i8* %0, i64 22
%64 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 11
%65 = load i8, i8* %64
%66 = zext i8 %65 to i64
%67 = call i32 @sprintf(i8* dereferenceable(1) %63, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i64 %66)
%68 = getelementptr inbounds i8, i8* %0, i64 24
%69 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 12
%70 = load i8, i8* %69
%71 = zext i8 %70 to i64
%72 = call i32 @sprintf(i8* dereferenceable(1) %68, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i64 %71)
%73 = getelementptr inbounds i8, i8* %0, i64 26
%74 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 13
%75 = load i8, i8* %74
%76 = zext i8 %75 to i64
%77 = call i32 @sprintf(i8* dereferenceable(1) %73, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i64 %76)
%78 = getelementptr inbounds i8, i8* %0, i64 28
%79 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 14
%80 = load i8, i8* %79
%81 = zext i8 %80 to i64
%82 = call i32 @sprintf(i8* dereferenceable(1) %78, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i64 %81)
%83 = getelementptr inbounds i8, i8* %0, i64 30
%84 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 15
%85 = load i8, i8* %84
%86 = zext i8 %85 to i64
%87 = call i32 @sprintf(i8* dereferenceable(1) %83, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i64 %86)
br label %88
88: ; preds = %7, %3
%89 = phi i8* [ null, %3 ], [ %0, %7 ]
ret i8* %89
}