#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 int32_t;

/* Variables and functions */
void prv_clamp_int16(int32_t *a, int32_t *b) {
  if (*a > 32767)
    *a = 32767;
  if (*a < -32768)
    *a = -32768;
  if (*b > 32767)
    *b = 32767;
  if (*b < -32768)
    *b = -32768;
}


x86 assembly (clang, -O0):
<prv_clamp_int16>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
cmpl   $0x7fff,(%rax)
jle    1126 <prv_clamp_int16+0x26>
mov    -0x8(%rbp),%rax
movl   $0x7fff,(%rax)
mov    -0x8(%rbp),%rax
cmpl   $0xffff8000,(%rax)
jge    1140 <prv_clamp_int16+0x40>
mov    -0x8(%rbp),%rax
movl   $0xffff8000,(%rax)
mov    -0x10(%rbp),%rax
cmpl   $0x7fff,(%rax)
jle    115a <prv_clamp_int16+0x5a>
mov    -0x10(%rbp),%rax
movl   $0x7fff,(%rax)
mov    -0x10(%rbp),%rax
cmpl   $0xffff8000,(%rax)
jge    1174 <prv_clamp_int16+0x74>
mov    -0x10(%rbp),%rax
movl   $0xffff8000,(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<prv_clamp_int16>:
mov    (%rdi),%ecx
mov    $0x7fff,%eax
cmp    $0x7fff,%ecx
jg     111c <prv_clamp_int16+0x1c>
mov    $0xffff8000,%eax
cmp    $0xffff7fff,%ecx
jg     111e <prv_clamp_int16+0x1e>
mov    %eax,(%rdi)
mov    (%rsi),%ecx
mov    $0x7fff,%eax
cmp    $0x7fff,%ecx
jg     113a <prv_clamp_int16+0x3a>
mov    $0xffff8000,%eax
cmp    $0xffff7fff,%ecx
jg     113c <prv_clamp_int16+0x3c>
mov    %eax,(%rsi)
ret

LLVM IR (-O0):
define void @prv_clamp_int16(i32* %0, i32* %1) {
%3 = alloca i32*
%4 = alloca i32*
store i32* %0, i32** %3
store i32* %1, i32** %4
%5 = load i32*, i32** %3
%6 = load i32, i32* %5
%7 = icmp sgt i32 %6, 32767
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = load i32*, i32** %3
store i32 32767, i32* %9
br label %10
10: ; preds = %8, %2
%11 = load i32*, i32** %3
%12 = load i32, i32* %11
%13 = icmp slt i32 %12, -32768
br i1 %13, label %14, label %16
14: ; preds = %10
%15 = load i32*, i32** %3
store i32 -32768, i32* %15
br label %16
16: ; preds = %14, %10
%17 = load i32*, i32** %4
%18 = load i32, i32* %17
%19 = icmp sgt i32 %18, 32767
br i1 %19, label %20, label %22
20: ; preds = %16
%21 = load i32*, i32** %4
store i32 32767, i32* %21
br label %22
22: ; preds = %20, %16
%23 = load i32*, i32** %4
%24 = load i32, i32* %23
%25 = icmp slt i32 %24, -32768
br i1 %25, label %26, label %28
26: ; preds = %22
%27 = load i32*, i32** %4
store i32 -32768, i32* %27
br label %28
28: ; preds = %26, %22
ret void
}

LLVM IR (-O2):
define void @prv_clamp_int16(i32* nocapture %0, i32* nocapture %1) {
%3 = load i32, i32* %0
%4 = icmp sgt i32 %3, 32767
br i1 %4, label %7, label %5
5: ; preds = %2
%6 = icmp slt i32 %3, -32768
br i1 %6, label %7, label %9
7: ; preds = %5, %2
%8 = phi i32 [ 32767, %2 ], [ -32768, %5 ]
store i32 %8, i32* %0
br label %9
9: ; preds = %7, %5
%10 = load i32, i32* %1
%11 = icmp sgt i32 %10, 32767
br i1 %11, label %14, label %12
12: ; preds = %9
%13 = icmp slt i32 %10, -32768
br i1 %13, label %14, label %16
14: ; preds = %12, %9
%15 = phi i32 [ 32767, %9 ], [ -32768, %12 ]
store i32 %15, i32* %1
br label %16
16: ; preds = %14, %12
ret void
}