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

/* Variables and functions */
int /*<<< orphan*/ memcpy(int /*<<< orphan*/ *, int *, int);
scalar_t__ strtoull(char const *, int /*<<< orphan*/ *, int);
void str_to_keyid(const char *s, uint8_t *keyid) {
  uint64_t u64;
  u64 = (uint64_t)strtoull(s, NULL, 16);
  u64 = ((u64 & 0x00000000000000FFUL) << 56) |
        ((u64 & 0x000000000000FF00UL) << 40) |
        ((u64 & 0x0000000000FF0000UL) << 24) |
        ((u64 & 0x00000000FF000000UL) << 8) |
        ((u64 & 0x000000FF00000000UL) >> 8) |
        ((u64 & 0x0000FF0000000000UL) >> 24) |
        ((u64 & 0x00FF000000000000UL) >> 40) |
        ((u64 & 0xFF00000000000000UL) >> 56);
  memcpy(keyid, &u64, 8);
}


x86 assembly (clang, -O0):
<str_to_keyid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1030 <strtoull@plt>
mov    %eax,-0x14(%rbp)
movslq -0x14(%rbp),%rax
and    $0xff,%rax
shl    $0x38,%rax
movslq -0x14(%rbp),%rcx
and    $0xff00,%rcx
shl    $0x28,%rcx
or     %rcx,%rax
movslq -0x14(%rbp),%rcx
and    $0xff0000,%rcx
shl    $0x18,%rcx
or     %rcx,%rax
movslq -0x14(%rbp),%rcx
movabs $0xff000000,%rdx
and    %rdx,%rcx
shl    $0x8,%rcx
or     %rcx,%rax
movslq -0x14(%rbp),%rcx
movabs $0xff00000000,%rdx
and    %rdx,%rcx
shr    $0x8,%rcx
or     %rcx,%rax
movslq -0x14(%rbp),%rcx
movabs $0xff0000000000,%rdx
and    %rdx,%rcx
shr    $0x18,%rcx
or     %rcx,%rax
movslq -0x14(%rbp),%rcx
movabs $0xff000000000000,%rdx
and    %rdx,%rcx
shr    $0x28,%rcx
or     %rcx,%rax
movslq -0x14(%rbp),%rcx
movabs $0xff00000000000000,%rdx
and    %rdx,%rcx
shr    $0x38,%rcx
or     %rcx,%rax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x14(%rbp),%rsi
mov    $0x8,%edx
call   1040 <memcpy@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_to_keyid>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
xor    %esi,%esi
mov    $0x10,%edx
call   1030 <strtoull@plt>
cltq
mov    %rax,%rcx
shr    $0x8,%rcx
and    $0xff000000,%ecx
mov    %rax,%rdx
shr    $0x18,%rdx
and    $0xff0000,%edx
mov    %rax,%rsi
shr    $0x28,%rsi
and    $0xff00,%esi
shr    $0x38,%rax
or     %ecx,%eax
or     %edx,%eax
or     %esi,%eax
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rsi
mov    %rbx,%rdi
mov    $0x8,%edx
call   1040 <memcpy@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define void @str_to_keyid(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32
store i8* %0, i8** %3
store i32* %1, i32** %4
%6 = load i8*, i8** %3
%7 = call i64 @strtoull(i8* %6, i32* null, i32 16)
%8 = trunc i64 %7 to i32
store i32 %8, i32* %5
%9 = load i32, i32* %5
%10 = sext i32 %9 to i64
%11 = and i64 %10, 255
%12 = shl i64 %11, 56
%13 = load i32, i32* %5
%14 = sext i32 %13 to i64
%15 = and i64 %14, 65280
%16 = shl i64 %15, 40
%17 = or i64 %12, %16
%18 = load i32, i32* %5
%19 = sext i32 %18 to i64
%20 = and i64 %19, 16711680
%21 = shl i64 %20, 24
%22 = or i64 %17, %21
%23 = load i32, i32* %5
%24 = sext i32 %23 to i64
%25 = and i64 %24, 4278190080
%26 = shl i64 %25, 8
%27 = or i64 %22, %26
%28 = load i32, i32* %5
%29 = sext i32 %28 to i64
%30 = and i64 %29, 1095216660480
%31 = lshr i64 %30, 8
%32 = or i64 %27, %31
%33 = load i32, i32* %5
%34 = sext i32 %33 to i64
%35 = and i64 %34, 280375465082880
%36 = lshr i64 %35, 24
%37 = or i64 %32, %36
%38 = load i32, i32* %5
%39 = sext i32 %38 to i64
%40 = and i64 %39, 71776119061217280
%41 = lshr i64 %40, 40
%42 = or i64 %37, %41
%43 = load i32, i32* %5
%44 = sext i32 %43 to i64
%45 = and i64 %44, -72057594037927936
%46 = lshr i64 %45, 56
%47 = or i64 %42, %46
%48 = trunc i64 %47 to i32
store i32 %48, i32* %5
%49 = load i32*, i32** %4
%50 = call i32 @memcpy(i32* %49, i32* %5, i32 8)
ret void
}

LLVM IR (-O2):
define void @str_to_keyid(i8* nocapture %0, i32* %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = tail call i64 @strtoull(i8* nocapture %0, i32* null, i32 16)
%6 = shl i64 %5, 32
%7 = ashr exact i64 %6, 32
%8 = lshr i64 %7, 8
%9 = and i64 %8, 4278190080
%10 = lshr i64 %7, 24
%11 = and i64 %10, 16711680
%12 = lshr i64 %7, 40
%13 = and i64 %12, 65280
%14 = lshr i64 %7, 56
%15 = or i64 %14, %9
%16 = or i64 %15, %11
%17 = or i64 %16, %13
%18 = trunc i64 %17 to i32
store i32 %18, i32* %3
%19 = call i32 @memcpy(i32* %1, i32* %3, i32 8)
ret void
}