#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 */
double DBL_EPSILON;
int FE_DOWNWARD;
int FE_TONEAREST;
int FE_TOWARDZERO;
int FE_UPWARD;
double copysign(double, double volatile);
int getround(void) {
  volatile double d;
  d = 1.0;
  d -= 1.0;
  if (copysign(1.0, d) < 0.0)
    return (FE_DOWNWARD);
  d = 1.0;
  if (d + (DBL_EPSILON * 3.0 / 4.0) == 1.0)
    return (FE_TOWARDZERO);
  if (d + (DBL_EPSILON * 1.0 / 4.0) > 1.0)
    return (FE_UPWARD);
  return (FE_TONEAREST);
}


x86 assembly (clang, -O0):
<getround>:
push   %rbp
mov    %rsp,%rbp
movsd  0xf14(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xf02(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm1
movaps 0xecd(%rip),%xmm0
pand   %xmm0,%xmm1
movaps 0xed2(%rip),%xmm0
por    %xmm0,%xmm1
xorps  %xmm0,%xmm0
ucomisd %xmm1,%xmm0
jbe    1160 <getround+0x60>
mov    0x2e7a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1215 <getround+0x115>
movsd  0xeb8(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xeb6(%rip),%xmm1
mov    0x2e5f(%rip),%rax
mulsd  (%rax),%xmm1
movsd  0xe9b(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  0xe83(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    11be <getround+0xbe>
jp     11be <getround+0xbe>
mov    0x2e34(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1215 <getround+0x115>
movsd  -0x10(%rbp),%xmm0
movsd  0xe55(%rip),%xmm1
mov    0x2e0e(%rip),%rax
mulsd  (%rax),%xmm1
movsd  0xe4a(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  0xe32(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1209 <getround+0x109>
mov    0x2dc1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1215 <getround+0x115>
mov    0x2dc8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<getround>:
movabs $0x3ff0000000000000,%rax
mov    %rax,-0x8(%rsp)
movsd  -0x8(%rsp),%xmm0
addsd  0xee3(%rip),%xmm0
movsd  %xmm0,-0x8(%rsp)
cmpq   $0x0,-0x8(%rsp)
js     116b <getround+0x6b>
mov    %rax,-0x8(%rsp)
mov    0x2ea9(%rip),%rax
movsd  (%rax),%xmm0
movsd  0xec5(%rip),%xmm1
mulsd  %xmm0,%xmm1
mulsd  0xec1(%rip),%xmm1
addsd  -0x8(%rsp),%xmm1
ucomisd 0xebb(%rip),%xmm1
jne    1175 <getround+0x75>
jp     1175 <getround+0x75>
mov    0x2e80(%rip),%rax
mov    (%rax),%eax
ret
mov    0x2e5e(%rip),%rax
mov    (%rax),%eax
ret
mulsd  0xe93(%rip),%xmm0
addsd  -0x8(%rsp),%xmm0
ucomisd 0xe8d(%rip),%xmm0
jbe    1197 <getround+0x97>
mov    0x2e2c(%rip),%rax
mov    (%rax),%eax
ret
mov    0x2e3a(%rip),%rax
mov    (%rax),%eax
ret

LLVM IR (-O0):
@FE_DOWNWARD = global i32 0
@DBL_EPSILON = global double 0.000000e+00
@FE_TOWARDZERO = global i32 0
@FE_UPWARD = global i32 0
@FE_TONEAREST = global i32 0
define i32 @getround() {
%1 = alloca i32
%2 = alloca double
store volatile double 1.000000e+00, double* %2
%3 = load volatile double, double* %2
%4 = fsub double %3, 1.000000e+00
store volatile double %4, double* %2
%5 = load volatile double, double* %2
%6 = call double @llvm.copysign.f64(double 1.000000e+00, double %5)
%7 = fcmp olt double %6, 0.000000e+00
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = load i32, i32* @FE_DOWNWARD
store i32 %9, i32* %1
br label %30
10: ; preds = %0
store volatile double 1.000000e+00, double* %2
%11 = load volatile double, double* %2
%12 = load double, double* @DBL_EPSILON
%13 = fmul double %12, 3.000000e+00
%14 = fdiv double %13, 4.000000e+00
%15 = fadd double %11, %14
%16 = fcmp oeq double %15, 1.000000e+00
br i1 %16, label %17, label %19
17: ; preds = %10
%18 = load i32, i32* @FE_TOWARDZERO
store i32 %18, i32* %1
br label %30
19: ; preds = %10
%20 = load volatile double, double* %2
%21 = load double, double* @DBL_EPSILON
%22 = fmul double %21, 1.000000e+00
%23 = fdiv double %22, 4.000000e+00
%24 = fadd double %20, %23
%25 = fcmp ogt double %24, 1.000000e+00
br i1 %25, label %26, label %28
26: ; preds = %19
%27 = load i32, i32* @FE_UPWARD
store i32 %27, i32* %1
br label %30
28: ; preds = %19
%29 = load i32, i32* @FE_TONEAREST
store i32 %29, i32* %1
br label %30
30: ; preds = %28, %26, %17, %8
%31 = load i32, i32* %1
ret i32 %31
}

LLVM IR (-O2):
@FE_DOWNWARD = global i32 0
@DBL_EPSILON = global double 0.000000e+00
@FE_TOWARDZERO = global i32 0
@FE_UPWARD = global i32 0
@FE_TONEAREST = global i32 0
define i32 @getround() {
%1 = alloca double
%2 = bitcast double* %1 to i8*
store volatile double 1.000000e+00, double* %1
%3 = load volatile double, double* %1
%4 = fadd double %3, -1.000000e+00
store volatile double %4, double* %1
%5 = load volatile double, double* %1
%6 = bitcast double %5 to i64
%7 = icmp slt i64 %6, 0
br i1 %7, label %21, label %8
8: ; preds = %0
store volatile double 1.000000e+00, double* %1
%9 = load volatile double, double* %1
%10 = load double, double* @DBL_EPSILON
%11 = fmul double %10, 3.000000e+00
%12 = fmul double %11, 2.500000e-01
%13 = fadd double %9, %12
%14 = fcmp oeq double %13, 1.000000e+00
br i1 %14, label %21, label %15
15: ; preds = %8
%16 = load volatile double, double* %1
%17 = fmul double %10, 2.500000e-01
%18 = fadd double %17, %16
%19 = fcmp ogt double %18, 1.000000e+00
%20 = select i1 %19, i32* @FE_UPWARD, i32* @FE_TONEAREST
br label %21
21: ; preds = %15, %8, %0
%22 = phi i32* [ @FE_DOWNWARD, %0 ], [ @FE_TOWARDZERO, %8 ], [ %20, %15 ]
%23 = load i32, i32* %22
ret i32 %23
}