#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*/ assert(char const *const);
int /*<<< orphan*/ sprintf(char *, char *, char const);
void sha3_msg_digest_to_string(char *const md_as_string, const char *const md,
                               const size_t md_len) {
  assert(md_as_string);
  assert(md);
  char *c = md_as_string;
  for (int i = 0; i < md_len; i++)
    c += sprintf(c, "%02hhx", md[i]);
}


x86 assembly (clang, -O0):
<sha3_msg_digest_to_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <assert@plt>
mov    -0x10(%rbp),%rdi
call   1030 <assert@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movslq -0x24(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    119d <sha3_msg_digest_to_string+0x7d>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
lea    0xe8a(%rip),%rsi
movsbl (%rax,%rcx,1),%edx
call   1040 <sprintf@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1155 <sha3_msg_digest_to_string+0x35>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sha3_msg_digest_to_string>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r13
call   1030 <assert@plt>
mov    %r15,%rdi
call   1030 <assert@plt>
test   %r14,%r14
je     116e <sha3_msg_digest_to_string+0x4e>
xor    %ebx,%ebx
lea    0xeb3(%rip),%r12
nopl   (%rax)
movsbl (%r15,%rbx,1),%edx
mov    %r13,%rdi
mov    %r12,%rsi
call   1040 <sprintf@plt>
cltq
add    %rax,%r13
add    $0x1,%rbx
cmp    %rbx,%r14
jne    1150 <sha3_msg_digest_to_string+0x30>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [7 x i8] c"%02hhx\00"
define void @sha3_msg_digest_to_string(i8* %0, i8* %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i64 %2, i64* %6
%9 = load i8*, i8** %4
%10 = call i32 @assert(i8* %9)
%11 = load i8*, i8** %5
%12 = call i32 @assert(i8* %11)
%13 = load i8*, i8** %4
store i8* %13, i8** %7
store i32 0, i32* %8
br label %14
14: ; preds = %30, %3
%15 = load i32, i32* %8
%16 = sext i32 %15 to i64
%17 = load i64, i64* %6
%18 = icmp ult i64 %16, %17
br i1 %18, label %19, label %33
19: ; preds = %14
%20 = load i8*, i8** %7
%21 = load i8*, i8** %5
%22 = load i32, i32* %8
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
%25 = load i8, i8* %24
%26 = call i32 @sprintf(i8* %20, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8 signext %25)
%27 = load i8*, i8** %7
%28 = sext i32 %26 to i64
%29 = getelementptr inbounds i8, i8* %27, i64 %28
store i8* %29, i8** %7
br label %30
30: ; preds = %19
%31 = load i32, i32* %8
%32 = add nsw i32 %31, 1
store i32 %32, i32* %8
br label %14
33: ; preds = %14
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"%02hhx\00"
define void @sha3_msg_digest_to_string(i8* %0, i8* %1, i64 %2) {
%4 = tail call i32 @assert(i8* %0)
%5 = tail call i32 @assert(i8* %1)
%6 = icmp eq i64 %2, 0
br i1 %6, label %7, label %8
7: ; preds = %8, %3
ret void
8: ; preds = %3, %8
%9 = phi i64 [ %16, %8 ], [ 0, %3 ]
%10 = phi i8* [ %15, %8 ], [ %0, %3 ]
%11 = getelementptr inbounds i8, i8* %1, i64 %9
%12 = load i8, i8* %11
%13 = tail call i32 @sprintf(i8* dereferenceable(1) %10, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8 signext %12)
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %10, i64 %14
%16 = add nuw i64 %9, 1
%17 = icmp eq i64 %16, %2
br i1 %17, label %7, label %8
}