#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 */
char const *eina_stringshare_add(char *);
const char *_sha1_to_string(const unsigned char *hashout) {
  const char hextab[] = {'0', '1', '2', '3', '4', '5', '6', '7',
                         '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
  char sha1[41] = {0};
  unsigned int i = 0;
  for (i = 0; i < 20; i++) {
    sha1[2 * i] = hextab[(hashout[i] >> 4) & 0x0f];
    sha1[2 * i + 1] = hextab[hashout[i] & 0x0f];
  }
  return eina_stringshare_add(sha1);
}


x86 assembly (clang, -O0):
<_sha1_to_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    0xecd(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xeca(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x29,%edx
call   1030 <memset@plt>
movl   $0x0,-0x54(%rbp)
movl   $0x0,-0x54(%rbp)
cmpl   $0x14,-0x54(%rbp)
jae    11be <_sha1_to_string+0x9e>
mov    -0x8(%rbp),%rax
mov    -0x54(%rbp),%ecx
movzbl (%rax,%rcx,1),%eax
sar    $0x4,%eax
and    $0xf,%eax
cltq
mov    -0x20(%rbp,%rax,1),%cl
mov    -0x54(%rbp),%eax
shl    $0x1,%eax
mov    %eax,%eax
mov    %cl,-0x50(%rbp,%rax,1)
mov    -0x8(%rbp),%rax
mov    -0x54(%rbp),%ecx
movzbl (%rax,%rcx,1),%eax
and    $0xf,%eax
cltq
mov    -0x20(%rbp,%rax,1),%cl
mov    -0x54(%rbp),%eax
shl    $0x1,%eax
add    $0x1,%eax
mov    %eax,%eax
mov    %cl,-0x50(%rbp,%rax,1)
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    1160 <_sha1_to_string+0x40>
lea    -0x50(%rbp),%rdi
call   1040 <eina_stringshare_add@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_sha1_to_string>:
sub    $0x38,%rsp
xorps  %xmm0,%xmm0
movups %xmm0,0x19(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
xor    %eax,%eax
lea    0xed2(%rip),%r8
xchg   %ax,%ax
movzbl (%rdi,%rax,1),%edx
mov    %rdx,%rsi
shr    $0x4,%rsi
movzbl (%rsi,%r8,1),%ecx
mov    %cl,(%rsp,%rax,2)
and    $0xf,%edx
movzbl (%rdx,%r8,1),%ecx
mov    %cl,0x1(%rsp,%rax,2)
add    $0x1,%rax
cmp    $0x14,%rax
jne    1130 <_sha1_to_string+0x20>
mov    %rsp,%rdi
call   1030 <eina_stringshare_add@plt>
add    $0x38,%rsp
ret

LLVM IR (-O0):
@__const._sha1_to_string.hextab = [16 x i8] c"0123456789abcdef"
define i8* @_sha1_to_string(i8* %0) {
%2 = alloca i8*
%3 = alloca [16 x i8]
%4 = alloca [41 x i8]
%5 = alloca i32
store i8* %0, i8** %2
%6 = bitcast [16 x i8]* %3 to i8*
%7 = bitcast [41 x i8]* %4 to i8*
store i32 0, i32* %5
store i32 0, i32* %5
br label %8
8: ; preds = %42, %1
%9 = load i32, i32* %5
%10 = icmp ult i32 %9, 20
br i1 %10, label %11, label %45
11: ; preds = %8
%12 = load i8*, i8** %2
%13 = load i32, i32* %5
%14 = zext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %12, i64 %14
%16 = load i8, i8* %15
%17 = zext i8 %16 to i32
%18 = ashr i32 %17, 4
%19 = and i32 %18, 15
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 %20
%22 = load i8, i8* %21
%23 = load i32, i32* %5
%24 = mul i32 2, %23
%25 = zext i32 %24 to i64
%26 = getelementptr inbounds [41 x i8], [41 x i8]* %4, i64 0, i64 %25
store i8 %22, i8* %26
%27 = load i8*, i8** %2
%28 = load i32, i32* %5
%29 = zext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
%31 = load i8, i8* %30
%32 = zext i8 %31 to i32
%33 = and i32 %32, 15
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 %34
%36 = load i8, i8* %35
%37 = load i32, i32* %5
%38 = mul i32 2, %37
%39 = add i32 %38, 1
%40 = zext i32 %39 to i64
%41 = getelementptr inbounds [41 x i8], [41 x i8]* %4, i64 0, i64 %40
store i8 %36, i8* %41
br label %42
42: ; preds = %11
%43 = load i32, i32* %5
%44 = add i32 %43, 1
store i32 %44, i32* %5
br label %8
45: ; preds = %8
%46 = getelementptr inbounds [41 x i8], [41 x i8]* %4, i64 0, i64 0
%47 = call i8* @eina_stringshare_add(i8* %46)
ret i8* %47
}

LLVM IR (-O2):
@__const._sha1_to_string.hextab = [16 x i8] c"0123456789abcdef"
define i8* @_sha1_to_string(i8* nocapture %0) {
%2 = alloca [41 x i8]
%3 = getelementptr inbounds [41 x i8], [41 x i8]* %2, i64 0, i64 0
br label %4
4: ; preds = %1, %4
%5 = phi i64 [ 0, %1 ], [ %20, %4 ]
%6 = getelementptr inbounds i8, i8* %0, i64 %5
%7 = load i8, i8* %6
%8 = lshr i8 %7, 4
%9 = zext i8 %8 to i64
%10 = getelementptr inbounds [16 x i8], [16 x i8]* @__const._sha1_to_string.hextab, i64 0, i64 %9
%11 = load i8, i8* %10
%12 = shl nuw nsw i64 %5, 1
%13 = getelementptr inbounds [41 x i8], [41 x i8]* %2, i64 0, i64 %12
store i8 %11, i8* %13
%14 = and i8 %7, 15
%15 = zext i8 %14 to i64
%16 = getelementptr inbounds [16 x i8], [16 x i8]* @__const._sha1_to_string.hextab, i64 0, i64 %15
%17 = load i8, i8* %16
%18 = or i64 %12, 1
%19 = getelementptr inbounds [41 x i8], [41 x i8]* %2, i64 0, i64 %18
store i8 %17, i8* %19
%20 = add nuw nsw i64 %5, 1
%21 = icmp eq i64 %20, 20
br i1 %21, label %22, label %4
22: ; preds = %4
%23 = call i8* @eina_stringshare_add(i8* %3)
ret i8* %23
}