#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*/ sprintf(char *, char *, unsigned char const);
void SHA1_DigestToHex(const unsigned char digest[20], char *output) {
  int i, j;
  char *c = output;
  for (i = 0; i < 20 / 4; i++) {
    for (j = 0; j < 4; j++) {
      sprintf(c, "%02X", digest[i * 4 + j]);
      c += 2;
    }
  }
}


x86 assembly (clang, -O0):
<SHA1_DigestToHex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x5,-0x14(%rbp)
jge    119b <SHA1_DigestToHex+0x8b>
movl   $0x0,-0x18(%rbp)
cmpl   $0x4,-0x18(%rbp)
jge    1188 <SHA1_DigestToHex+0x78>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
shl    $0x2,%ecx
add    -0x18(%rbp),%ecx
movslq %ecx,%rcx
lea    0xe9b(%rip),%rsi
movzbl (%rax,%rcx,1),%edx
call   1030 <sprintf@plt>
mov    -0x20(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1140 <SHA1_DigestToHex+0x30>
jmp    118d <SHA1_DigestToHex+0x7d>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    112f <SHA1_DigestToHex+0x1f>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SHA1_DigestToHex>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%r14
movzbl (%rdi),%edx
lea    0xedb(%rip),%r15
mov    %rsi,%rdi
mov    %r15,%rsi
call   1030 <sprintf@plt>
lea    0x2(%rbx),%rdi
movzbl 0x1(%r14),%edx
mov    %r15,%rsi
call   1030 <sprintf@plt>
lea    0x4(%rbx),%rdi
movzbl 0x2(%r14),%edx
mov    %r15,%rsi
call   1030 <sprintf@plt>
lea    0x6(%rbx),%rdi
movzbl 0x3(%r14),%edx
mov    %r15,%rsi
call   1030 <sprintf@plt>
lea    0x8(%rbx),%rdi
movzbl 0x4(%r14),%edx
mov    %r15,%rsi
call   1030 <sprintf@plt>
lea    0xa(%rbx),%rdi
movzbl 0x5(%r14),%edx
mov    %r15,%rsi
call   1030 <sprintf@plt>
lea    0xc(%rbx),%rdi
movzbl 0x6(%r14),%edx
mov    %r15,%rsi
call   1030 <sprintf@plt>
lea    0xe(%rbx),%rdi
movzbl 0x7(%r14),%edx
mov    %r15,%rsi
call   1030 <sprintf@plt>
lea    0x10(%rbx),%rdi
movzbl 0x8(%r14),%edx
mov    %r15,%rsi
call   1030 <sprintf@plt>
lea    0x12(%rbx),%rdi
movzbl 0x9(%r14),%edx
mov    %r15,%rsi
call   1030 <sprintf@plt>
lea    0x14(%rbx),%rdi
movzbl 0xa(%r14),%edx
mov    %r15,%rsi
call   1030 <sprintf@plt>
lea    0x16(%rbx),%rdi
movzbl 0xb(%r14),%edx
mov    %r15,%rsi
call   1030 <sprintf@plt>
lea    0x18(%rbx),%rdi
movzbl 0xc(%r14),%edx
mov    %r15,%rsi
call   1030 <sprintf@plt>
lea    0x1a(%rbx),%rdi
movzbl 0xd(%r14),%edx
mov    %r15,%rsi
call   1030 <sprintf@plt>
lea    0x1c(%rbx),%rdi
movzbl 0xe(%r14),%edx
mov    %r15,%rsi
call   1030 <sprintf@plt>
lea    0x1e(%rbx),%rdi
movzbl 0xf(%r14),%edx
mov    %r15,%rsi
call   1030 <sprintf@plt>
lea    0x20(%rbx),%rdi
movzbl 0x10(%r14),%edx
mov    %r15,%rsi
call   1030 <sprintf@plt>
lea    0x22(%rbx),%rdi
movzbl 0x11(%r14),%edx
mov    %r15,%rsi
call   1030 <sprintf@plt>
lea    0x24(%rbx),%rdi
movzbl 0x12(%r14),%edx
mov    %r15,%rsi
call   1030 <sprintf@plt>
add    $0x26,%rbx
movzbl 0x13(%r14),%edx
mov    %rbx,%rdi
mov    %r15,%rsi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <sprintf@plt>

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

LLVM IR (-O2):
@.str = [5 x i8] c"%02X\00"
define void @SHA1_DigestToHex(i8* nocapture %0, i8* nocapture writeonly %1) {
%3 = load i8, i8* %0
%4 = tail call i32 @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %3)
%5 = getelementptr inbounds i8, i8* %1, i64 2
%6 = getelementptr inbounds i8, i8* %0, i64 1
%7 = load i8, i8* %6
%8 = tail call i32 @sprintf(i8* dereferenceable(1) %5, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %7)
%9 = getelementptr inbounds i8, i8* %1, i64 4
%10 = getelementptr inbounds i8, i8* %0, i64 2
%11 = load i8, i8* %10
%12 = tail call i32 @sprintf(i8* dereferenceable(1) %9, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %11)
%13 = getelementptr inbounds i8, i8* %1, i64 6
%14 = getelementptr inbounds i8, i8* %0, i64 3
%15 = load i8, i8* %14
%16 = tail call i32 @sprintf(i8* dereferenceable(1) %13, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %15)
%17 = getelementptr inbounds i8, i8* %1, i64 8
%18 = getelementptr inbounds i8, i8* %0, i64 4
%19 = load i8, i8* %18
%20 = tail call i32 @sprintf(i8* dereferenceable(1) %17, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %19)
%21 = getelementptr inbounds i8, i8* %1, i64 10
%22 = getelementptr inbounds i8, i8* %0, i64 5
%23 = load i8, i8* %22
%24 = tail call i32 @sprintf(i8* dereferenceable(1) %21, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %23)
%25 = getelementptr inbounds i8, i8* %1, i64 12
%26 = getelementptr inbounds i8, i8* %0, i64 6
%27 = load i8, i8* %26
%28 = tail call i32 @sprintf(i8* dereferenceable(1) %25, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %27)
%29 = getelementptr inbounds i8, i8* %1, i64 14
%30 = getelementptr inbounds i8, i8* %0, i64 7
%31 = load i8, i8* %30
%32 = tail call i32 @sprintf(i8* dereferenceable(1) %29, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %31)
%33 = getelementptr inbounds i8, i8* %1, i64 16
%34 = getelementptr inbounds i8, i8* %0, i64 8
%35 = load i8, i8* %34
%36 = tail call i32 @sprintf(i8* dereferenceable(1) %33, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %35)
%37 = getelementptr inbounds i8, i8* %1, i64 18
%38 = getelementptr inbounds i8, i8* %0, i64 9
%39 = load i8, i8* %38
%40 = tail call i32 @sprintf(i8* dereferenceable(1) %37, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %39)
%41 = getelementptr inbounds i8, i8* %1, i64 20
%42 = getelementptr inbounds i8, i8* %0, i64 10
%43 = load i8, i8* %42
%44 = tail call i32 @sprintf(i8* dereferenceable(1) %41, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %43)
%45 = getelementptr inbounds i8, i8* %1, i64 22
%46 = getelementptr inbounds i8, i8* %0, i64 11
%47 = load i8, i8* %46
%48 = tail call i32 @sprintf(i8* dereferenceable(1) %45, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %47)
%49 = getelementptr inbounds i8, i8* %1, i64 24
%50 = getelementptr inbounds i8, i8* %0, i64 12
%51 = load i8, i8* %50
%52 = tail call i32 @sprintf(i8* dereferenceable(1) %49, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %51)
%53 = getelementptr inbounds i8, i8* %1, i64 26
%54 = getelementptr inbounds i8, i8* %0, i64 13
%55 = load i8, i8* %54
%56 = tail call i32 @sprintf(i8* dereferenceable(1) %53, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %55)
%57 = getelementptr inbounds i8, i8* %1, i64 28
%58 = getelementptr inbounds i8, i8* %0, i64 14
%59 = load i8, i8* %58
%60 = tail call i32 @sprintf(i8* dereferenceable(1) %57, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %59)
%61 = getelementptr inbounds i8, i8* %1, i64 30
%62 = getelementptr inbounds i8, i8* %0, i64 15
%63 = load i8, i8* %62
%64 = tail call i32 @sprintf(i8* dereferenceable(1) %61, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %63)
%65 = getelementptr inbounds i8, i8* %1, i64 32
%66 = getelementptr inbounds i8, i8* %0, i64 16
%67 = load i8, i8* %66
%68 = tail call i32 @sprintf(i8* dereferenceable(1) %65, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %67)
%69 = getelementptr inbounds i8, i8* %1, i64 34
%70 = getelementptr inbounds i8, i8* %0, i64 17
%71 = load i8, i8* %70
%72 = tail call i32 @sprintf(i8* dereferenceable(1) %69, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %71)
%73 = getelementptr inbounds i8, i8* %1, i64 36
%74 = getelementptr inbounds i8, i8* %0, i64 18
%75 = load i8, i8* %74
%76 = tail call i32 @sprintf(i8* dereferenceable(1) %73, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %75)
%77 = getelementptr inbounds i8, i8* %1, i64 38
%78 = getelementptr inbounds i8, i8* %0, i64 19
%79 = load i8, i8* %78
%80 = tail call i32 @sprintf(i8* dereferenceable(1) %77, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %79)
ret void
}