#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 SHA_DIGEST_LENGTH;
int getHexVal(char);
void convertHash(const char *hexhash, unsigned char *binhash) {
  int i;
  for (i = 0; i < SHA_DIGEST_LENGTH; i++) {
    char first = *(hexhash + (2 * i));
    char second = *(hexhash + (2 * i) + 1);
    *(binhash + i) = (getHexVal(first) * 16) + getHexVal(second);
  }
}


x86 assembly (clang, -O0):
<convertHash>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    0x2eb7(%rip),%rcx
cmp    (%rcx),%eax
jge    119a <convertHash+0x8a>
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
shl    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x15(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
shl    $0x1,%ecx
movslq %ecx,%rcx
mov    0x1(%rax,%rcx,1),%al
mov    %al,-0x16(%rbp)
movsbl -0x15(%rbp),%edi
call   1030 <getHexVal@plt>
shl    $0x4,%eax
mov    %eax,-0x1c(%rbp)
movsbl -0x16(%rbp),%edi
call   1030 <getHexVal@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
add    %ecx,%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1127 <convertHash+0x17>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<convertHash>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    0x2ec6(%rip),%r12
cmpl   $0x0,(%r12)
jle    1170 <convertHash+0x60>
mov    %rsi,%r14
mov    %rdi,%r15
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsbl (%r15,%rbp,2),%edi
movsbl 0x1(%r15,%rbp,2),%r13d
call   1030 <getHexVal@plt>
mov    %eax,%ebx
shl    $0x4,%ebx
mov    %r13d,%edi
call   1030 <getHexVal@plt>
add    %ebx,%eax
mov    %al,(%r14,%rbp,1)
add    $0x1,%rbp
movslq (%r12),%rax
cmp    %rax,%rbp
jl     1140 <convertHash+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@SHA_DIGEST_LENGTH = global i32 0
define void @convertHash(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8
%7 = alloca i8
store i8* %0, i8** %3
store i8* %1, i8** %4
store i32 0, i32* %5
br label %8
8: ; preds = %37, %2
%9 = load i32, i32* %5
%10 = load i32, i32* @SHA_DIGEST_LENGTH
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %40
12: ; preds = %8
%13 = load i8*, i8** %3
%14 = load i32, i32* %5
%15 = mul nsw i32 2, %14
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %13, i64 %16
%18 = load i8, i8* %17
store i8 %18, i8* %6
%19 = load i8*, i8** %3
%20 = load i32, i32* %5
%21 = mul nsw i32 2, %20
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %19, i64 %22
%24 = getelementptr inbounds i8, i8* %23, i64 1
%25 = load i8, i8* %24
store i8 %25, i8* %7
%26 = load i8, i8* %6
%27 = call i32 @getHexVal(i8 signext %26)
%28 = mul nsw i32 %27, 16
%29 = load i8, i8* %7
%30 = call i32 @getHexVal(i8 signext %29)
%31 = add nsw i32 %28, %30
%32 = trunc i32 %31 to i8
%33 = load i8*, i8** %4
%34 = load i32, i32* %5
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %33, i64 %35
store i8 %32, i8* %36
br label %37
37: ; preds = %12
%38 = load i32, i32* %5
%39 = add nsw i32 %38, 1
store i32 %39, i32* %5
br label %8
40: ; preds = %8
ret void
}

LLVM IR (-O2):
@SHA_DIGEST_LENGTH = global i32 0
define void @convertHash(i8* nocapture %0, i8* nocapture writeonly %1) {
%3 = load i32, i32* @SHA_DIGEST_LENGTH
%4 = icmp sgt i32 %3, 0
br i1 %4, label %5, label %22
5: ; preds = %2, %5
%6 = phi i64 [ %18, %5 ], [ 0, %2 ]
%7 = shl nuw nsw i64 %6, 1
%8 = getelementptr inbounds i8, i8* %0, i64 %7
%9 = load i8, i8* %8
%10 = getelementptr inbounds i8, i8* %8, i64 1
%11 = load i8, i8* %10
%12 = tail call i32 @getHexVal(i8 signext %9)
%13 = shl nsw i32 %12, 4
%14 = tail call i32 @getHexVal(i8 signext %11)
%15 = add nsw i32 %13, %14
%16 = trunc i32 %15 to i8
%17 = getelementptr inbounds i8, i8* %1, i64 %6
store i8 %16, i8* %17
%18 = add nuw nsw i64 %6, 1
%19 = load i32, i32* @SHA_DIGEST_LENGTH
%20 = sext i32 %19 to i64
%21 = icmp slt i64 %18, %20
br i1 %21, label %5, label %22
22: ; preds = %5, %2
ret void
}