#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__ uint32_t;
typedef int int32_t;

/* Variables and functions */
int __SSAT(int, int);
__attribute__((always_)) uint32_t __QSAX(uint32_t x, uint32_t y) {
  int32_t r, s;
  r = __SSAT(((((int32_t)x << 16) >> 16) + (((int32_t)y) >> 16)), 16) &
      (int32_t)0x0000FFFF;
  s = __SSAT(((((int32_t)x) >> 16) - (((int32_t)y << 16) >> 16)), 16) &
      (int32_t)0x0000FFFF;
  return ((uint32_t)((s << 16) | (r)));
}


x86 assembly (clang, -O0):
<__QSAX>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %eax,%edi
shl    $0x10,%edi
sar    $0x10,%edi
mov    -0x10(%rbp),%rax
sar    $0x10,%eax
add    %eax,%edi
mov    $0x10,%esi
call   1030 <__SSAT@plt>
and    $0xffff,%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    %eax,%edi
sar    $0x10,%edi
mov    -0x10(%rbp),%rax
shl    $0x10,%eax
sar    $0x10,%eax
sub    %eax,%edi
mov    $0x10,%esi
call   1030 <__SSAT@plt>
and    $0xffff,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
shl    $0x10,%eax
or     -0x14(%rbp),%eax
cltq
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__QSAX>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
movswl %bx,%eax
mov    %r14d,%edi
sar    $0x10,%edi
add    %eax,%edi
mov    $0x10,%esi
call   1030 <__SSAT@plt>
movzwl %ax,%ebp
sar    $0x10,%ebx
movswl %r14w,%eax
sub    %eax,%ebx
mov    %ebx,%edi
mov    $0x10,%esi
call   1030 <__SSAT@plt>
shl    $0x10,%eax
or     %ebp,%eax
cltq
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i64 @__QSAX(i64 %0, i64 %1) {
%3 = alloca i64
%4 = alloca i64
%5 = alloca i32
%6 = alloca i32
store i64 %0, i64* %3
store i64 %1, i64* %4
%7 = load i64, i64* %3
%8 = trunc i64 %7 to i32
%9 = shl i32 %8, 16
%10 = ashr i32 %9, 16
%11 = load i64, i64* %4
%12 = trunc i64 %11 to i32
%13 = ashr i32 %12, 16
%14 = add nsw i32 %10, %13
%15 = call i32 @__SSAT(i32 %14, i32 16)
%16 = and i32 %15, 65535
store i32 %16, i32* %5
%17 = load i64, i64* %3
%18 = trunc i64 %17 to i32
%19 = ashr i32 %18, 16
%20 = load i64, i64* %4
%21 = trunc i64 %20 to i32
%22 = shl i32 %21, 16
%23 = ashr i32 %22, 16
%24 = sub nsw i32 %19, %23
%25 = call i32 @__SSAT(i32 %24, i32 16)
%26 = and i32 %25, 65535
store i32 %26, i32* %6
%27 = load i32, i32* %6
%28 = shl i32 %27, 16
%29 = load i32, i32* %5
%30 = or i32 %28, %29
%31 = sext i32 %30 to i64
ret i64 %31
}

LLVM IR (-O2):
define i64 @__QSAX(i64 %0, i64 %1) {
%3 = trunc i64 %0 to i32
%4 = shl i32 %3, 16
%5 = ashr exact i32 %4, 16
%6 = trunc i64 %1 to i32
%7 = ashr i32 %6, 16
%8 = add nsw i32 %5, %7
%9 = tail call i32 @__SSAT(i32 %8, i32 16)
%10 = and i32 %9, 65535
%11 = ashr i32 %3, 16
%12 = shl i32 %6, 16
%13 = ashr exact i32 %12, 16
%14 = sub nsw i32 %11, %13
%15 = tail call i32 @__SSAT(i32 %14, i32 16)
%16 = shl i32 %15, 16
%17 = or i32 %16, %10
%18 = sext i32 %17 to i64
ret i64 %18
}