#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 */

/* Variables and functions */
long double fabsd(long double);
long double fclipd(long double max_val, long double x) {
  long double abs_max_val, abs_x;
  abs_max_val = fabsd(max_val);
  abs_x = fabsd(x);
  if (abs_max_val < abs_x) {
    return max_val;
  } else {
    return (max_val < 0 ? -abs_x : abs_x);
  }
}


x86 assembly (clang, -O0):
<fclipd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
fldt   0x20(%rbp)
fldt   0x10(%rbp)
fstpt  -0x20(%rbp)
fstpt  -0x30(%rbp)
fldt   -0x20(%rbp)
mov    %rsp,%rax
fstpt  (%rax)
call   1030 <fabsd@plt>
fstpt  -0x40(%rbp)
fldt   -0x30(%rbp)
mov    %rsp,%rax
fstpt  (%rax)
call   1030 <fabsd@plt>
fstpt  -0x50(%rbp)
fldt   -0x40(%rbp)
fldt   -0x50(%rbp)
fucomip %st(1),%st
fstp   %st(0)
jbe    1164 <fclipd+0x54>
jmp    1159 <fclipd+0x49>
fldt   -0x20(%rbp)
fstpt  -0x10(%rbp)
jmp    1191 <fclipd+0x81>
fldt   -0x20(%rbp)
fldz
fucomip %st(1),%st
fstp   %st(0)
jbe    1185 <fclipd+0x75>
jmp    1178 <fclipd+0x68>
fldt   -0x50(%rbp)
fchs
fstpt  -0x5c(%rbp)
jmp    118b <fclipd+0x7b>
fldt   -0x50(%rbp)
fstpt  -0x5c(%rbp)
fldt   -0x5c(%rbp)
fstpt  -0x10(%rbp)
fldt   -0x10(%rbp)
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fclipd>:
sub    $0x38,%rsp
fldt   0x50(%rsp)
fstpt  0x20(%rsp)
fldt   0x40(%rsp)
fld    %st(0)
fstpt  0x14(%rsp)
fstpt  (%rsp)
call   1030 <fabsd@plt>
fstpt  0x2c(%rsp)
fldt   0x20(%rsp)
fstpt  (%rsp)
call   1030 <fabsd@plt>
fldz
fldt   0x14(%rsp)
fxch   %st(1)
fucomip %st(1),%st
fld    %st(1)
fchs
fld    %st(2)
fcmovnbe %st(1),%st
fstp   %st(1)
fldt   0x2c(%rsp)
fxch   %st(3)
fucomip %st(3),%st
fstp   %st(2)
fxch   %st(1)
fcmovnbe %st(1),%st
fstp   %st(1)
add    $0x38,%rsp
ret

LLVM IR (-O0):
define x86_fp80 @fclipd(x86_fp80 %0, x86_fp80 %1) {
%3 = alloca x86_fp80
%4 = alloca x86_fp80
%5 = alloca x86_fp80
%6 = alloca x86_fp80
%7 = alloca x86_fp80
store x86_fp80 %0, x86_fp80* %4
store x86_fp80 %1, x86_fp80* %5
%8 = load x86_fp80, x86_fp80* %4
%9 = call x86_fp80 @fabsd(x86_fp80 %8)
store x86_fp80 %9, x86_fp80* %6
%10 = load x86_fp80, x86_fp80* %5
%11 = call x86_fp80 @fabsd(x86_fp80 %10)
store x86_fp80 %11, x86_fp80* %7
%12 = load x86_fp80, x86_fp80* %6
%13 = load x86_fp80, x86_fp80* %7
%14 = fcmp olt x86_fp80 %12, %13
br i1 %14, label %15, label %17
15: ; preds = %2
%16 = load x86_fp80, x86_fp80* %4
store x86_fp80 %16, x86_fp80* %3
br label %27
17: ; preds = %2
%18 = load x86_fp80, x86_fp80* %4
%19 = fcmp olt x86_fp80 %18, 0xK00000000000000000000
br i1 %19, label %20, label %23
20: ; preds = %17
%21 = load x86_fp80, x86_fp80* %7
%22 = fneg x86_fp80 %21
br label %25
23: ; preds = %17
%24 = load x86_fp80, x86_fp80* %7
br label %25
25: ; preds = %23, %20
%26 = phi x86_fp80 [ %22, %20 ], [ %24, %23 ]
store x86_fp80 %26, x86_fp80* %3
br label %27
27: ; preds = %25, %15
%28 = load x86_fp80, x86_fp80* %3
ret x86_fp80 %28
}

LLVM IR (-O2):
define x86_fp80 @fclipd(x86_fp80 %0, x86_fp80 %1) {
%3 = tail call x86_fp80 @fabsd(x86_fp80 %0)
%4 = tail call x86_fp80 @fabsd(x86_fp80 %1)
%5 = fcmp olt x86_fp80 %3, %4
%6 = fcmp olt x86_fp80 %0, 0xK00000000000000000000
%7 = fneg x86_fp80 %4
%8 = select i1 %6, x86_fp80 %7, x86_fp80 %4
%9 = select i1 %5, x86_fp80 %0, x86_fp80 %8
ret x86_fp80 %9
}