#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 /*<<< orphan*/ uint32_t;

/* Variables and functions */
int /*<<< orphan*/ htobe32(int /*<<< orphan*/);
int /*<<< orphan*/ sscanf(char const *, char *, int /*<<< orphan*/ *);
const char *hex2digest(const char *hexstr) {
  int i;
  uint32_t tmp;
  static unsigned char digest[20];
  for (i = 0; i < 5; i++) {
    sscanf(hexstr + 8 * i, "%08x", &tmp);
    *(uint32_t *)(digest + i * 4) = htobe32(tmp);
  }
  return digest;
}


x86 assembly (clang, -O0):
<hex2digest>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x5,-0xc(%rbp)
jge    1187 <hex2digest+0x67>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%eax
shl    $0x3,%eax
cltq
add    %rax,%rdi
lea    0xead(%rip),%rsi
lea    -0x10(%rbp),%rdx
call   1040 <sscanf@plt>
mov    -0x10(%rbp),%edi
call   1030 <htobe32@plt>
mov    %eax,%edx
mov    -0xc(%rbp),%eax
shl    $0x2,%eax
movslq %eax,%rcx
lea    0x2eca(%rip),%rax
mov    %edx,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1133 <hex2digest+0x13>
lea    0x2eb2(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hex2digest>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0xece(%rip),%r14
lea    0x4(%rsp),%r15
mov    %r14,%rsi
mov    %r15,%rdx
call   1040 <sscanf@plt>
mov    0x4(%rsp),%edi
call   1030 <htobe32@plt>
mov    %eax,0x2eef(%rip)
lea    0x2ee8(%rip),%r12
lea    0x8(%rbx),%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1040 <sscanf@plt>
mov    0x4(%rsp),%edi
call   1030 <htobe32@plt>
mov    %eax,0x2ece(%rip)
lea    0x10(%rbx),%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1040 <sscanf@plt>
mov    0x4(%rsp),%edi
call   1030 <htobe32@plt>
mov    %eax,0x2eb4(%rip)
lea    0x18(%rbx),%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1040 <sscanf@plt>
mov    0x4(%rsp),%edi
call   1030 <htobe32@plt>
mov    %eax,0x2e9a(%rip)
add    $0x20,%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1040 <sscanf@plt>
mov    0x4(%rsp),%edi
call   1030 <htobe32@plt>
mov    %eax,0x2e7d(%rip)
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@hex2digest.digest = internal global [20 x i8] zeroinitializer
@.str = [5 x i8] c"%08x\00"
define i8* @hex2digest(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %3
br label %5
5: ; preds = %22, %1
%6 = load i32, i32* %3
%7 = icmp slt i32 %6, 5
br i1 %7, label %8, label %25
8: ; preds = %5
%9 = load i8*, i8** %2
%10 = load i32, i32* %3
%11 = mul nsw i32 8, %10
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %9, i64 %12
%14 = call i32 @sscanf(i8* %13, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32* %4)
%15 = load i32, i32* %4
%16 = call i32 @htobe32(i32 %15)
%17 = load i32, i32* %3
%18 = mul nsw i32 %17, 4
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @hex2digest.digest, i64 0, i64 0), i64 %19
%21 = bitcast i8* %20 to i32*
store i32 %16, i32* %21
br label %22
22: ; preds = %8
%23 = load i32, i32* %3
%24 = add nsw i32 %23, 1
store i32 %24, i32* %3
br label %5
25: ; preds = %5
ret i8* getelementptr inbounds ([20 x i8], [20 x i8]* @hex2digest.digest, i64 0, i64 0)
}

LLVM IR (-O2):
@hex2digest.digest = internal global [20 x i8] zeroinitializer
@.str = [5 x i8] c"%08x\00"
define i8* @hex2digest(i8* nocapture %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32* %2)
%5 = load i32, i32* %2
%6 = call i32 @htobe32(i32 %5)
store i32 %6, i32* bitcast ([20 x i8]* @hex2digest.digest to i32*)
%7 = getelementptr inbounds i8, i8* %0, i64 8
%8 = call i32 @sscanf(i8* %7, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32* %2)
%9 = load i32, i32* %2
%10 = call i32 @htobe32(i32 %9)
store i32 %10, i32* bitcast (i8* getelementptr inbounds ([20 x i8], [20 x i8]* @hex2digest.digest, i64 0, i64 4) to i32*)
%11 = getelementptr inbounds i8, i8* %0, i64 16
%12 = call i32 @sscanf(i8* %11, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32* %2)
%13 = load i32, i32* %2
%14 = call i32 @htobe32(i32 %13)
store i32 %14, i32* bitcast (i8* getelementptr inbounds ([20 x i8], [20 x i8]* @hex2digest.digest, i64 0, i64 8) to i32*)
%15 = getelementptr inbounds i8, i8* %0, i64 24
%16 = call i32 @sscanf(i8* %15, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32* %2)
%17 = load i32, i32* %2
%18 = call i32 @htobe32(i32 %17)
store i32 %18, i32* bitcast (i8* getelementptr inbounds ([20 x i8], [20 x i8]* @hex2digest.digest, i64 0, i64 12) to i32*)
%19 = getelementptr inbounds i8, i8* %0, i64 32
%20 = call i32 @sscanf(i8* %19, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32* %2)
%21 = load i32, i32* %2
%22 = call i32 @htobe32(i32 %21)
store i32 %22, i32* bitcast (i8* getelementptr inbounds ([20 x i8], [20 x i8]* @hex2digest.digest, i64 0, i64 16) to i32*)
ret i8* getelementptr inbounds ([20 x i8], [20 x i8]* @hex2digest.digest, i64 0, i64 0)
}