void round2csd(a, b, n, cprec, csdprec, bincode, csdcode, csdcoder) double *a,
    *b;
int n, cprec, csdprec;
int **bincode, **csdcode, **csdcoder;
{
  int i, k, ia;
  for (i = 0; i < n; i++) {
    k = a[i] > 0.0 ? 1 : -1;
    ia = (int)(a[i] * (1 << cprec) + k * 0.5);
    int2csd(ia, cprec, csdprec, bincode[i], csdcode[i], csdcoder[i]);
    ia = csd2int(cprec, csdcoder[i]);
    b[i] = (double)(ia) / (double)(1 << cprec);
  }
}


x86 assembly (clang, -O0):
<round2csd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%rax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
mov    %r9,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1237 <round2csd+0x117>
mov    -0x8(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
xorps  %xmm1,%xmm1
mov    $0xffffffff,%eax
mov    $0x1,%ecx
ucomisd %xmm1,%xmm0
cmova  %ecx,%eax
mov    %eax,-0x30(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
cvtsi2sd %eax,%xmm2
cvtsi2sdl -0x30(%rbp),%xmm1
movsd  0xe5b(%rip),%xmm3
mulsd  %xmm3,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rcx
mov    0x10(%rbp),%rax
movslq -0x2c(%rbp),%r8
mov    (%rax,%r8,8),%r8
mov    0x18(%rbp),%rax
movslq -0x2c(%rbp),%r9
mov    (%rax,%r9,8),%r9
mov    $0x0,%al
call   1030 <int2csd@plt>
mov    -0x18(%rbp),%edi
mov    0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
mov    $0x0,%al
call   1040 <csd2int@plt>
mov    %eax,-0x34(%rbp)
cvtsi2sdl -0x34(%rbp),%xmm0
mov    -0x18(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
cvtsi2sd %eax,%xmm1
divsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    114d <round2csd+0x2d>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<round2csd>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %ecx,0x4(%rsp)
test   %edx,%edx
jle    11eb <round2csd+0xcb>
mov    %r9,%r12
mov    %r8d,%ebp
mov    %rsi,%r13
mov    %rdi,%r14
mov    $0x1,%eax
mov    0x4(%rsp),%ecx
shl    %cl,%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,0x8(%rsp)
mov    %edx,%eax
mov    %rax,0x10(%rsp)
xor    %r15d,%r15d
mov    0x4(%rsp),%ebx
nopl   0x0(%rax)
movsd  (%r14,%r15,8),%xmm0
xor    %eax,%eax
ucomisd 0xe90(%rip),%xmm0
seta   %al
mulsd  0x8(%rsp),%xmm0
lea    0xe70(%rip),%rcx
addsd  (%rcx,%rax,8),%xmm0
cvttsd2si %xmm0,%edi
mov    (%r12,%r15,8),%rcx
mov    0x50(%rsp),%rax
mov    (%rax,%r15,8),%r8
mov    0x58(%rsp),%rax
mov    (%rax,%r15,8),%r9
mov    %ebx,%esi
mov    %ebp,%edx
xor    %eax,%eax
call   1030 <int2csd@plt>
mov    0x58(%rsp),%rax
mov    (%rax,%r15,8),%rsi
mov    %ebx,%edi
xor    %eax,%eax
call   1040 <csd2int@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
divsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x0(%r13,%r15,8)
add    $0x1,%r15
cmp    %r15,0x10(%rsp)
jne    1170 <round2csd+0x50>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @round2csd(double* %0, double* %1, i32 %2, i32 %3, i32 %4, i32** %5, i32** %6, i32** %7) {
%9 = alloca double*
%10 = alloca double*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32**
%15 = alloca i32**
%16 = alloca i32**
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
store double* %0, double** %9
store double* %1, double** %10
store i32 %2, i32* %11
store i32 %3, i32* %12
store i32 %4, i32* %13
store i32** %5, i32*** %14
store i32** %6, i32*** %15
store i32** %7, i32*** %16
store i32 0, i32* %17
br label %20
20: ; preds = %82, %8
%21 = load i32, i32* %17
%22 = load i32, i32* %11
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %85
24: ; preds = %20
%25 = load double*, double** %9
%26 = load i32, i32* %17
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds double, double* %25, i64 %27
%29 = load double, double* %28
%30 = fcmp ogt double %29, 0.000000e+00
%31 = zext i1 %30 to i64
%32 = select i1 %30, i32 1, i32 -1
store i32 %32, i32* %18
%33 = load double*, double** %9
%34 = load i32, i32* %17
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds double, double* %33, i64 %35
%37 = load double, double* %36
%38 = load i32, i32* %12
%39 = shl i32 1, %38
%40 = sitofp i32 %39 to double
%41 = load i32, i32* %18
%42 = sitofp i32 %41 to double
%43 = fmul double %42, 5.000000e-01
%44 = call double @llvm.fmuladd.f64(double %37, double %40, double %43)
%45 = fptosi double %44 to i32
store i32 %45, i32* %19
%46 = load i32, i32* %19
%47 = load i32, i32* %12
%48 = load i32, i32* %13
%49 = load i32**, i32*** %14
%50 = load i32, i32* %17
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i32*, i32** %49, i64 %51
%53 = load i32*, i32** %52
%54 = load i32**, i32*** %15
%55 = load i32, i32* %17
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i32*, i32** %54, i64 %56
%58 = load i32*, i32** %57
%59 = load i32**, i32*** %16
%60 = load i32, i32* %17
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds i32*, i32** %59, i64 %61
%63 = load i32*, i32** %62
%64 = call i32 (i32, i32, i32, i32*, i32*, i32*, ...) bitcast (i32 (...)* @int2csd to i32 (i32, i32, i32, i32*, i32*, i32*, ...)*)(i32 %46, i32 %47, i32 %48, i32* %53, i32* %58, i32* %63)
%65 = load i32, i32* %12
%66 = load i32**, i32*** %16
%67 = load i32, i32* %17
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds i32*, i32** %66, i64 %68
%70 = load i32*, i32** %69
%71 = call i32 (i32, i32*, ...) bitcast (i32 (...)* @csd2int to i32 (i32, i32*, ...)*)(i32 %65, i32* %70)
store i32 %71, i32* %19
%72 = load i32, i32* %19
%73 = sitofp i32 %72 to double
%74 = load i32, i32* %12
%75 = shl i32 1, %74
%76 = sitofp i32 %75 to double
%77 = fdiv double %73, %76
%78 = load double*, double** %10
%79 = load i32, i32* %17
%80 = sext i32 %79 to i64
%81 = getelementptr inbounds double, double* %78, i64 %80
store double %77, double* %81
br label %82
82: ; preds = %24
%83 = load i32, i32* %17
%84 = add nsw i32 %83, 1
store i32 %84, i32* %17
br label %20
85: ; preds = %20
ret void
}

LLVM IR (-O2):
define void @round2csd(double* nocapture %0, double* nocapture writeonly %1, i32 %2, i32 %3, i32 %4, i32** nocapture %5, i32** nocapture %6, i32** nocapture %7) {
%9 = icmp sgt i32 %2, 0
br i1 %9, label %10, label %36
10: ; preds = %8
%11 = shl nuw i32 1, %3
%12 = sitofp i32 %11 to double
%13 = zext i32 %2 to i64
br label %14
14: ; preds = %10, %14
%15 = phi i64 [ 0, %10 ], [ %34, %14 ]
%16 = getelementptr inbounds double, double* %0, i64 %15
%17 = load double, double* %16
%18 = fcmp ogt double %17, 0.000000e+00
%19 = select i1 %18, double 5.000000e-01, double -5.000000e-01
%20 = tail call double @llvm.fmuladd.f64(double %17, double %12, double %19)
%21 = fptosi double %20 to i32
%22 = getelementptr inbounds i32*, i32** %5, i64 %15
%23 = load i32*, i32** %22
%24 = getelementptr inbounds i32*, i32** %6, i64 %15
%25 = load i32*, i32** %24
%26 = getelementptr inbounds i32*, i32** %7, i64 %15
%27 = load i32*, i32** %26
%28 = tail call i32 (i32, i32, i32, i32*, i32*, i32*, ...) bitcast (i32 (...)* @int2csd to i32 (i32, i32, i32, i32*, i32*, i32*, ...)*)(i32 %21, i32 %3, i32 %4, i32* %23, i32* %25, i32* %27)
%29 = load i32*, i32** %26
%30 = tail call i32 (i32, i32*, ...) bitcast (i32 (...)* @csd2int to i32 (i32, i32*, ...)*)(i32 %3, i32* %29)
%31 = sitofp i32 %30 to double
%32 = fdiv double %31, %12
%33 = getelementptr inbounds double, double* %1, i64 %15
store double %32, double* %33
%34 = add nuw nsw i64 %15, 1
%35 = icmp eq i64 %34, %13
br i1 %35, label %36, label %14
36: ; preds = %14, %8
ret void
}