#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 */
int decode_signed24(uint8_t *apdu, int32_t *value) {
  if (value) {
    if (apdu[0] & 0x80)
      *value = 0xFF000000;
    else
      *value = 0;
    *value |= ((int32_t)((((int32_t)apdu[0]) << 16) & 0x00ff0000));
    *value |= ((int32_t)((((int32_t)apdu[1]) << 8) & 0x0000ff00));
    *value |= ((int32_t)(((int32_t)apdu[2]) & 0x000000ff));
  }
  return 3;
}


x86 assembly (clang, -O0):
<decode_signed24>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1188 <decode_signed24+0x88>
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
and    $0x80,%eax
cmp    $0x0,%eax
je     113a <decode_signed24+0x3a>
mov    -0x10(%rbp),%rax
movl   $0xff000000,(%rax)
jmp    1144 <decode_signed24+0x44>
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%ecx
shl    $0x10,%ecx
and    $0xff0000,%ecx
mov    -0x10(%rbp),%rax
or     (%rax),%ecx
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%ecx
shl    $0x8,%ecx
and    $0xff00,%ecx
mov    -0x10(%rbp),%rax
or     (%rax),%ecx
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%ecx
and    $0xff,%ecx
mov    -0x10(%rbp),%rax
or     (%rax),%ecx
mov    %ecx,(%rax)
mov    $0x3,%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<decode_signed24>:
test   %rsi,%rsi
je     1130 <decode_signed24+0x30>
movsbl (%rdi),%eax
and    $0xff000000,%eax
mov    %eax,(%rsi)
mov    (%rdi),%ecx
movzbl %cl,%ecx
shl    $0x10,%ecx
or     %eax,%ecx
mov    %ecx,(%rsi)
mov    0x4(%rdi),%eax
shl    $0x8,%eax
movzwl %ax,%eax
or     %ecx,%eax
mov    %eax,(%rsi)
movzbl 0x8(%rdi),%ecx
or     %eax,%ecx
mov    %ecx,(%rsi)
mov    $0x3,%eax
ret

LLVM IR (-O0):
define i32 @decode_signed24(i32* %0, i32* %1) {
%3 = alloca i32*
%4 = alloca i32*
store i32* %0, i32** %3
store i32* %1, i32** %4
%5 = load i32*, i32** %4
%6 = icmp ne i32* %5, null
br i1 %6, label %7, label %41
7: ; preds = %2
%8 = load i32*, i32** %3
%9 = getelementptr inbounds i32, i32* %8, i64 0
%10 = load i32, i32* %9
%11 = and i32 %10, 128
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %7
%14 = load i32*, i32** %4
store i32 -16777216, i32* %14
br label %17
15: ; preds = %7
%16 = load i32*, i32** %4
store i32 0, i32* %16
br label %17
17: ; preds = %15, %13
%18 = load i32*, i32** %3
%19 = getelementptr inbounds i32, i32* %18, i64 0
%20 = load i32, i32* %19
%21 = shl i32 %20, 16
%22 = and i32 %21, 16711680
%23 = load i32*, i32** %4
%24 = load i32, i32* %23
%25 = or i32 %24, %22
store i32 %25, i32* %23
%26 = load i32*, i32** %3
%27 = getelementptr inbounds i32, i32* %26, i64 1
%28 = load i32, i32* %27
%29 = shl i32 %28, 8
%30 = and i32 %29, 65280
%31 = load i32*, i32** %4
%32 = load i32, i32* %31
%33 = or i32 %32, %30
store i32 %33, i32* %31
%34 = load i32*, i32** %3
%35 = getelementptr inbounds i32, i32* %34, i64 2
%36 = load i32, i32* %35
%37 = and i32 %36, 255
%38 = load i32*, i32** %4
%39 = load i32, i32* %38
%40 = or i32 %39, %37
store i32 %40, i32* %38
br label %41
41: ; preds = %17, %2
ret i32 3
}

LLVM IR (-O2):
define i32 @decode_signed24(i32* nocapture %0, i32* writeonly %1) {
%3 = icmp eq i32* %1, null
br i1 %3, label %22, label %4
4: ; preds = %2
%5 = load i32, i32* %0
%6 = and i32 %5, 128
%7 = icmp eq i32 %6, 0
%8 = select i1 %7, i32 0, i32 -16777216
store i32 %8, i32* %1
%9 = load i32, i32* %0
%10 = shl i32 %9, 16
%11 = and i32 %10, 16711680
%12 = or i32 %11, %8
store i32 %12, i32* %1
%13 = getelementptr inbounds i32, i32* %0, i64 1
%14 = load i32, i32* %13
%15 = shl i32 %14, 8
%16 = and i32 %15, 65280
%17 = or i32 %16, %12
store i32 %17, i32* %1
%18 = getelementptr inbounds i32, i32* %0, i64 2
%19 = load i32, i32* %18
%20 = and i32 %19, 255
%21 = or i32 %17, %20
store i32 %21, i32* %1
br label %22
22: ; preds = %4, %2
ret i32 3
}