int encode_GDS_I4(buf, dchars, size)
char *buf;
unsigned char *dchars;
int size;
{
  double value = 0.0;
  int rest;
  int i;
  sscanf(buf, "%lf", &value);
  if (value < 0.0)
    value += 65536.0 * 65536.0;
  for (i = 3; i >= 0; i--) {
    rest = value / 256.0;
    dchars[i] = (int)(value - rest * 256.0);
    value = rest;
  }
  return 4;
}


x86 assembly (clang, -O0):
<encode_GDS_I4>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xeda(%rip),%rsi
lea    -0x20(%rbp),%rdx
mov    $0x0,%al
call   1030 <sscanf@plt>
xorps  %xmm0,%xmm0
ucomisd -0x20(%rbp),%xmm0
jbe    1161 <encode_GDS_I4+0x51>
movsd  0xea9(%rip),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x3,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jl     11e4 <encode_GDS_I4+0xd4>
movsd  -0x20(%rbp),%xmm0
movsd  0xe89(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x24(%rbp)
movsd  -0x20(%rbp),%xmm1
cvtsi2sdl -0x24(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  0xe55(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
cvtsi2sdl -0x24(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x28(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x28(%rbp)
jmp    1168 <encode_GDS_I4+0x58>
mov    $0x4,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<encode_GDS_I4>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
movq   $0x0,0x8(%rsp)
lea    0xf28(%rip),%rsi
lea    0x8(%rsp),%rdx
xor    %eax,%eax
call   1030 <sscanf@plt>
movsd  0x8(%rsp),%xmm1
movsd  0xebe(%rip),%xmm2
addsd  %xmm1,%xmm2
xorpd  %xmm3,%xmm3
movapd %xmm1,%xmm0
cmpltsd %xmm3,%xmm0
andpd  %xmm0,%xmm2
andnpd %xmm1,%xmm0
orpd   %xmm2,%xmm0
movsd  0xea1(%rip),%xmm1
movapd %xmm0,%xmm2
mulsd  %xmm1,%xmm2
cvttpd2dq %xmm2,%xmm2
cvtdq2pd %xmm2,%xmm2
movapd %xmm2,%xmm3
mulsd  %xmm1,%xmm3
cvttpd2dq %xmm3,%xmm3
cvtdq2pd %xmm3,%xmm3
movapd %xmm3,%xmm4
mulsd  %xmm1,%xmm4
cvttpd2dq %xmm4,%xmm4
cvtdq2pd %xmm4,%xmm4
mulsd  %xmm4,%xmm1
cvttpd2dq %xmm1,%xmm1
cvtdq2pd %xmm1,%xmm1
unpcklpd %xmm4,%xmm1
unpcklpd %xmm3,%xmm4
unpcklpd %xmm2,%xmm3
unpcklpd %xmm0,%xmm2
movapd 0xe55(%rip),%xmm0
mulpd  %xmm0,%xmm3
addpd  %xmm2,%xmm3
mulpd  %xmm0,%xmm1
addpd  %xmm4,%xmm1
cvttpd2dq %xmm1,%xmm0
cvttpd2dq %xmm3,%xmm1
andpd  0xe45(%rip),%xmm1
pshuflw $0x84,%xmm1,%xmm1
packuswb %xmm1,%xmm1
movdqa 0xe44(%rip),%xmm2
pandn  %xmm1,%xmm2
pand   0xe48(%rip),%xmm0
packuswb %xmm0,%xmm0
packuswb %xmm0,%xmm0
por    %xmm2,%xmm0
movd   %xmm0,(%rbx)
mov    $0x4,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%lf\00"
define i32 @encode_GDS_I4(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca double
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
store double 0.000000e+00, double* %7
%10 = load i8*, i8** %4
%11 = call i32 (i8*, i8*, ...) @sscanf(i8* %10, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), double* %7)
%12 = load double, double* %7
%13 = fcmp olt double %12, 0.000000e+00
br i1 %13, label %14, label %17
14: ; preds = %3
%15 = load double, double* %7
%16 = fadd double %15, 0x41F0000000000000
store double %16, double* %7
br label %17
17: ; preds = %14, %3
store i32 3, i32* %9
br label %18
18: ; preds = %38, %17
%19 = load i32, i32* %9
%20 = icmp sge i32 %19, 0
br i1 %20, label %21, label %41
21: ; preds = %18
%22 = load double, double* %7
%23 = fdiv double %22, 2.560000e+02
%24 = fptosi double %23 to i32
store i32 %24, i32* %8
%25 = load double, double* %7
%26 = load i32, i32* %8
%27 = sitofp i32 %26 to double
%28 = fneg double %27
%29 = call double @llvm.fmuladd.f64(double %28, double 2.560000e+02, double %25)
%30 = fptosi double %29 to i32
%31 = trunc i32 %30 to i8
%32 = load i8*, i8** %5
%33 = load i32, i32* %9
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %32, i64 %34
store i8 %31, i8* %35
%36 = load i32, i32* %8
%37 = sitofp i32 %36 to double
store double %37, double* %7
br label %38
38: ; preds = %21
%39 = load i32, i32* %9
%40 = add nsw i32 %39, -1
store i32 %40, i32* %9
br label %18
41: ; preds = %18
ret i32 4
}

LLVM IR (-O2):
@.str = [4 x i8] c"%lf\00"
define i32 @encode_GDS_I4(i8* nocapture %0, i8* nocapture writeonly %1, i32 %2) {
%4 = alloca double
%5 = bitcast double* %4 to i8*
store double 0.000000e+00, double* %4
%6 = call i32 (i8*, i8*, ...) @sscanf(i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), double* %4)
%7 = load double, double* %4
%8 = fcmp olt double %7, 0.000000e+00
%9 = fadd double %7, 0x41F0000000000000
%10 = select i1 %8, double %9, double %7
%11 = fmul double %10, 3.906250e-03
%12 = fptosi double %11 to i32
%13 = sitofp i32 %12 to double
%14 = fmul double %13, 3.906250e-03
%15 = fptosi double %14 to i32
%16 = sitofp i32 %15 to double
%17 = fmul double %16, 3.906250e-03
%18 = fptosi double %17 to i32
%19 = sitofp i32 %18 to double
%20 = fmul double %19, 3.906250e-03
%21 = fptosi double %20 to i32
%22 = sitofp i32 %21 to double
%23 = insertelement <4 x double> poison, double %22, i64 0
%24 = insertelement <4 x double> %23, double %19, i64 1
%25 = insertelement <4 x double> %24, double %16, i64 2
%26 = insertelement <4 x double> %25, double %13, i64 3
%27 = fneg <4 x double> %26
%28 = insertelement <4 x double> poison, double %19, i64 0
%29 = insertelement <4 x double> %28, double %16, i64 1
%30 = insertelement <4 x double> %29, double %13, i64 2
%31 = insertelement <4 x double> %30, double %10, i64 3
%32 = call <4 x double> @llvm.fmuladd.v4f64(<4 x double> %27, <4 x double> <double 2.560000e+02, double 2.560000e+02, double 2.560000e+02, double 2.560000e+02>, <4 x double> %31)
%33 = fptosi <4 x double> %32 to <4 x i32>
%34 = trunc <4 x i32> %33 to <4 x i8>
%35 = bitcast i8* %1 to <4 x i8>*
store <4 x i8> %34, <4 x i8>* %35
ret i32 4
}