#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 */
char const *strchr(char const *, char const);
void hex_to_sha1(const char *s, unsigned char *sha1) {
  static const char hex[] = "0123456789abcdef";
  for (; *s; s += 2, ++sha1)
    *sha1 = ((strchr(hex, *s) - hex) << 4) + strchr(hex, *(s + 1)) - hex;
}


x86 assembly (clang, -O0):
<hex_to_sha1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     119c <hex_to_sha1+0x8c>
mov    -0x8(%rbp),%rax
lea    0xec8(%rip),%rdi
movsbl (%rax),%esi
call   1030 <strchr@plt>
lea    0xeb9(%rip),%rcx
sub    %rcx,%rax
shl    $0x4,%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
lea    0xea3(%rip),%rdi
movsbl 0x1(%rax),%esi
call   1030 <strchr@plt>
mov    -0x18(%rbp),%rcx
add    %rcx,%rax
lea    0xe8c(%rip),%rcx
sub    %rcx,%rax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
mov    -0x8(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1120 <hex_to_sha1+0x10>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hex_to_sha1>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    (%rdi),%al
test   %al,%al
je     1169 <hex_to_sha1+0x59>
mov    %rsi,%r14
mov    %rdi,%r15
xor    %r13d,%r13d
lea    0xed1(%rip),%r12
nop
movsbl %al,%esi
mov    %r12,%rdi
call   1030 <strchr@plt>
mov    %rax,%rbx
sub    %r12d,%ebx
shl    $0x4,%ebx
movsbl 0x1(%r15,%r13,2),%esi
mov    %r12,%rdi
call   1030 <strchr@plt>
add    %ebx,%eax
sub    %r12b,%al
mov    %al,(%r14,%r13,1)
movzbl 0x2(%r15,%r13,2),%eax
add    $0x1,%r13
test   %al,%al
jne    1130 <hex_to_sha1+0x20>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@hex_to_sha1.hex = internal constant [17 x i8] c"0123456789abcdef\00"
define void @hex_to_sha1(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
br label %5
5: ; preds = %25, %2
%6 = load i8*, i8** %3
%7 = load i8, i8* %6
%8 = icmp ne i8 %7, 0
br i1 %8, label %9, label %30
9: ; preds = %5
%10 = load i8*, i8** %3
%11 = load i8, i8* %10
%12 = call i8* @strchr(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @hex_to_sha1.hex, i64 0, i64 0), i8 signext %11)
%13 = ptrtoint i8* %12 to i64
%14 = sub i64 %13, ptrtoint ([17 x i8]* @hex_to_sha1.hex to i64)
%15 = shl i64 %14, 4
%16 = load i8*, i8** %3
%17 = getelementptr inbounds i8, i8* %16, i64 1
%18 = load i8, i8* %17
%19 = call i8* @strchr(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @hex_to_sha1.hex, i64 0, i64 0), i8 signext %18)
%20 = getelementptr inbounds i8, i8* %19, i64 %15
%21 = ptrtoint i8* %20 to i64
%22 = sub i64 %21, ptrtoint ([17 x i8]* @hex_to_sha1.hex to i64)
%23 = trunc i64 %22 to i8
%24 = load i8*, i8** %4
store i8 %23, i8* %24
br label %25
25: ; preds = %9
%26 = load i8*, i8** %3
%27 = getelementptr inbounds i8, i8* %26, i64 2
store i8* %27, i8** %3
%28 = load i8*, i8** %4
%29 = getelementptr inbounds i8, i8* %28, i32 1
store i8* %29, i8** %4
br label %5
30: ; preds = %5
ret void
}

LLVM IR (-O2):
@hex_to_sha1.hex = internal constant [17 x i8] c"0123456789abcdef\00"
define void @hex_to_sha1(i8* nocapture %0, i8* nocapture writeonly %1) {
%3 = load i8, i8* %0
%4 = icmp eq i8 %3, 0
br i1 %4, label %24, label %5
5: ; preds = %2, %5
%6 = phi i8 [ %22, %5 ], [ %3, %2 ]
%7 = phi i8* [ %21, %5 ], [ %1, %2 ]
%8 = phi i8* [ %20, %5 ], [ %0, %2 ]
%9 = tail call i8* @strchr(i8* dereferenceable(17) getelementptr inbounds ([17 x i8], [17 x i8]* @hex_to_sha1.hex, i64 0, i64 0), i8 signext %6)
%10 = ptrtoint i8* %9 to i64
%11 = sub i64 %10, ptrtoint ([17 x i8]* @hex_to_sha1.hex to i64)
%12 = shl i64 %11, 4
%13 = getelementptr inbounds i8, i8* %8, i64 1
%14 = load i8, i8* %13
%15 = tail call i8* @strchr(i8* dereferenceable(17) getelementptr inbounds ([17 x i8], [17 x i8]* @hex_to_sha1.hex, i64 0, i64 0), i8 signext %14)
%16 = getelementptr inbounds i8, i8* %15, i64 %12
%17 = ptrtoint i8* %16 to i64
%18 = trunc i64 %17 to i8
%19 = sub i8 %18, ptrtoint ([17 x i8]* @hex_to_sha1.hex to i8)
store i8 %19, i8* %7
%20 = getelementptr inbounds i8, i8* %8, i64 2
%21 = getelementptr inbounds i8, i8* %7, i64 1
%22 = load i8, i8* %20
%23 = icmp eq i8 %22, 0
br i1 %23, label %24, label %5
24: ; preds = %5, %2
ret void
}