#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 */
int pow(int, int);
double round2(double num, int precision) {
  double rnum = 0.0;
  int tnum;
  if (num == 0.0)
    return num;
  rnum = num * pow(10, precision);
  tnum = (int)(rnum < 0 ? rnum - 0.5 : rnum + 0.5);
  rnum = tnum / pow(10, precision);
  return rnum;
}


x86 assembly (clang, -O0):
<round2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x10(%rbp)
mov    %edi,-0x14(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    114f <round2+0x3f>
jp     114f <round2+0x3f>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11ed <round2+0xdd>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x14(%rbp),%esi
mov    $0xa,%edi
call   1030 <pow@plt>
movsd  -0x30(%rbp),%xmm0
cvtsi2sd %eax,%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x20(%rbp),%xmm0
jbe    11a1 <round2+0x91>
movsd  -0x20(%rbp),%xmm0
movsd  0xe6d(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
jmp    11b3 <round2+0xa3>
movsd  0xe57(%rip),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x14(%rbp),%esi
mov    $0xa,%edi
call   1030 <pow@plt>
mov    %eax,%ecx
mov    -0x3c(%rbp),%eax
cltd
idiv   %ecx
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<round2>:
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    111d <round2+0xd>
jp     111d <round2+0xd>
ret
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
mov    $0xa,%edi
mov    %ebx,%esi
movsd  %xmm0,(%rsp)
call   1030 <pow@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  (%rsp),%xmm0
xor    %eax,%eax
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
seta   %al
lea    0xead(%rip),%rcx
addsd  (%rcx,%rax,8),%xmm0
cvttsd2si %xmm0,%ebp
mov    $0xa,%edi
mov    %ebx,%esi
call   1030 <pow@plt>
mov    %eax,%ecx
mov    %ebp,%eax
cltd
idiv   %ecx
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define double @round2(double %0, i32 %1) {
%3 = alloca double
%4 = alloca double
%5 = alloca i32
%6 = alloca double
%7 = alloca i32
store double %0, double* %4
store i32 %1, i32* %5
store double 0.000000e+00, double* %6
%8 = load double, double* %4
%9 = fcmp oeq double %8, 0.000000e+00
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = load double, double* %4
store double %11, double* %3
br label %35
12: ; preds = %2
%13 = load double, double* %4
%14 = load i32, i32* %5
%15 = call i32 @pow(i32 10, i32 %14)
%16 = sitofp i32 %15 to double
%17 = fmul double %13, %16
store double %17, double* %6
%18 = load double, double* %6
%19 = fcmp olt double %18, 0.000000e+00
br i1 %19, label %20, label %23
20: ; preds = %12
%21 = load double, double* %6
%22 = fsub double %21, 5.000000e-01
br label %26
23: ; preds = %12
%24 = load double, double* %6
%25 = fadd double %24, 5.000000e-01
br label %26
26: ; preds = %23, %20
%27 = phi double [ %22, %20 ], [ %25, %23 ]
%28 = fptosi double %27 to i32
store i32 %28, i32* %7
%29 = load i32, i32* %7
%30 = load i32, i32* %5
%31 = call i32 @pow(i32 10, i32 %30)
%32 = sdiv i32 %29, %31
%33 = sitofp i32 %32 to double
store double %33, double* %6
%34 = load double, double* %6
store double %34, double* %3
br label %35
35: ; preds = %26, %10
%36 = load double, double* %3
ret double %36
}

LLVM IR (-O2):
define double @round2(double %0, i32 %1) {
%3 = fcmp oeq double %0, 0.000000e+00
br i1 %3, label %15, label %4
4: ; preds = %2
%5 = tail call i32 @pow(i32 10, i32 %1)
%6 = sitofp i32 %5 to double
%7 = fmul double %6, %0
%8 = fcmp olt double %7, 0.000000e+00
%9 = select i1 %8, double -5.000000e-01, double 5.000000e-01
%10 = fadd double %7, %9
%11 = fptosi double %10 to i32
%12 = tail call i32 @pow(i32 10, i32 %1)
%13 = sdiv i32 %11, %12
%14 = sitofp i32 %13 to double
br label %15
15: ; preds = %2, %4
%16 = phi double [ %14, %4 ], [ %0, %2 ]
ret double %16
}