#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 int uint8_t;
typedef int /*<<< orphan*/ h;

/* Variables and functions */
int /*<<< orphan*/ memset(int *, int /*<<< orphan*/, int);
int /*<<< orphan*/ ripemd160(int *, int, int *);
int /*<<< orphan*/ sha256_Raw(int const *, int, int *);
void ecdsa_get_pubkeyhash(const uint8_t *pub_key, uint8_t *pubkeyhash) {
  uint8_t h[32];
  if (pub_key[0] == 0x04) {
    sha256_Raw(pub_key, 65, h);
  } else if (pub_key[0] == 0x00) {
    sha256_Raw(pub_key, 1, h);
  } else {
    sha256_Raw(pub_key, 33, h);
  }
  ripemd160(h, 32, pubkeyhash);
  memset((h), 0, (sizeof(h)));
}


x86 assembly (clang, -O0):
<ecdsa_get_pubkeyhash>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
cmpl   $0x4,(%rax)
jne    116a <ecdsa_get_pubkeyhash+0x3a>
mov    -0x8(%rbp),%rdi
lea    -0x90(%rbp),%rdx
mov    $0x41,%esi
call   1030 <sha256_Raw@plt>
jmp    11ab <ecdsa_get_pubkeyhash+0x7b>
mov    -0x8(%rbp),%rax
cmpl   $0x0,(%rax)
jne    1191 <ecdsa_get_pubkeyhash+0x61>
mov    -0x8(%rbp),%rdi
lea    -0x90(%rbp),%rdx
mov    $0x1,%esi
call   1030 <sha256_Raw@plt>
jmp    11a6 <ecdsa_get_pubkeyhash+0x76>
mov    -0x8(%rbp),%rdi
lea    -0x90(%rbp),%rdx
mov    $0x21,%esi
call   1030 <sha256_Raw@plt>
jmp    11ab <ecdsa_get_pubkeyhash+0x7b>
lea    -0x90(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x20,%esi
call   1050 <ripemd160@plt>
lea    -0x90(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1040 <memset@plt>
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ecdsa_get_pubkeyhash>:
push   %r14
push   %rbx
sub    $0x88,%rsp
mov    %rsi,%r14
mov    (%rdi),%eax
xor    %ecx,%ecx
test   %eax,%eax
setne  %cl
shl    $0x5,%ecx
or     $0x1,%ecx
cmp    $0x4,%eax
mov    $0x41,%esi
cmovne %ecx,%esi
mov    %rsp,%rbx
mov    %rbx,%rdx
call   1030 <sha256_Raw@plt>
mov    %rbx,%rdi
mov    $0x20,%esi
mov    %r14,%rdx
call   1050 <ripemd160@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1040 <memset@plt>
add    $0x88,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @ecdsa_get_pubkeyhash(i32* %0, i32* %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca [32 x i32]
store i32* %0, i32** %3
store i32* %1, i32** %4
%6 = load i32*, i32** %3
%7 = getelementptr inbounds i32, i32* %6, i64 0
%8 = load i32, i32* %7
%9 = icmp eq i32 %8, 4
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = load i32*, i32** %3
%12 = getelementptr inbounds [32 x i32], [32 x i32]* %5, i64 0, i64 0
%13 = call i32 @sha256_Raw(i32* %11, i32 65, i32* %12)
br label %28
14: ; preds = %2
%15 = load i32*, i32** %3
%16 = getelementptr inbounds i32, i32* %15, i64 0
%17 = load i32, i32* %16
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %14
%20 = load i32*, i32** %3
%21 = getelementptr inbounds [32 x i32], [32 x i32]* %5, i64 0, i64 0
%22 = call i32 @sha256_Raw(i32* %20, i32 1, i32* %21)
br label %27
23: ; preds = %14
%24 = load i32*, i32** %3
%25 = getelementptr inbounds [32 x i32], [32 x i32]* %5, i64 0, i64 0
%26 = call i32 @sha256_Raw(i32* %24, i32 33, i32* %25)
br label %27
27: ; preds = %23, %19
br label %28
28: ; preds = %27, %10
%29 = getelementptr inbounds [32 x i32], [32 x i32]* %5, i64 0, i64 0
%30 = load i32*, i32** %4
%31 = call i32 @ripemd160(i32* %29, i32 32, i32* %30)
%32 = getelementptr inbounds [32 x i32], [32 x i32]* %5, i64 0, i64 0
%33 = call i32 @memset(i32* %32, i32 0, i32 128)
ret void
}

LLVM IR (-O2):
define void @ecdsa_get_pubkeyhash(i32* %0, i32* %1) {
%3 = alloca [32 x i32]
%4 = bitcast [32 x i32]* %3 to i8*
%5 = load i32, i32* %0
%6 = icmp eq i32 %5, 0
%7 = select i1 %6, i32 1, i32 33
%8 = icmp eq i32 %5, 4
%9 = select i1 %8, i32 65, i32 %7
%10 = getelementptr inbounds [32 x i32], [32 x i32]* %3, i64 0, i64 0
%11 = call i32 @sha256_Raw(i32* %0, i32 %9, i32* %10)
%12 = getelementptr inbounds [32 x i32], [32 x i32]* %3, i64 0, i64 0
%13 = call i32 @ripemd160(i32* %12, i32 32, i32* %1)
%14 = call i32 @memset(i32* %12, i32 0, i32 128)
ret void
}