#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 char uint32_t;
typedef int /*<<< orphan*/ SHA_CTX;

/* Variables and functions */
int /*<<< orphan*/ SHA1_Final(void *, int /*<<< orphan*/ *);
int /*<<< orphan*/ SHA1_Init(int /*<<< orphan*/ *);
int /*<<< orphan*/ SHA1_Update(int /*<<< orphan*/ *, void *, int);
int /*<<< orphan*/ encodeb64(unsigned char const *, char *);
int /*<<< orphan*/ memcpy(char *, char *, int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
void sha1_hash(const char *input, char *output, uint32_t len) {
  char str[38] __attribute__((aligned(32)));
  uint32_t prehash[5] __attribute__((aligned(32)));
  uint32_t hash[5] __attribute__((aligned(32))) = {0};
  int i = 0;
  SHA_CTX ctx;
  SHA1_Init(&ctx);
  SHA1_Update(&ctx, (void *)input, len);
  SHA1_Final((void *)prehash, &ctx);
  encodeb64((const unsigned char *)prehash, str);
  memcpy(&str[26], str, 11);
  str[37] = 0;
  for (i = 0; i < 26; i++) {
    SHA1_Init(&ctx);
    SHA1_Update(&ctx, (void *)&str[i], 12);
    SHA1_Final((void *)prehash, &ctx);
    hash[0] ^= prehash[0];
    hash[1] ^= prehash[1];
    hash[2] ^= prehash[2];
    hash[3] ^= prehash[3];
    hash[4] ^= prehash[4];
  }
  memset(output, 0, 32 - 20);
  memcpy(&output[32 - 20], hash, 20);
}


x86 assembly (clang, -O0):
<sha1_hash>:
push   %rbp
mov    %rsp,%rbp
and    $0xffffffffffffffe0,%rsp
sub    $0xc0,%rsp
mov    %dl,%al
mov    %rdi,0xa8(%rsp)
mov    %rsi,0xa0(%rsp)
mov    %al,0x9f(%rsp)
lea    0x20(%rsp),%rdi
xor    %esi,%esi
mov    $0x5,%edx
call   1040 <memset@plt>
movl   $0x0,0x1c(%rsp)
lea    0x18(%rsp),%rdi
call   1070 <SHA1_Init@plt>
mov    0xa8(%rsp),%rsi
movsbl 0x9f(%rsp),%edx
lea    0x18(%rsp),%rdi
call   1060 <SHA1_Update@plt>
lea    0x40(%rsp),%rdi
lea    0x18(%rsp),%rsi
call   1080 <SHA1_Final@plt>
lea    0x40(%rsp),%rdi
lea    0x60(%rsp),%rsi
call   1030 <encodeb64@plt>
lea    0x60(%rsp),%rdi
add    $0x1a,%rdi
lea    0x60(%rsp),%rsi
mov    $0xb,%edx
call   1050 <memcpy@plt>
movb   $0x0,0x85(%rsp)
movl   $0x0,0x1c(%rsp)
cmpl   $0x1a,0x1c(%rsp)
jge    12ab <sha1_hash+0x14b>
lea    0x18(%rsp),%rdi
call   1070 <SHA1_Init@plt>
movslq 0x1c(%rsp),%rax
lea    0x60(%rsp),%rsi
add    %rax,%rsi
lea    0x18(%rsp),%rdi
mov    $0xc,%edx
call   1060 <SHA1_Update@plt>
lea    0x40(%rsp),%rdi
lea    0x18(%rsp),%rsi
call   1080 <SHA1_Final@plt>
movsbl 0x40(%rsp),%ecx
movsbl 0x20(%rsp),%eax
xor    %ecx,%eax
mov    %al,0x20(%rsp)
movsbl 0x41(%rsp),%ecx
movsbl 0x21(%rsp),%eax
xor    %ecx,%eax
mov    %al,0x21(%rsp)
movsbl 0x42(%rsp),%ecx
movsbl 0x22(%rsp),%eax
xor    %ecx,%eax
mov    %al,0x22(%rsp)
movsbl 0x43(%rsp),%ecx
movsbl 0x23(%rsp),%eax
xor    %ecx,%eax
mov    %al,0x23(%rsp)
movsbl 0x44(%rsp),%ecx
movsbl 0x24(%rsp),%eax
xor    %ecx,%eax
mov    %al,0x24(%rsp)
mov    0x1c(%rsp),%eax
add    $0x1,%eax
mov    %eax,0x1c(%rsp)
jmp    120b <sha1_hash+0xab>
mov    0xa0(%rsp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1040 <memset@plt>
mov    0xa0(%rsp),%rdi
add    $0xc,%rdi
lea    0x20(%rsp),%rsi
mov    $0x14,%edx
call   1050 <memcpy@plt>
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sha1_hash>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
and    $0xffffffffffffffe0,%rsp
sub    $0x80,%rsp
mov    %edx,%r15d
mov    %rsi,0x30(%rsp)
mov    %rdi,%r12
lea    0x2c(%rsp),%rbx
mov    %rbx,%rdi
call   1070 <SHA1_Init@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r15d,%edx
call   1060 <SHA1_Update@plt>
mov    %rsp,%r14
mov    %r14,%rdi
mov    %rbx,%rsi
call   1080 <SHA1_Final@plt>
lea    0x40(%rsp),%r12
mov    %r14,%rdi
mov    %r12,%rsi
call   1030 <encodeb64@plt>
lea    0x5a(%rsp),%rdi
mov    %r12,%rsi
mov    $0xb,%edx
call   1050 <memcpy@plt>
movb   $0x0,0x65(%rsp)
xor    %eax,%eax
xor    %ebx,%ebx
xor    %r14d,%r14d
xor    %r15d,%r15d
xor    %r13d,%r13d
xor    %r12d,%r12d
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rax,0x38(%rsp)
lea    0x2c(%rsp),%rdi
call   1070 <SHA1_Init@plt>
lea    (%rsp,%r12,1),%rsi
add    $0x40,%rsi
lea    0x2c(%rsp),%rdi
mov    $0xc,%edx
call   1060 <SHA1_Update@plt>
mov    %rsp,%rdi
lea    0x2c(%rsp),%rsi
call   1080 <SHA1_Final@plt>
mov    0x38(%rsp),%rax
xor    (%rsp),%r13b
mov    %r13b,0x20(%rsp)
xor    0x1(%rsp),%r15b
mov    %r15b,0x21(%rsp)
xor    0x2(%rsp),%r14b
mov    %r14b,0x22(%rsp)
xor    0x3(%rsp),%bl
xor    0x4(%rsp),%al
mov    %bl,0x23(%rsp)
mov    %al,0x24(%rsp)
add    $0x1,%r12
cmp    $0x1a,%r12
jne    11f0 <sha1_hash+0x90>
mov    0x30(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1040 <memset@plt>
add    $0xc,%rbx
lea    0x20(%rsp),%rsi
mov    %rbx,%rdi
mov    $0x14,%edx
call   1050 <memcpy@plt>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @sha1_hash(i8* %0, i8* %1, i8 signext %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8
%7 = alloca [38 x i8]
%8 = alloca [5 x i8]
%9 = alloca [5 x i8]
%10 = alloca i32
%11 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8 %2, i8* %6
%12 = bitcast [5 x i8]* %9 to i8*
store i32 0, i32* %10
%13 = call i32 @SHA1_Init(i32* %11)
%14 = load i8*, i8** %4
%15 = load i8, i8* %6
%16 = sext i8 %15 to i32
%17 = call i32 @SHA1_Update(i32* %11, i8* %14, i32 %16)
%18 = getelementptr inbounds [5 x i8], [5 x i8]* %8, i64 0, i64 0
%19 = call i32 @SHA1_Final(i8* %18, i32* %11)
%20 = getelementptr inbounds [5 x i8], [5 x i8]* %8, i64 0, i64 0
%21 = getelementptr inbounds [38 x i8], [38 x i8]* %7, i64 0, i64 0
%22 = call i32 @encodeb64(i8* %20, i8* %21)
%23 = getelementptr inbounds [38 x i8], [38 x i8]* %7, i64 0, i64 26
%24 = getelementptr inbounds [38 x i8], [38 x i8]* %7, i64 0, i64 0
%25 = call i32 @memcpy(i8* %23, i8* %24, i32 11)
%26 = getelementptr inbounds [38 x i8], [38 x i8]* %7, i64 0, i64 37
store i8 0, i8* %26
store i32 0, i32* %10
br label %27
27: ; preds = %78, %3
%28 = load i32, i32* %10
%29 = icmp slt i32 %28, 26
br i1 %29, label %30, label %81
30: ; preds = %27
%31 = call i32 @SHA1_Init(i32* %11)
%32 = load i32, i32* %10
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [38 x i8], [38 x i8]* %7, i64 0, i64 %33
%35 = call i32 @SHA1_Update(i32* %11, i8* %34, i32 12)
%36 = getelementptr inbounds [5 x i8], [5 x i8]* %8, i64 0, i64 0
%37 = call i32 @SHA1_Final(i8* %36, i32* %11)
%38 = getelementptr inbounds [5 x i8], [5 x i8]* %8, i64 0, i64 0
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = getelementptr inbounds [5 x i8], [5 x i8]* %9, i64 0, i64 0
%42 = load i8, i8* %41
%43 = sext i8 %42 to i32
%44 = xor i32 %43, %40
%45 = trunc i32 %44 to i8
store i8 %45, i8* %41
%46 = getelementptr inbounds [5 x i8], [5 x i8]* %8, i64 0, i64 1
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
%49 = getelementptr inbounds [5 x i8], [5 x i8]* %9, i64 0, i64 1
%50 = load i8, i8* %49
%51 = sext i8 %50 to i32
%52 = xor i32 %51, %48
%53 = trunc i32 %52 to i8
store i8 %53, i8* %49
%54 = getelementptr inbounds [5 x i8], [5 x i8]* %8, i64 0, i64 2
%55 = load i8, i8* %54
%56 = sext i8 %55 to i32
%57 = getelementptr inbounds [5 x i8], [5 x i8]* %9, i64 0, i64 2
%58 = load i8, i8* %57
%59 = sext i8 %58 to i32
%60 = xor i32 %59, %56
%61 = trunc i32 %60 to i8
store i8 %61, i8* %57
%62 = getelementptr inbounds [5 x i8], [5 x i8]* %8, i64 0, i64 3
%63 = load i8, i8* %62
%64 = sext i8 %63 to i32
%65 = getelementptr inbounds [5 x i8], [5 x i8]* %9, i64 0, i64 3
%66 = load i8, i8* %65
%67 = sext i8 %66 to i32
%68 = xor i32 %67, %64
%69 = trunc i32 %68 to i8
store i8 %69, i8* %65
%70 = getelementptr inbounds [5 x i8], [5 x i8]* %8, i64 0, i64 4
%71 = load i8, i8* %70
%72 = sext i8 %71 to i32
%73 = getelementptr inbounds [5 x i8], [5 x i8]* %9, i64 0, i64 4
%74 = load i8, i8* %73
%75 = sext i8 %74 to i32
%76 = xor i32 %75, %72
%77 = trunc i32 %76 to i8
store i8 %77, i8* %73
br label %78
78: ; preds = %30
%79 = load i32, i32* %10
%80 = add nsw i32 %79, 1
store i32 %80, i32* %10
br label %27
81: ; preds = %27
%82 = load i8*, i8** %5
%83 = call i32 @memset(i8* %82, i32 0, i32 12)
%84 = load i8*, i8** %5
%85 = getelementptr inbounds i8, i8* %84, i64 12
%86 = getelementptr inbounds [5 x i8], [5 x i8]* %9, i64 0, i64 0
%87 = call i32 @memcpy(i8* %85, i8* %86, i32 20)
ret void
}

LLVM IR (-O2):
define void @sha1_hash(i8* %0, i8* %1, i8 signext %2) {
%4 = alloca [38 x i8]
%5 = alloca [5 x i8]
%6 = alloca [5 x i8]
%7 = alloca i32
%8 = getelementptr inbounds [38 x i8], [38 x i8]* %4, i64 0, i64 0
%9 = getelementptr inbounds [5 x i8], [5 x i8]* %5, i64 0, i64 0
%10 = getelementptr inbounds [5 x i8], [5 x i8]* %6, i64 0, i64 0
%11 = bitcast i32* %7 to i8*
%12 = call i32 @SHA1_Init(i32* %7)
%13 = sext i8 %2 to i32
%14 = call i32 @SHA1_Update(i32* %7, i8* %0, i32 %13)
%15 = call i32 @SHA1_Final(i8* %9, i32* %7)
%16 = call i32 @encodeb64(i8* %9, i8* %8)
%17 = getelementptr inbounds [38 x i8], [38 x i8]* %4, i64 0, i64 26
%18 = call i32 @memcpy(i8* %17, i8* %8, i32 11)
%19 = getelementptr inbounds [38 x i8], [38 x i8]* %4, i64 0, i64 37
store i8 0, i8* %19
%20 = getelementptr inbounds [5 x i8], [5 x i8]* %5, i64 0, i64 1
%21 = getelementptr inbounds [5 x i8], [5 x i8]* %6, i64 0, i64 1
%22 = getelementptr inbounds [5 x i8], [5 x i8]* %5, i64 0, i64 2
%23 = getelementptr inbounds [5 x i8], [5 x i8]* %6, i64 0, i64 2
%24 = getelementptr inbounds [5 x i8], [5 x i8]* %5, i64 0, i64 3
%25 = getelementptr inbounds [5 x i8], [5 x i8]* %6, i64 0, i64 3
%26 = getelementptr inbounds [5 x i8], [5 x i8]* %5, i64 0, i64 4
%27 = getelementptr inbounds [5 x i8], [5 x i8]* %6, i64 0, i64 4
br label %28
28: ; preds = %3, %28
%29 = phi i8 [ 0, %3 ], [ %48, %28 ]
%30 = phi i8 [ 0, %3 ], [ %46, %28 ]
%31 = phi i8 [ 0, %3 ], [ %44, %28 ]
%32 = phi i8 [ 0, %3 ], [ %42, %28 ]
%33 = phi i8 [ 0, %3 ], [ %40, %28 ]
%34 = phi i64 [ 0, %3 ], [ %49, %28 ]
%35 = call i32 @SHA1_Init(i32* %7)
%36 = getelementptr inbounds [38 x i8], [38 x i8]* %4, i64 0, i64 %34
%37 = call i32 @SHA1_Update(i32* %7, i8* %36, i32 12)
%38 = call i32 @SHA1_Final(i8* %9, i32* %7)
%39 = load i8, i8* %9
%40 = xor i8 %33, %39
store i8 %40, i8* %10
%41 = load i8, i8* %20
%42 = xor i8 %32, %41
store i8 %42, i8* %21
%43 = load i8, i8* %22
%44 = xor i8 %31, %43
store i8 %44, i8* %23
%45 = load i8, i8* %24
%46 = xor i8 %30, %45
store i8 %46, i8* %25
%47 = load i8, i8* %26
%48 = xor i8 %29, %47
store i8 %48, i8* %27
%49 = add nuw nsw i64 %34, 1
%50 = icmp eq i64 %49, 26
br i1 %50, label %51, label %28
51: ; preds = %28
%52 = call i32 @memset(i8* %1, i32 0, i32 12)
%53 = getelementptr inbounds i8, i8* %1, i64 12
%54 = call i32 @memcpy(i8* %53, i8* %10, i32 20)
ret void
}