#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 uint32_t;

/* Variables and functions */
int be32toh(int);
int snprintf(char *, size_t, char *, int);
int get_truncate(const uint8_t *hash, size_t len, char *buffer, size_t maxlen) {
  uint32_t value;
  uint8_t offset;
  offset = hash[len - 1] & 0x0F;
  value = *((uint32_t *)(hash + offset));
  value = be32toh(value) & 0x7FFFFFFF;
  value %= 100000000;
  return snprintf(buffer, maxlen, "%08d", value);
}


x86 assembly (clang, -O0):
<get_truncate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    $0x1,%rcx
mov    (%rax,%rcx,4),%eax
and    $0xf,%eax
mov    %eax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
call   1040 <be32toh@plt>
and    $0x7fffffff,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    $0x5f5e100,%ecx
cltd
idiv   %ecx
mov    %edx,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%ecx
lea    0xe75(%rip),%rdx
call   1030 <snprintf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_truncate>:
push   %r14
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdx,%rbx
mov    -0x4(%rdi,%rsi,4),%eax
and    $0xf,%eax
mov    (%rdi,%rax,4),%edi
call   1040 <be32toh@plt>
and    $0x7fffffff,%eax
imul   $0x55e63b89,%rax,%rcx
shr    $0x39,%rcx
imul   $0x5f5e100,%ecx,%ecx
sub    %ecx,%eax
lea    0xea8(%rip),%rdx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %eax,%ecx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <snprintf@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"%08d\00"
define i32 @get_truncate(i32* %0, i64 %1, i8* %2, i64 %3) {
%5 = alloca i32*
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32
%10 = alloca i32
store i32* %0, i32** %5
store i64 %1, i64* %6
store i8* %2, i8** %7
store i64 %3, i64* %8
%11 = load i32*, i32** %5
%12 = load i64, i64* %6
%13 = sub i64 %12, 1
%14 = getelementptr inbounds i32, i32* %11, i64 %13
%15 = load i32, i32* %14
%16 = and i32 %15, 15
store i32 %16, i32* %10
%17 = load i32*, i32** %5
%18 = load i32, i32* %10
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i32, i32* %17, i64 %19
%21 = load i32, i32* %20
store i32 %21, i32* %9
%22 = load i32, i32* %9
%23 = call i32 @be32toh(i32 %22)
%24 = and i32 %23, 2147483647
store i32 %24, i32* %9
%25 = load i32, i32* %9
%26 = srem i32 %25, 100000000
store i32 %26, i32* %9
%27 = load i8*, i8** %7
%28 = load i64, i64* %8
%29 = load i32, i32* %9
%30 = call i32 @snprintf(i8* %27, i64 %28, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %29)
ret i32 %30
}

LLVM IR (-O2):
@.str = [5 x i8] c"%08d\00"
define i32 @get_truncate(i32* nocapture %0, i64 %1, i8* %2, i64 %3) {
%5 = add i64 %1, -1
%6 = getelementptr inbounds i32, i32* %0, i64 %5
%7 = load i32, i32* %6
%8 = and i32 %7, 15
%9 = zext i32 %8 to i64
%10 = getelementptr inbounds i32, i32* %0, i64 %9
%11 = load i32, i32* %10
%12 = tail call i32 @be32toh(i32 %11)
%13 = and i32 %12, 2147483647
%14 = urem i32 %13, 100000000
%15 = tail call i32 @snprintf(i8* %2, i64 %3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %14)
ret i32 %15
}