#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_signed16(uint8_t *apdu, int32_t *value) {
  if (value) {
    if (apdu[0] & 0x80)
      *value = 0xFFFF0000;
    else
      *value = 0;
    *value |= ((int32_t)((((int32_t)apdu[0]) << 8) & 0x0000ff00));
    *value |= ((int32_t)(((int32_t)apdu[1]) & 0x000000ff));
  }
  return 2;
}


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

x86 assembly (clang, -O2):
<decode_signed16>:
test   %rsi,%rsi
je     1123 <decode_signed16+0x23>
movsbl (%rdi),%eax
and    $0xffff0000,%eax
mov    %eax,(%rsi)
mov    (%rdi),%ecx
shl    $0x8,%ecx
movzwl %cx,%ecx
or     %eax,%ecx
mov    %ecx,(%rsi)
movzbl 0x4(%rdi),%eax
or     %ecx,%eax
mov    %eax,(%rsi)
mov    $0x2,%eax
ret

LLVM IR (-O0):
define i32 @decode_signed16(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 %33
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 -65536, 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, 8
%22 = and i32 %21, 65280
%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 = and i32 %28, 255
%30 = load i32*, i32** %4
%31 = load i32, i32* %30
%32 = or i32 %31, %29
store i32 %32, i32* %30
br label %33
33: ; preds = %17, %2
ret i32 2
}

LLVM IR (-O2):
define i32 @decode_signed16(i32* nocapture %0, i32* writeonly %1) {
%3 = icmp eq i32* %1, null
br i1 %3, label %17, 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 -65536
store i32 %8, i32* %1
%9 = load i32, i32* %0
%10 = shl i32 %9, 8
%11 = and i32 %10, 65280
%12 = or i32 %11, %8
store i32 %12, i32* %1
%13 = getelementptr inbounds i32, i32* %0, i64 1
%14 = load i32, i32* %13
%15 = and i32 %14, 255
%16 = or i32 %12, %15
store i32 %16, i32* %1
br label %17
17: ; preds = %4, %2
ret i32 2
}