double PackMaterial(double d1, double d2, double d3, double d4) {
  int a, b, c, d, ires;
  double res;
  a = (int)(d1 * 100 - 0.5);
  if (a < 0)
    a = 0;
  if (a > 99)
    a = 99;
  b = (int)(d2 * 100 - 0.5);
  if (b < 0)
    b = 0;
  if (b > 99)
    b = 99;
  c = (int)(d3 * 100 - 0.5);
  if (c < 0)
    c = 0;
  if (c > 99)
    c = 99;
  d = (int)(d4 * 10 - 0.5);
  if (d < 0)
    d = 0;
  if (d > 9)
    d = 9;
  ires = ((((a * 100) + b) * 100) + c) * 10 + d;
  res = ires;
  return res;
}


x86 assembly (clang, -O0):
<PackMaterial>:
push   %rbp
mov    %rsp,%rbp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  %xmm2,-0x18(%rbp)
movsd  %xmm3,-0x20(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  0xedb(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xed7(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    114d <PackMaterial+0x4d>
movl   $0x0,-0x24(%rbp)
cmpl   $0x63,-0x24(%rbp)
jle    115e <PackMaterial+0x5e>
movl   $0x63,-0x24(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xe95(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe91(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jge    1193 <PackMaterial+0x93>
movl   $0x0,-0x28(%rbp)
cmpl   $0x63,-0x28(%rbp)
jle    11a4 <PackMaterial+0xa4>
movl   $0x63,-0x28(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  0xe4f(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe4b(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    11d9 <PackMaterial+0xd9>
movl   $0x0,-0x2c(%rbp)
cmpl   $0x63,-0x2c(%rbp)
jle    11ea <PackMaterial+0xea>
movl   $0x63,-0x2c(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  0xe19(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe05(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
jge    121f <PackMaterial+0x11f>
movl   $0x0,-0x30(%rbp)
cmpl   $0x9,-0x30(%rbp)
jle    1230 <PackMaterial+0x130>
movl   $0x9,-0x30(%rbp)
imul   $0x64,-0x24(%rbp),%eax
add    -0x28(%rbp),%eax
imul   $0x64,%eax,%eax
add    -0x2c(%rbp),%eax
imul   $0xa,%eax,%eax
add    -0x30(%rbp),%eax
mov    %eax,-0x34(%rbp)
cvtsi2sdl -0x34(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<PackMaterial>:
unpcklpd %xmm0,%xmm1
unpcklpd %xmm2,%xmm3
mulpd  0xef0(%rip),%xmm3
movapd 0xef8(%rip),%xmm0
addpd  %xmm0,%xmm3
mulpd  0xefc(%rip),%xmm1
addpd  %xmm0,%xmm1
cvttpd2dq %xmm1,%xmm0
cvttpd2dq %xmm3,%xmm1
unpcklpd %xmm0,%xmm1
xorpd  %xmm0,%xmm0
movapd %xmm1,%xmm2
pcmpgtd %xmm0,%xmm2
pand   %xmm1,%xmm2
movdqa 0xee4(%rip),%xmm0
pxor   %xmm2,%xmm0
movdqa 0xee8(%rip),%xmm1
pcmpgtd %xmm0,%xmm1
movmskps %xmm1,%eax
pshufd $0xff,%xmm2,%xmm0
pshufd $0xee,%xmm2,%xmm1
movd   %xmm1,%ecx
test   $0x4,%al
mov    $0x63,%edx
cmove  %edx,%ecx
movd   %xmm0,%r8d
pshufd $0x55,%xmm2,%xmm0
movd   %xmm0,%edi
test   $0x2,%al
cmove  %edx,%edi
movd   %xmm2,%edx
test   $0x1,%al
mov    $0x9,%esi
cmovne %edx,%esi
imul   $0x64,%r8d,%edx
test   $0x8,%al
mov    $0x26ac,%eax
cmovne %edx,%eax
add    %ecx,%eax
imul   $0x64,%eax,%eax
add    %edi,%eax
lea    (%rax,%rax,4),%eax
lea    (%rsi,%rax,2),%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
ret

LLVM IR (-O0):
define double @PackMaterial(double %0, double %1, double %2, double %3) {
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca double
store double %0, double* %5
store double %1, double* %6
store double %2, double* %7
store double %3, double* %8
%15 = load double, double* %5
%16 = call double @llvm.fmuladd.f64(double %15, double 1.000000e+02, double -5.000000e-01)
%17 = fptosi double %16 to i32
store i32 %17, i32* %9
%18 = load i32, i32* %9
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %4
store i32 0, i32* %9
br label %21
21: ; preds = %20, %4
%22 = load i32, i32* %9
%23 = icmp sgt i32 %22, 99
br i1 %23, label %24, label %25
24: ; preds = %21
store i32 99, i32* %9
br label %25
25: ; preds = %24, %21
%26 = load double, double* %6
%27 = call double @llvm.fmuladd.f64(double %26, double 1.000000e+02, double -5.000000e-01)
%28 = fptosi double %27 to i32
store i32 %28, i32* %10
%29 = load i32, i32* %10
%30 = icmp slt i32 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %25
store i32 0, i32* %10
br label %32
32: ; preds = %31, %25
%33 = load i32, i32* %10
%34 = icmp sgt i32 %33, 99
br i1 %34, label %35, label %36
35: ; preds = %32
store i32 99, i32* %10
br label %36
36: ; preds = %35, %32
%37 = load double, double* %7
%38 = call double @llvm.fmuladd.f64(double %37, double 1.000000e+02, double -5.000000e-01)
%39 = fptosi double %38 to i32
store i32 %39, i32* %11
%40 = load i32, i32* %11
%41 = icmp slt i32 %40, 0
br i1 %41, label %42, label %43
42: ; preds = %36
store i32 0, i32* %11
br label %43
43: ; preds = %42, %36
%44 = load i32, i32* %11
%45 = icmp sgt i32 %44, 99
br i1 %45, label %46, label %47
46: ; preds = %43
store i32 99, i32* %11
br label %47
47: ; preds = %46, %43
%48 = load double, double* %8
%49 = call double @llvm.fmuladd.f64(double %48, double 1.000000e+01, double -5.000000e-01)
%50 = fptosi double %49 to i32
store i32 %50, i32* %12
%51 = load i32, i32* %12
%52 = icmp slt i32 %51, 0
br i1 %52, label %53, label %54
53: ; preds = %47
store i32 0, i32* %12
br label %54
54: ; preds = %53, %47
%55 = load i32, i32* %12
%56 = icmp sgt i32 %55, 9
br i1 %56, label %57, label %58
57: ; preds = %54
store i32 9, i32* %12
br label %58
58: ; preds = %57, %54
%59 = load i32, i32* %9
%60 = mul nsw i32 %59, 100
%61 = load i32, i32* %10
%62 = add nsw i32 %60, %61
%63 = mul nsw i32 %62, 100
%64 = load i32, i32* %11
%65 = add nsw i32 %63, %64
%66 = mul nsw i32 %65, 10
%67 = load i32, i32* %12
%68 = add nsw i32 %66, %67
store i32 %68, i32* %13
%69 = load i32, i32* %13
%70 = sitofp i32 %69 to double
store double %70, double* %14
%71 = load double, double* %14
ret double %71
}

LLVM IR (-O2):
define double @PackMaterial(double %0, double %1, double %2, double %3) {
%5 = insertelement <4 x double> poison, double %3, i64 0
%6 = insertelement <4 x double> %5, double %2, i64 1
%7 = insertelement <4 x double> %6, double %1, i64 2
%8 = insertelement <4 x double> %7, double %0, i64 3
%9 = call <4 x double> @llvm.fmuladd.v4f64(<4 x double> %8, <4 x double> <double 1.000000e+01, double 1.000000e+02, double 1.000000e+02, double 1.000000e+02>, <4 x double> <double -5.000000e-01, double -5.000000e-01, double -5.000000e-01, double -5.000000e-01>)
%10 = fptosi <4 x double> %9 to <4 x i32>
%11 = icmp sgt <4 x i32> %10, zeroinitializer
%12 = select <4 x i1> %11, <4 x i32> %10, <4 x i32> zeroinitializer
%13 = icmp ult <4 x i32> %12, <i32 9, i32 99, i32 99, i32 99>
%14 = extractelement <4 x i1> %13, i64 3
%15 = extractelement <4 x i32> %12, i64 3
%16 = extractelement <4 x i1> %13, i64 2
%17 = extractelement <4 x i32> %12, i64 2
%18 = select i1 %16, i32 %17, i32 99
%19 = extractelement <4 x i1> %13, i64 1
%20 = extractelement <4 x i32> %12, i64 1
%21 = select i1 %19, i32 %20, i32 99
%22 = extractelement <4 x i1> %13, i64 0
%23 = extractelement <4 x i32> %12, i64 0
%24 = select i1 %22, i32 %23, i32 9
%25 = mul nuw nsw i32 %15, 100
%26 = select i1 %14, i32 %25, i32 9900
%27 = add nuw nsw i32 %26, %18
%28 = mul nuw nsw i32 %27, 100
%29 = add nuw nsw i32 %28, %21
%30 = mul nuw nsw i32 %29, 10
%31 = add nuw nsw i32 %30, %24
%32 = sitofp i32 %31 to double
ret double %32
}