#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);
double log10(double);
int myrint(double);
int pow(int, double);
double arrondi_echelle(double x) {
  double l, n;
  int r;
  static int corresp[] = {1, 1, 2, 2, 5, 5, 5, 10, 10, 10, 10, 10};
  l = log10(x);
  n = floor(l);
  l = x * pow(10, -n);
  r = myrint(l);
  r = corresp[r];
  return r * pow(10, n);
}


x86 assembly (clang, -O0):
<arrondi_echelle>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1050 <log10@plt>
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1060 <floor@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x18(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mov    $0xa,%edi
call   1040 <pow@plt>
movsd  -0x28(%rbp),%xmm0
cvtsi2sd %eax,%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1030 <myrint@plt>
mov    %eax,-0x1c(%rbp)
movslq -0x1c(%rbp),%rcx
lea    0x2e8b(%rip),%rax
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm0
mov    $0xa,%edi
call   1040 <pow@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
imul   %ecx,%eax
cvtsi2sd %eax,%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<arrondi_echelle>:
push   %r14
push   %rbx
sub    $0x28,%rsp
movsd  %xmm0,0x8(%rsp)
call   1050 <log10@plt>
call   1060 <floor@plt>
movaps %xmm0,%xmm1
movaps %xmm0,0x10(%rsp)
movaps 0xe9a(%rip),%xmm0
xorps  %xmm1,%xmm0
mov    $0xa,%edi
call   1040 <pow@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  0x8(%rsp),%xmm0
call   1030 <myrint@plt>
movslq %eax,%rbx
lea    0xe81(%rip),%r14
mov    $0xa,%edi
movaps 0x10(%rsp),%xmm0
call   1040 <pow@plt>
imul   (%r14,%rbx,4),%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@arrondi_echelle.corresp = internal global [12 x i32] [i32 1, i32 1, i32 2, i32 2, i32 5, i32 5, i32 5, i32 10, i32 10, i32 10, i32 10, i32 10]
define double @arrondi_echelle(double %0) {
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca i32
store double %0, double* %2
%6 = load double, double* %2
%7 = call double @log10(double %6)
store double %7, double* %3
%8 = load double, double* %3
%9 = call double @llvm.floor.f64(double %8)
store double %9, double* %4
%10 = load double, double* %2
%11 = load double, double* %4
%12 = fneg double %11
%13 = call i32 @pow(i32 10, double %12)
%14 = sitofp i32 %13 to double
%15 = fmul double %10, %14
store double %15, double* %3
%16 = load double, double* %3
%17 = call i32 @myrint(double %16)
store i32 %17, i32* %5
%18 = load i32, i32* %5
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [12 x i32], [12 x i32]* @arrondi_echelle.corresp, i64 0, i64 %19
%21 = load i32, i32* %20
store i32 %21, i32* %5
%22 = load i32, i32* %5
%23 = load double, double* %4
%24 = call i32 @pow(i32 10, double %23)
%25 = mul nsw i32 %22, %24
%26 = sitofp i32 %25 to double
ret double %26
}

LLVM IR (-O2):
@arrondi_echelle.corresp = internal unnamed_addr constant [12 x i32] [i32 1, i32 1, i32 2, i32 2, i32 5, i32 5, i32 5, i32 10, i32 10, i32 10, i32 10, i32 10]
define double @arrondi_echelle(double %0) {
%2 = tail call double @log10(double %0)
%3 = tail call double @llvm.floor.f64(double %2)
%4 = fneg double %3
%5 = tail call i32 @pow(i32 10, double %4)
%6 = sitofp i32 %5 to double
%7 = fmul double %6, %0
%8 = tail call i32 @myrint(double %7)
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds [12 x i32], [12 x i32]* @arrondi_echelle.corresp, i64 0, i64 %9
%11 = load i32, i32* %10
%12 = tail call i32 @pow(i32 10, double %3)
%13 = mul nsw i32 %12, %11
%14 = sitofp i32 %13 to double
ret double %14
}