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

/* Variables and functions */
int _FPU_DEFAULT;
#define _FPU_RC_DOWN 131
#define _FPU_RC_NEAREST 130
#define _FPU_RC_UP 129
#define _FPU_RC_ZERO 128
int __fpu_control;
unsigned long rdfpcr();
int /*<<< orphan*/ wrfpcr(unsigned long);
void __setfpucw(fpu_control_t fpu_control) {
  unsigned long fpcr;
  if (!fpu_control)
    fpu_control = _FPU_DEFAULT;
  fpcr = rdfpcr();
  fpcr &= ~(0x3UL << 58);
  switch (fpu_control & 0xc00) {
  case _FPU_RC_NEAREST:
    fpcr |= (0x2UL << 58);
    break;
  case _FPU_RC_DOWN:
    fpcr |= (0x1UL << 58);
    break;
  case _FPU_RC_UP:
    fpcr |= (0x3UL << 58);
    break;
  case _FPU_RC_ZERO:
    fpcr |= (0x0UL << 58);
    break;
  }
  wrfpcr(fpcr);
  __fpu_control = fpu_control;
}


x86 assembly (clang, -O0):
<__setfpucw>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jne    1141 <__setfpucw+0x21>
mov    0x2eac(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
xor    %eax,%eax
call   1040 <rdfpcr@plt>
mov    %rax,-0x10(%rbp)
mov    -0x9(%rbp),%al
and    $0xf3,%al
mov    %al,-0x9(%rbp)
mov    -0x4(%rbp),%eax
and    $0xc00,%eax
add    $0xffffff80,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x3,%eax
ja     11d3 <__setfpucw+0xb3>
mov    -0x18(%rbp),%rax
lea    0xe87(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movabs $0x800000000000000,%rax
or     -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
jmp    11d3 <__setfpucw+0xb3>
movabs $0x400000000000000,%rax
or     -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
jmp    11d3 <__setfpucw+0xb3>
movabs $0xc00000000000000,%rax
or     -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
jmp    11d3 <__setfpucw+0xb3>
mov    -0x10(%rbp),%rax
or     $0x0,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <wrfpcr@plt>
mov    -0x4(%rbp),%ecx
mov    0x2df2(%rip),%rax
mov    %ecx,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__setfpucw>:
push   %rbx
mov    %edi,%ebx
test   %edi,%edi
jne    1130 <__setfpucw+0x10>
mov    0x2eba(%rip),%rax
mov    (%rax),%ebx
xor    %eax,%eax
call   1040 <rdfpcr@plt>
movabs $0xf3ffffffffffffff,%rdi
ff ff f3
and    %rax,%rdi
call   1030 <wrfpcr@plt>
mov    0x2e88(%rip),%rax
mov    %ebx,(%rax)
pop    %rbx
ret

LLVM IR (-O0):
@_FPU_DEFAULT = global i32 0
@__fpu_control = global i32 0
define void @__setfpucw(i32 %0) {
%2 = alloca i32
%3 = alloca i64
store i32 %0, i32* %2
%4 = load i32, i32* %2
%5 = icmp ne i32 %4, 0
br i1 %5, label %8, label %6
6: ; preds = %1
%7 = load i32, i32* @_FPU_DEFAULT
store i32 %7, i32* %2
br label %8
8: ; preds = %6, %1
%9 = call i64 (...) @rdfpcr()
store i64 %9, i64* %3
%10 = load i64, i64* %3
%11 = and i64 %10, -864691128455135233
store i64 %11, i64* %3
%12 = load i32, i32* %2
%13 = and i32 %12, 3072
switch i32 %13, label %26 [
i32 130, label %14
i32 131, label %17
i32 129, label %20
i32 128, label %23
]
14: ; preds = %8
%15 = load i64, i64* %3
%16 = or i64 %15, 576460752303423488
store i64 %16, i64* %3
br label %26
17: ; preds = %8
%18 = load i64, i64* %3
%19 = or i64 %18, 288230376151711744
store i64 %19, i64* %3
br label %26
20: ; preds = %8
%21 = load i64, i64* %3
%22 = or i64 %21, 864691128455135232
store i64 %22, i64* %3
br label %26
23: ; preds = %8
%24 = load i64, i64* %3
%25 = or i64 %24, 0
store i64 %25, i64* %3
br label %26
26: ; preds = %8, %23, %20, %17, %14
%27 = load i64, i64* %3
%28 = call i32 @wrfpcr(i64 %27)
%29 = load i32, i32* %2
store i32 %29, i32* @__fpu_control
ret void
}

LLVM IR (-O2):
@_FPU_DEFAULT = global i32 0
@__fpu_control = global i32 0
define void @__setfpucw(i32 %0) {
%2 = icmp eq i32 %0, 0
%3 = load i32, i32* @_FPU_DEFAULT
%4 = select i1 %2, i32 %3, i32 %0
%5 = tail call i64 (...) @rdfpcr()
%6 = and i64 %5, -864691128455135233
%7 = tail call i32 @wrfpcr(i64 %6)
store i32 %4, i32* @__fpu_control
ret void
}