#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 uint_fast32_t;
typedef int /*<<< orphan*/ int_fast32_t;

/* Variables and functions */
__attribute__((unused)) int_fast32_t cop_ld_sle24(const void *buf) {
  uint_fast32_t val;
  val = ((const unsigned char *)buf)[2];
  val = (val << 8) | ((const unsigned char *)buf)[1];
  val = (val << 8) | ((const unsigned char *)buf)[0];
  return (val & 0x800000u) ? -(int_fast32_t)(((~val) & 0x7FFFFFu) + 1)
                           : (int_fast32_t)val;
}


x86 assembly (clang, -O0):
<cop_ld_sle24>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movzbl 0x2(%rax),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
shl    $0x8,%eax
mov    -0x8(%rbp),%rcx
movzbl 0x1(%rcx),%ecx
or     %ecx,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
shl    $0x8,%eax
mov    -0x8(%rbp),%rcx
movzbl (%rcx),%ecx
or     %ecx,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
and    $0x800000,%eax
cmp    $0x0,%eax
je     1164 <cop_ld_sle24+0x64>
mov    -0xc(%rbp),%ecx
xor    $0xffffffff,%ecx
and    $0x7fffff,%ecx
add    $0x1,%ecx
xor    %eax,%eax
sub    %ecx,%eax
mov    %eax,-0x10(%rbp)
jmp    116a <cop_ld_sle24+0x6a>
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<cop_ld_sle24>:
movzbl 0x2(%rdi),%ecx
movzbl 0x1(%rdi),%eax
mov    %ecx,%edx
shl    $0x10,%edx
shl    $0x8,%eax
or     %edx,%eax
movzbl (%rdi),%edx
or     %eax,%edx
mov    %edx,%eax
or     $0xff800000,%eax
test   $0x80,%cl
cmove  %edx,%eax
ret

LLVM IR (-O0):
define i32 @cop_ld_sle24(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = getelementptr inbounds i8, i8* %4, i64 2
%6 = load i8, i8* %5
%7 = zext i8 %6 to i32
store i32 %7, i32* %3
%8 = load i32, i32* %3
%9 = shl i32 %8, 8
%10 = load i8*, i8** %2
%11 = getelementptr inbounds i8, i8* %10, i64 1
%12 = load i8, i8* %11
%13 = zext i8 %12 to i32
%14 = or i32 %9, %13
store i32 %14, i32* %3
%15 = load i32, i32* %3
%16 = shl i32 %15, 8
%17 = load i8*, i8** %2
%18 = getelementptr inbounds i8, i8* %17, i64 0
%19 = load i8, i8* %18
%20 = zext i8 %19 to i32
%21 = or i32 %16, %20
store i32 %21, i32* %3
%22 = load i32, i32* %3
%23 = and i32 %22, 8388608
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %31
25: ; preds = %1
%26 = load i32, i32* %3
%27 = xor i32 %26, -1
%28 = and i32 %27, 8388607
%29 = add i32 %28, 1
%30 = sub nsw i32 0, %29
br label %33
31: ; preds = %1
%32 = load i32, i32* %3
br label %33
33: ; preds = %31, %25
%34 = phi i32 [ %30, %25 ], [ %32, %31 ]
ret i32 %34
}

LLVM IR (-O2):
define i32 @cop_ld_sle24(i8* nocapture %0) {
%2 = getelementptr inbounds i8, i8* %0, i64 2
%3 = load i8, i8* %2
%4 = zext i8 %3 to i32
%5 = getelementptr inbounds i8, i8* %0, i64 1
%6 = load i8, i8* %5
%7 = zext i8 %6 to i32
%8 = shl nuw nsw i32 %4, 16
%9 = shl nuw nsw i32 %7, 8
%10 = or i32 %9, %8
%11 = load i8, i8* %0
%12 = zext i8 %11 to i32
%13 = or i32 %10, %12
%14 = and i32 %4, 128
%15 = icmp eq i32 %14, 0
%16 = or i32 %13, -8388608
%17 = select i1 %15, i32 %13, i32 %16
ret i32 %17
}