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

/* Variables and functions */
double convert_int24_to_double(void *buf, int i) {
  int32_t tmp;
  tmp = ((uint8_t *)buf)[i * 3 + 2] << 24;
  tmp |= ((uint8_t *)buf)[i * 3 + 1] << 16;
  tmp |= ((uint8_t *)buf)[i * 3] << 8;
  tmp >>= 8;
  return tmp;
}


x86 assembly (clang, -O0):
<convert_int24_to_double>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
imul   $0x3,-0xc(%rbp),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%eax
shl    $0x18,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
imul   $0x3,-0xc(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%eax
shl    $0x10,%eax
or     -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
imul   $0x3,-0xc(%rbp),%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%eax
shl    $0x8,%eax
or     -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
sar    $0x8,%eax
mov    %eax,-0x10(%rbp)
cvtsi2sdl -0x10(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<convert_int24_to_double>:
lea    (%rsi,%rsi,2),%eax
cltq
mov    0x8(%rdi,%rax,4),%ecx
shl    $0x18,%ecx
mov    (%rdi,%rax,4),%edx
mov    0x4(%rdi,%rax,4),%eax
shl    $0x10,%eax
or     %ecx,%eax
shl    $0x8,%edx
or     %eax,%edx
sar    $0x8,%edx
cvtsi2sd %edx,%xmm0
ret

LLVM IR (-O0):
define double @convert_int24_to_double(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 = bitcast i8* %6 to i32*
%8 = load i32, i32* %4
%9 = mul nsw i32 %8, 3
%10 = add nsw i32 %9, 2
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i32, i32* %7, i64 %11
%13 = load i32, i32* %12
%14 = shl i32 %13, 24
store i32 %14, i32* %5
%15 = load i8*, i8** %3
%16 = bitcast i8* %15 to i32*
%17 = load i32, i32* %4
%18 = mul nsw i32 %17, 3
%19 = add nsw i32 %18, 1
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i32, i32* %16, i64 %20
%22 = load i32, i32* %21
%23 = shl i32 %22, 16
%24 = load i32, i32* %5
%25 = or i32 %24, %23
store i32 %25, i32* %5
%26 = load i8*, i8** %3
%27 = bitcast i8* %26 to i32*
%28 = load i32, i32* %4
%29 = mul nsw i32 %28, 3
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i32, i32* %27, i64 %30
%32 = load i32, i32* %31
%33 = shl i32 %32, 8
%34 = load i32, i32* %5
%35 = or i32 %34, %33
store i32 %35, i32* %5
%36 = load i32, i32* %5
%37 = ashr i32 %36, 8
store i32 %37, i32* %5
%38 = load i32, i32* %5
%39 = sitofp i32 %38 to double
ret double %39
}

LLVM IR (-O2):
define double @convert_int24_to_double(i8* nocapture %0, i32 %1) {
%3 = bitcast i8* %0 to i32*
%4 = mul nsw i32 %1, 3
%5 = add nsw i32 %4, 2
%6 = sext i32 %5 to i64
%7 = getelementptr inbounds i32, i32* %3, i64 %6
%8 = load i32, i32* %7
%9 = shl i32 %8, 24
%10 = add nsw i32 %4, 1
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i32, i32* %3, i64 %11
%13 = load i32, i32* %12
%14 = shl i32 %13, 16
%15 = or i32 %14, %9
%16 = sext i32 %4 to i64
%17 = getelementptr inbounds i32, i32* %3, i64 %16
%18 = load i32, i32* %17
%19 = shl i32 %18, 8
%20 = or i32 %15, %19
%21 = ashr exact i32 %20, 8
%22 = sitofp i32 %21 to double
ret double %22
}