#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 */
float pow(int, int);
float round_f(float f, int d) {
  int temp = (int)(f * pow(10, d));
  if (temp % 10 >= 5)
    temp = temp + (10 - (temp % 10));
  return temp / ((float)pow(10, d));
}


x86 assembly (clang, -O0):
<round_f>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movss  %xmm0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
movss  -0x4(%rbp),%xmm0
movss  %xmm0,-0x10(%rbp)
mov    -0x8(%rbp),%esi
mov    $0xa,%edi
call   1030 <pow@plt>
movaps %xmm0,%xmm1
movss  -0x10(%rbp),%xmm0
mulss  %xmm1,%xmm0
cvttss2si %xmm0,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
cmp    $0x5,%edx
jl     117e <round_f+0x6e>
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    -0x14(%rbp),%eax
mov    $0xa,%ecx
sub    %edx,%ecx
add    %ecx,%eax
mov    %eax,-0xc(%rbp)
cvtsi2ssl -0xc(%rbp),%xmm0
movss  %xmm0,-0x18(%rbp)
mov    -0x8(%rbp),%esi
mov    $0xa,%edi
call   1030 <pow@plt>
movaps %xmm0,%xmm1
movss  -0x18(%rbp),%xmm0
divss  %xmm1,%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<round_f>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
movss  %xmm0,0x4(%rsp)
mov    $0xa,%ebp
mov    $0xa,%edi
mov    %ebx,%esi
call   1030 <pow@plt>
mulss  0x4(%rsp),%xmm0
cvttss2si %xmm0,%eax
cltq
imul   $0x66666667,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x22,%rcx
add    %edx,%ecx
add    %ecx,%ecx
lea    (%rcx,%rcx,4),%ecx
mov    %eax,%edx
sub    %ecx,%edx
sub    %edx,%ebp
xor    %ecx,%ecx
cmp    $0x5,%edx
cmovge %ebp,%ecx
add    %eax,%ecx
xorps  %xmm0,%xmm0
cvtsi2ss %ecx,%xmm0
movss  %xmm0,0x4(%rsp)
mov    $0xa,%edi
mov    %ebx,%esi
call   1030 <pow@plt>
movss  0x4(%rsp),%xmm1
divss  %xmm0,%xmm1
movaps %xmm1,%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define float @round_f(float %0, i32 %1) {
%3 = alloca float
%4 = alloca i32
%5 = alloca i32
store float %0, float* %3
store i32 %1, i32* %4
%6 = load float, float* %3
%7 = load i32, i32* %4
%8 = call float @pow(i32 10, i32 %7)
%9 = fmul float %6, %8
%10 = fptosi float %9 to i32
store i32 %10, i32* %5
%11 = load i32, i32* %5
%12 = srem i32 %11, 10
%13 = icmp sge i32 %12, 5
br i1 %13, label %14, label %20
14: ; preds = %2
%15 = load i32, i32* %5
%16 = load i32, i32* %5
%17 = srem i32 %16, 10
%18 = sub nsw i32 10, %17
%19 = add nsw i32 %15, %18
store i32 %19, i32* %5
br label %20
20: ; preds = %14, %2
%21 = load i32, i32* %5
%22 = sitofp i32 %21 to float
%23 = load i32, i32* %4
%24 = call float @pow(i32 10, i32 %23)
%25 = fdiv float %22, %24
ret float %25
}

LLVM IR (-O2):
define float @round_f(float %0, i32 %1) {
%3 = tail call float @pow(i32 10, i32 %1)
%4 = fmul float %3, %0
%5 = fptosi float %4 to i32
%6 = srem i32 %5, 10
%7 = icmp sgt i32 %6, 4
%8 = sub nsw i32 10, %6
%9 = select i1 %7, i32 %8, i32 0
%10 = add nsw i32 %9, %5
%11 = sitofp i32 %10 to float
%12 = tail call float @pow(i32 10, i32 %1)
%13 = fdiv float %11, %12
ret float %13
}