#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 pow(int, long);
double round(double);
double roundn(double f, long n) {
  double ret = f;
  if (n == 0) {
    ret = round(f);
  } else if (n > 0) {
    long tem = pow(10, n);
    f *= tem;
    ret = round(f);
    ret /= tem;
  }
  return ret;
}


x86 assembly (clang, -O0):
<roundn>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %rdi,-0x10(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    115a <roundn+0x3a>
movsd  -0x8(%rbp),%xmm0
call   1040 <round@plt>
movsd  %xmm0,-0x18(%rbp)
jmp    11af <roundn+0x8f>
cmpq   $0x0,-0x10(%rbp)
jle    11aa <roundn+0x8a>
mov    -0x10(%rbp),%rsi
mov    $0xa,%edi
call   1030 <pow@plt>
mov    %rax,-0x20(%rbp)
cvtsi2sdq -0x20(%rbp),%xmm0
mulsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1040 <round@plt>
movsd  %xmm0,-0x18(%rbp)
cvtsi2sdq -0x20(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    11af <roundn+0x8f>
movsd  -0x18(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<roundn>:
test   %rdi,%rdi
je     1163 <roundn+0x43>
jle    1162 <roundn+0x42>
sub    $0x18,%rsp
mov    %rdi,%rsi
mov    $0xa,%edi
movsd  %xmm0,0x8(%rsp)
call   1030 <pow@plt>
cvtsi2sd %rax,%xmm1
movsd  %xmm1,0x10(%rsp)
movsd  0x8(%rsp),%xmm0
mulsd  %xmm1,%xmm0
call   1040 <round@plt>
divsd  0x10(%rsp),%xmm0
add    $0x18,%rsp
ret
jmp    1040 <round@plt>

LLVM IR (-O0):
define double @roundn(double %0, i64 %1) {
%3 = alloca double
%4 = alloca i64
%5 = alloca double
%6 = alloca i64
store double %0, double* %3
store i64 %1, i64* %4
%7 = load double, double* %3
store double %7, double* %5
%8 = load i64, i64* %4
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = load double, double* %3
%12 = call double @llvm.round.f64(double %11)
store double %12, double* %5
br label %30
13: ; preds = %2
%14 = load i64, i64* %4
%15 = icmp sgt i64 %14, 0
br i1 %15, label %16, label %29
16: ; preds = %13
%17 = load i64, i64* %4
%18 = call i64 @pow(i32 10, i64 %17)
store i64 %18, i64* %6
%19 = load i64, i64* %6
%20 = sitofp i64 %19 to double
%21 = load double, double* %3
%22 = fmul double %21, %20
store double %22, double* %3
%23 = load double, double* %3
%24 = call double @llvm.round.f64(double %23)
store double %24, double* %5
%25 = load i64, i64* %6
%26 = sitofp i64 %25 to double
%27 = load double, double* %5
%28 = fdiv double %27, %26
store double %28, double* %5
br label %29
29: ; preds = %16, %13
br label %30
30: ; preds = %29, %10
%31 = load double, double* %5
ret double %31
}

LLVM IR (-O2):
define double @roundn(double %0, i64 %1) {
%3 = icmp eq i64 %1, 0
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call double @llvm.round.f64(double %0)
br label %14
6: ; preds = %2
%7 = icmp sgt i64 %1, 0
br i1 %7, label %8, label %14
8: ; preds = %6
%9 = tail call i64 @pow(i32 10, i64 %1)
%10 = sitofp i64 %9 to double
%11 = fmul double %10, %0
%12 = tail call double @llvm.round.f64(double %11)
%13 = fdiv double %12, %10
br label %14
14: ; preds = %6, %8, %4
%15 = phi double [ %5, %4 ], [ %13, %8 ], [ %0, %6 ]
ret double %15
}