#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 floor(double);
int /*<<< orphan*/ sprintf(char *, char *, double);
double roundc(double a, int digit) {
  double b = 1.0;
  int i;
  double c;
  char s[10];
  for (i = 1; i < digit; i++) {
    b *= 10.0;
  }
  c = a * b + 0.5;
  sprintf(s, "%5.1f\n", c);
  return floor(c) / b;
}


x86 assembly (clang, -O0):
<roundc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %edi,-0xc(%rbp)
movsd  0xec8(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1170 <roundc+0x50>
movsd  0xeb8(%rip),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1144 <roundc+0x24>
movsd  -0x8(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe82(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
lea    -0x32(%rbp),%rdi
movsd  -0x28(%rbp),%xmm0
lea    0xe79(%rip),%rsi
call   1030 <sprintf@plt>
movsd  -0x28(%rbp),%xmm0
call   1040 <floor@plt>
divsd  -0x18(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<roundc>:
sub    $0x28,%rsp
cmp    $0x2,%edi
jl     1143 <roundc+0x23>
lea    -0x1(%rdi),%ecx
add    $0xfffffffe,%edi
mov    %ecx,%eax
and    $0x7,%eax
cmp    $0x7,%edi
jae    114d <roundc+0x2d>
movsd  0xebf(%rip),%xmm2
jmp    1185 <roundc+0x65>
movsd  0xeb5(%rip),%xmm2
jmp    11a9 <roundc+0x89>
and    $0xfffffff8,%ecx
movsd  0xea8(%rip),%xmm2
movsd  0xea8(%rip),%xmm1
mulsd  %xmm1,%xmm2
mulsd  %xmm1,%xmm2
mulsd  %xmm1,%xmm2
mulsd  %xmm1,%xmm2
mulsd  %xmm1,%xmm2
mulsd  %xmm1,%xmm2
mulsd  %xmm1,%xmm2
mulsd  %xmm1,%xmm2
add    $0xfffffff8,%ecx
jne    1160 <roundc+0x40>
test   %eax,%eax
je     11a9 <roundc+0x89>
movsd  0xe77(%rip),%xmm1
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mulsd  %xmm1,%xmm2
add    $0xffffffff,%eax
jne    11a0 <roundc+0x80>
movsd  %xmm2,0x10(%rsp)
mulsd  %xmm2,%xmm0
addsd  0xe55(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
lea    0xe50(%rip),%rsi
lea    0x1e(%rsp),%rdi
call   1030 <sprintf@plt>
movsd  0x8(%rsp),%xmm0
call   1040 <floor@plt>
divsd  0x10(%rsp),%xmm0
add    $0x28,%rsp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"%5.1f\0A\00"
define double @roundc(double %0, i32 %1) {
%3 = alloca double
%4 = alloca i32
%5 = alloca double
%6 = alloca i32
%7 = alloca double
%8 = alloca [10 x i8]
store double %0, double* %3
store i32 %1, i32* %4
store double 1.000000e+00, double* %5
store i32 1, i32* %6
br label %9
9: ; preds = %16, %2
%10 = load i32, i32* %6
%11 = load i32, i32* %4
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %19
13: ; preds = %9
%14 = load double, double* %5
%15 = fmul double %14, 1.000000e+01
store double %15, double* %5
br label %16
16: ; preds = %13
%17 = load i32, i32* %6
%18 = add nsw i32 %17, 1
store i32 %18, i32* %6
br label %9
19: ; preds = %9
%20 = load double, double* %3
%21 = load double, double* %5
%22 = call double @llvm.fmuladd.f64(double %20, double %21, double 5.000000e-01)
store double %22, double* %7
%23 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 0
%24 = load double, double* %7
%25 = call i32 @sprintf(i8* %23, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), double %24)
%26 = load double, double* %7
%27 = call double @llvm.floor.f64(double %26)
%28 = load double, double* %5
%29 = fdiv double %27, %28
ret double %29
}

LLVM IR (-O2):
@.str = [7 x i8] c"%5.1f\0A\00"
define double @roundc(double %0, i32 %1) {
%3 = alloca [10 x i8]
%4 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%5 = icmp sgt i32 %1, 1
br i1 %5, label %6, label %36
6: ; preds = %2
%7 = add i32 %1, -1
%8 = add i32 %1, -2
%9 = and i32 %7, 7
%10 = icmp ult i32 %8, 7
br i1 %10, label %26, label %11
11: ; preds = %6
%12 = and i32 %7, -8
br label %13
13: ; preds = %13, %11
%14 = phi double [ 1.000000e+00, %11 ], [ %23, %13 ]
%15 = phi i32 [ 0, %11 ], [ %24, %13 ]
%16 = fmul double %14, 1.000000e+01
%17 = fmul double %16, 1.000000e+01
%18 = fmul double %17, 1.000000e+01
%19 = fmul double %18, 1.000000e+01
%20 = fmul double %19, 1.000000e+01
%21 = fmul double %20, 1.000000e+01
%22 = fmul double %21, 1.000000e+01
%23 = fmul double %22, 1.000000e+01
%24 = add i32 %15, 8
%25 = icmp eq i32 %24, %12
br i1 %25, label %26, label %13
26: ; preds = %13, %6
%27 = phi double [ undef, %6 ], [ %23, %13 ]
%28 = phi double [ 1.000000e+00, %6 ], [ %23, %13 ]
%29 = icmp eq i32 %9, 0
br i1 %29, label %36, label %30
30: ; preds = %26, %30
%31 = phi double [ %33, %30 ], [ %28, %26 ]
%32 = phi i32 [ %34, %30 ], [ 0, %26 ]
%33 = fmul double %31, 1.000000e+01
%34 = add i32 %32, 1
%35 = icmp eq i32 %34, %9
br i1 %35, label %36, label %30
36: ; preds = %26, %30, %2
%37 = phi double [ 1.000000e+00, %2 ], [ %27, %26 ], [ %33, %30 ]
%38 = tail call double @llvm.fmuladd.f64(double %0, double %37, double 5.000000e-01)
%39 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), double %38)
%40 = tail call double @llvm.floor.f64(double %38)
%41 = fdiv double %40, %37
ret double %41
}