#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 __QADD16(uint32_t x, uint32_t y) {
  int32_t r = 0, s = 0;
  r = __SSAT(((((int32_t)x << 16) >> 16) + (((int32_t)y << 16) >> 16)), 16) &
      (int32_t)0x0000FFFF;
  s = __SSAT(((((int32_t)x) >> 16) + (((int32_t)y) >> 16)), 16) &
      (int32_t)0x0000FFFF;
  return ((uint32_t)((s << 16) | (r)));
}


x86 assembly (clang, -O0):
<__QADD16>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %eax,%edi
shl    $0x10,%edi
sar    $0x10,%edi
mov    -0x10(%rbp),%rax
shl    $0x10,%eax
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
sar    $0x10,%eax
add    %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):
<__QADD16>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%r14
movswl %r14w,%eax
movswl %bx,%edi
add    %eax,%edi
mov    $0x10,%esi
call   1030 <__SSAT@plt>
movzwl %ax,%ebp
sar    $0x10,%r14d
sar    $0x10,%ebx
add    %r14d,%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 @__QADD16(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
store i32 0, i32* %5
store i32 0, i32* %6
%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 = shl i32 %12, 16
%14 = ashr i32 %13, 16
%15 = add nsw i32 %10, %14
%16 = call i32 @__SSAT(i32 %15, i32 16)
%17 = and i32 %16, 65535
store i32 %17, i32* %5
%18 = load i64, i64* %3
%19 = trunc i64 %18 to i32
%20 = ashr i32 %19, 16
%21 = load i64, i64* %4
%22 = trunc i64 %21 to i32
%23 = ashr i32 %22, 16
%24 = add nsw i32 %20, %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 @__QADD16(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 = shl i32 %6, 16
%8 = ashr exact i32 %7, 16
%9 = add nsw i32 %8, %5
%10 = tail call i32 @__SSAT(i32 %9, i32 16)
%11 = and i32 %10, 65535
%12 = ashr i32 %3, 16
%13 = ashr i32 %6, 16
%14 = add nsw i32 %13, %12
%15 = tail call i32 @__SSAT(i32 %14, i32 16)
%16 = shl i32 %15, 16
%17 = or i32 %16, %11
%18 = sext i32 %17 to i64
ret i64 %18
}