#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 scalar_t__ uint8_t;
typedef int int32_t;

/* Variables and functions */
int decode_signed32(uint8_t *apdu, int32_t *value) {
  if (value) {
    *value = ((int32_t)((((int32_t)apdu[0]) << 24) & 0xff000000));
    *value |= ((int32_t)((((int32_t)apdu[1]) << 16) & 0x00ff0000));
    *value |= ((int32_t)((((int32_t)apdu[2]) << 8) & 0x0000ff00));
    *value |= ((int32_t)(((int32_t)apdu[3]) & 0x000000ff));
  }
  return 4;
}


x86 assembly (clang, -O0):
<decode_signed32>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     117d <decode_signed32+0x7d>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %eax,%ecx
shl    $0x18,%ecx
and    $0xff000000,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rax
mov    %eax,%ecx
shl    $0x10,%ecx
and    $0xff0000,%ecx
mov    -0x10(%rbp),%rax
or     (%rax),%ecx
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rax
mov    0x10(%rax),%rax
mov    %eax,%ecx
shl    $0x8,%ecx
and    $0xff00,%ecx
mov    -0x10(%rbp),%rax
or     (%rax),%ecx
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rax
mov    0x18(%rax),%rax
mov    %eax,%ecx
and    $0xff,%ecx
mov    -0x10(%rbp),%rax
or     (%rax),%ecx
mov    %ecx,(%rax)
mov    $0x4,%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<decode_signed32>:
test   %rsi,%rsi
je     1128 <decode_signed32+0x28>
mov    (%rdi),%eax
mov    0x8(%rdi),%ecx
shl    $0x18,%eax
movzbl %cl,%ecx
shl    $0x10,%ecx
or     %eax,%ecx
mov    0x10(%rdi),%eax
shl    $0x8,%eax
movzwl %ax,%eax
or     %ecx,%eax
movzbl 0x18(%rdi),%ecx
or     %eax,%ecx
mov    %ecx,(%rsi)
mov    $0x4,%eax
ret

LLVM IR (-O0):
define i32 @decode_signed32(i64* %0, i32* %1) {
%3 = alloca i64*
%4 = alloca i32*
store i64* %0, i64** %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 i64*, i64** %3
%9 = getelementptr inbounds i64, i64* %8, i64 0
%10 = load i64, i64* %9
%11 = trunc i64 %10 to i32
%12 = shl i32 %11, 24
%13 = and i32 %12, -16777216
%14 = load i32*, i32** %4
store i32 %13, i32* %14
%15 = load i64*, i64** %3
%16 = getelementptr inbounds i64, i64* %15, i64 1
%17 = load i64, i64* %16
%18 = trunc i64 %17 to i32
%19 = shl i32 %18, 16
%20 = and i32 %19, 16711680
%21 = load i32*, i32** %4
%22 = load i32, i32* %21
%23 = or i32 %22, %20
store i32 %23, i32* %21
%24 = load i64*, i64** %3
%25 = getelementptr inbounds i64, i64* %24, i64 2
%26 = load i64, i64* %25
%27 = trunc i64 %26 to i32
%28 = shl i32 %27, 8
%29 = and i32 %28, 65280
%30 = load i32*, i32** %4
%31 = load i32, i32* %30
%32 = or i32 %31, %29
store i32 %32, i32* %30
%33 = load i64*, i64** %3
%34 = getelementptr inbounds i64, i64* %33, i64 3
%35 = load i64, i64* %34
%36 = trunc i64 %35 to i32
%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 = %7, %2
ret i32 4
}

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