#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 */
scalar_t__ fabs(double);
double floor(scalar_t__);
double pow(double, double);
double Round(double n, int p) {
  double r;
  r = pow(10.0, (double)p);
  r = floor(.5 + fabs(n * r)) / r;
  if (n < 0.0)
    return (-r);
  return (r);
}


x86 assembly (clang, -O0):
<Round>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x10(%rbp)
mov    %edi,-0x14(%rbp)
cvtsi2sdl -0x14(%rbp),%xmm1
movsd  0xebb(%rip),%xmm0
call   1040 <pow@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
mulsd  -0x20(%rbp),%xmm0
call   1030 <fabs@plt>
cvtsi2sd %rax,%xmm1
movsd  0xe8d(%rip),%xmm0
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rdi
call   1050 <floor@plt>
divsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    11bf <Round+0x8f>
movsd  -0x20(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11c9 <Round+0x99>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Round>:
sub    $0x28,%rsp
movaps %xmm0,0x10(%rsp)
cvtsi2sd %edi,%xmm1
movsd  0xebb(%rip),%xmm0
call   1040 <pow@plt>
movsd  %xmm0,0x8(%rsp)
mulsd  0x10(%rsp),%xmm0
call   1030 <fabs@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
addsd  0xe9d(%rip),%xmm0
cvttsd2si %xmm0,%rdi
call   1050 <floor@plt>
divsd  0x8(%rsp),%xmm0
movapd 0xe8d(%rip),%xmm1
xorpd  %xmm0,%xmm1
xorpd  %xmm2,%xmm2
movapd 0x10(%rsp),%xmm3
cmpltsd %xmm2,%xmm3
movapd %xmm3,%xmm2
andnpd %xmm0,%xmm2
andpd  %xmm1,%xmm3
orpd   %xmm2,%xmm3
movapd %xmm3,%xmm0
add    $0x28,%rsp
ret

LLVM IR (-O0):
define double @Round(double %0, i32 %1) {
%3 = alloca double
%4 = alloca double
%5 = alloca i32
%6 = alloca double
store double %0, double* %4
store i32 %1, i32* %5
%7 = load i32, i32* %5
%8 = sitofp i32 %7 to double
%9 = call double @pow(double 1.000000e+01, double %8)
store double %9, double* %6
%10 = load double, double* %4
%11 = load double, double* %6
%12 = fmul double %10, %11
%13 = call i64 @fabs(double %12)
%14 = sitofp i64 %13 to double
%15 = fadd double 5.000000e-01, %14
%16 = fptosi double %15 to i64
%17 = call double @floor(i64 %16)
%18 = load double, double* %6
%19 = fdiv double %17, %18
store double %19, double* %6
%20 = load double, double* %4
%21 = fcmp olt double %20, 0.000000e+00
br i1 %21, label %22, label %25
22: ; preds = %2
%23 = load double, double* %6
%24 = fneg double %23
store double %24, double* %3
br label %27
25: ; preds = %2
%26 = load double, double* %6
store double %26, double* %3
br label %27
27: ; preds = %25, %22
%28 = load double, double* %3
ret double %28
}

LLVM IR (-O2):
define double @Round(double %0, i32 %1) {
%3 = sitofp i32 %1 to double
%4 = tail call double @pow(double 1.000000e+01, double %3)
%5 = fmul double %4, %0
%6 = tail call i64 @fabs(double %5)
%7 = sitofp i64 %6 to double
%8 = fadd double %7, 5.000000e-01
%9 = fptosi double %8 to i64
%10 = tail call double @floor(i64 %9)
%11 = fdiv double %10, %4
%12 = fcmp olt double %0, 0.000000e+00
%13 = fneg double %11
%14 = select i1 %12, double %13, double %11
ret double %14
}