#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*/ md5(unsigned char const *, int, unsigned char *);
int /*<<< orphan*/ memset(unsigned char *, float, int);
int /*<<< orphan*/ sha1(unsigned char const *, int, unsigned char *);
int /*<<< orphan*/ sha2(unsigned char const *, int, unsigned char *, int);
int /*<<< orphan*/ sha4(unsigned char const *, int, unsigned char *, int);
void x509_hash(const unsigned char *in, int len, int alg, unsigned char *out) {
  switch (alg) {
  case 4:
    md5(in, len, out);
    break;
  case 5:
    sha1(in, len, out);
    break;
  case 14:
    sha2(in, len, out, 1);
    break;
  case 11:
    sha2(in, len, out, 0);
    break;
  case 12:
    sha4(in, len, out, 1);
    break;
  case 13:
    sha4(in, len, out, 0);
    break;
  default:
    memset(out, '\xFF', 64);
    break;
  }
}


x86 assembly (clang, -O0):
<x509_hash>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    -0x10(%rbp),%eax
add    $0xfffffffc,%eax
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0xa,%eax
ja     121b <x509_hash+0xcb>
mov    -0x20(%rbp),%rax
lea    0xe7e(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rdx
call   1070 <md5@plt>
jmp    1231 <x509_hash+0xe1>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rdx
call   1030 <sha1@plt>
jmp    1231 <x509_hash+0xe1>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rdx
mov    $0x1,%ecx
call   1060 <sha2@plt>
jmp    1231 <x509_hash+0xe1>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rdx
xor    %ecx,%ecx
call   1060 <sha2@plt>
jmp    1231 <x509_hash+0xe1>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rdx
mov    $0x1,%ecx
call   1050 <sha4@plt>
jmp    1231 <x509_hash+0xe1>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rdx
xor    %ecx,%ecx
call   1050 <sha4@plt>
jmp    1231 <x509_hash+0xe1>
mov    -0x18(%rbp),%rdi
movss  0xdd9(%rip),%xmm0
mov    $0x40,%esi
call   1040 <memset@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<x509_hash>:
add    $0xfffffffc,%edx
cmp    $0xa,%edx
ja     1178 <x509_hash+0x28>
lea    0xea5(%rip),%rax
movslq (%rax,%rdx,4),%rdx
add    %rax,%rdx
jmp    *%rdx
mov    %rcx,%rdx
jmp    1070 <md5@plt>
mov    %rcx,%rdx
jmp    1030 <sha1@plt>
movss  0xe80(%rip),%xmm0
mov    %rcx,%rdi
mov    $0x40,%esi
jmp    1040 <memset@plt>
mov    %rcx,%rdx
xor    %ecx,%ecx
jmp    1060 <sha2@plt>
mov    %rcx,%rdx
mov    $0x1,%ecx
jmp    1050 <sha4@plt>
mov    %rcx,%rdx
xor    %ecx,%ecx
jmp    1050 <sha4@plt>
mov    %rcx,%rdx
mov    $0x1,%ecx
jmp    1060 <sha2@plt>

LLVM IR (-O0):
define void @x509_hash(i8* %0, i32 %1, i32 %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i8* %3, i8** %8
%9 = load i32, i32* %7
switch i32 %9, label %40 [
i32 4, label %10
i32 5, label %15
i32 14, label %20
i32 11, label %25
i32 12, label %30
i32 13, label %35
]
10: ; preds = %4
%11 = load i8*, i8** %5
%12 = load i32, i32* %6
%13 = load i8*, i8** %8
%14 = call i32 @md5(i8* %11, i32 %12, i8* %13)
br label %43
15: ; preds = %4
%16 = load i8*, i8** %5
%17 = load i32, i32* %6
%18 = load i8*, i8** %8
%19 = call i32 @sha1(i8* %16, i32 %17, i8* %18)
br label %43
20: ; preds = %4
%21 = load i8*, i8** %5
%22 = load i32, i32* %6
%23 = load i8*, i8** %8
%24 = call i32 @sha2(i8* %21, i32 %22, i8* %23, i32 1)
br label %43
25: ; preds = %4
%26 = load i8*, i8** %5
%27 = load i32, i32* %6
%28 = load i8*, i8** %8
%29 = call i32 @sha2(i8* %26, i32 %27, i8* %28, i32 0)
br label %43
30: ; preds = %4
%31 = load i8*, i8** %5
%32 = load i32, i32* %6
%33 = load i8*, i8** %8
%34 = call i32 @sha4(i8* %31, i32 %32, i8* %33, i32 1)
br label %43
35: ; preds = %4
%36 = load i8*, i8** %5
%37 = load i32, i32* %6
%38 = load i8*, i8** %8
%39 = call i32 @sha4(i8* %36, i32 %37, i8* %38, i32 0)
br label %43
40: ; preds = %4
%41 = load i8*, i8** %8
%42 = call i32 @memset(i8* %41, float -1.000000e+00, i32 64)
br label %43
43: ; preds = %40, %35, %30, %25, %20, %15, %10
ret void
}

LLVM IR (-O2):
define void @x509_hash(i8* %0, i32 %1, i32 %2, i8* %3) {
switch i32 %2, label %17 [
i32 4, label %5
i32 5, label %7
i32 14, label %9
i32 11, label %11
i32 12, label %13
i32 13, label %15
]
5: ; preds = %4
%6 = tail call i32 @md5(i8* %0, i32 %1, i8* %3)
br label %19
7: ; preds = %4
%8 = tail call i32 @sha1(i8* %0, i32 %1, i8* %3)
br label %19
9: ; preds = %4
%10 = tail call i32 @sha2(i8* %0, i32 %1, i8* %3, i32 1)
br label %19
11: ; preds = %4
%12 = tail call i32 @sha2(i8* %0, i32 %1, i8* %3, i32 0)
br label %19
13: ; preds = %4
%14 = tail call i32 @sha4(i8* %0, i32 %1, i8* %3, i32 1)
br label %19
15: ; preds = %4
%16 = tail call i32 @sha4(i8* %0, i32 %1, i8* %3, i32 0)
br label %19
17: ; preds = %4
%18 = tail call i32 @memset(i8* %3, float -1.000000e+00, i32 64)
br label %19
19: ; preds = %17, %15, %13, %11, %9, %7, %5
ret void
}