#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 uint32_t;
typedef int /*<<< orphan*/ int32_t;

/* Variables and functions */
int /*<<< orphan*/ ceil_w_d(double const *, int /*<<< orphan*/ *);
int /*<<< orphan*/ floor_w_d(double const *, int /*<<< orphan*/ *);
int /*<<< orphan*/ round_w_d(double const *, int /*<<< orphan*/ *);
int /*<<< orphan*/ trunc_w_d(double const *, int /*<<< orphan*/ *);
void cvt_w_d(const uint32_t *fcr31, const double *source, int32_t *dest) {
  switch (*fcr31 & 3) {
  case 0:
    round_w_d(source, dest);
    return;
  case 1:
    trunc_w_d(source, dest);
    return;
  case 2:
    ceil_w_d(source, dest);
    return;
  case 3:
    floor_w_d(source, dest);
    return;
  }
}


x86 assembly (clang, -O0):
<cvt_w_d>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
and    $0x3,%eax
mov    %rax,-0x20(%rbp)
sub    $0x3,%eax
ja     11c1 <cvt_w_d+0x81>
mov    -0x20(%rbp),%rax
lea    0xe8b(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <round_w_d@plt>
jmp    11c1 <cvt_w_d+0x81>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <trunc_w_d@plt>
jmp    11c1 <cvt_w_d+0x81>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <ceil_w_d@plt>
jmp    11c1 <cvt_w_d+0x81>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <floor_w_d@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cvt_w_d>:
mov    (%rdi),%eax
and    $0x3,%eax
lea    0xeb4(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    %rsi,%rdi
mov    %rdx,%rsi
jmp    1060 <round_w_d@plt>
mov    %rsi,%rdi
mov    %rdx,%rsi
jmp    1030 <ceil_w_d@plt>
mov    %rsi,%rdi
mov    %rdx,%rsi
jmp    1040 <floor_w_d@plt>
mov    %rsi,%rdi
mov    %rdx,%rsi
jmp    1050 <trunc_w_d@plt>

LLVM IR (-O0):
define void @cvt_w_d(i32* %0, double* %1, i32* %2) {
%4 = alloca i32*
%5 = alloca double*
%6 = alloca i32*
store i32* %0, i32** %4
store double* %1, double** %5
store i32* %2, i32** %6
%7 = load i32*, i32** %4
%8 = load i32, i32* %7
%9 = and i32 %8, 3
switch i32 %9, label %26 [
i32 0, label %10
i32 1, label %14
i32 2, label %18
i32 3, label %22
]
10: ; preds = %3
%11 = load double*, double** %5
%12 = load i32*, i32** %6
%13 = call i32 @round_w_d(double* %11, i32* %12)
br label %26
14: ; preds = %3
%15 = load double*, double** %5
%16 = load i32*, i32** %6
%17 = call i32 @trunc_w_d(double* %15, i32* %16)
br label %26
18: ; preds = %3
%19 = load double*, double** %5
%20 = load i32*, i32** %6
%21 = call i32 @ceil_w_d(double* %19, i32* %20)
br label %26
22: ; preds = %3
%23 = load double*, double** %5
%24 = load i32*, i32** %6
%25 = call i32 @floor_w_d(double* %23, i32* %24)
br label %26
26: ; preds = %10, %14, %18, %22, %3
ret void
}

LLVM IR (-O2):
define void @cvt_w_d(i32* nocapture %0, double* %1, i32* %2) {
%4 = load i32, i32* %0
%5 = and i32 %4, 3
switch i32 %5, label %14 [
i32 0, label %6
i32 1, label %8
i32 2, label %10
i32 3, label %12
]
6: ; preds = %3
%7 = tail call i32 @round_w_d(double* %1, i32* %2)
br label %15
8: ; preds = %3
%9 = tail call i32 @trunc_w_d(double* %1, i32* %2)
br label %15
10: ; preds = %3
%11 = tail call i32 @ceil_w_d(double* %1, i32* %2)
br label %15
12: ; preds = %3
%13 = tail call i32 @floor_w_d(double* %1, i32* %2)
br label %15
14: ; preds = %3
unreachable
15: ; preds = %6, %8, %10, %12
ret void
}