int et_getdigit(long double *val, int *cnt) {
  int digit;
  long double d;
  if ((*cnt)++ >= 16)
    return '0';
  digit = (int)*val;
  d = digit;
  digit += '0';
  *val = (*val - d) * 10.0;
  return digit;
}


x86 assembly (clang, -O0):
<et_getdigit>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rcx
mov    (%rcx),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,(%rcx)
cmp    $0x10,%eax
jl     112e <et_getdigit+0x2e>
movl   $0x30,-0x4(%rbp)
jmp    1183 <et_getdigit+0x83>
mov    -0x10(%rbp),%rax
fldt   (%rax)
fnstcw -0x3a(%rbp)
movzwl -0x3a(%rbp),%eax
or     $0xc00,%eax
mov    %ax,-0x3c(%rbp)
fldcw  -0x3c(%rbp)
fistpl -0x38(%rbp)
fldcw  -0x3a(%rbp)
mov    -0x38(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x34(%rbp)
fildl  -0x34(%rbp)
fstpt  -0x30(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x30,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
fldt   (%rax)
fldt   -0x30(%rbp)
fsubrp %st,%st(1)
flds   0xe87(%rip)
fmulp  %st,%st(1)
fstpt  (%rax)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<et_getdigit>:
mov    (%rsi),%ecx
lea    0x1(%rcx),%eax
mov    %eax,(%rsi)
mov    $0x30,%eax
cmp    $0xf,%ecx
jg     1149 <et_getdigit+0x49>
fldt   (%rdi)
fnstcw -0xc(%rsp)
movzwl -0xc(%rsp),%eax
or     $0xc00,%eax
mov    %ax,-0xa(%rsp)
fldcw  -0xa(%rsp)
fistl  -0x8(%rsp)
fldcw  -0xc(%rsp)
mov    -0x8(%rsp),%eax
mov    %eax,-0x4(%rsp)
fisubl -0x4(%rsp)
add    $0x30,%eax
fmuls  0xeb9(%rip)
fstpt  (%rdi)
ret

LLVM IR (-O0):
define i32 @et_getdigit(x86_fp80* %0, i32* %1) {
%3 = alloca i32
%4 = alloca x86_fp80*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca x86_fp80
store x86_fp80* %0, x86_fp80** %4
store i32* %1, i32** %5
%8 = load i32*, i32** %5
%9 = load i32, i32* %8
%10 = add nsw i32 %9, 1
store i32 %10, i32* %8
%11 = icmp sge i32 %9, 16
br i1 %11, label %12, label %13
12: ; preds = %2
store i32 48, i32* %3
br label %28
13: ; preds = %2
%14 = load x86_fp80*, x86_fp80** %4
%15 = load x86_fp80, x86_fp80* %14
%16 = fptosi x86_fp80 %15 to i32
store i32 %16, i32* %6
%17 = load i32, i32* %6
%18 = sitofp i32 %17 to x86_fp80
store x86_fp80 %18, x86_fp80* %7
%19 = load i32, i32* %6
%20 = add nsw i32 %19, 48
store i32 %20, i32* %6
%21 = load x86_fp80*, x86_fp80** %4
%22 = load x86_fp80, x86_fp80* %21
%23 = load x86_fp80, x86_fp80* %7
%24 = fsub x86_fp80 %22, %23
%25 = fmul x86_fp80 %24, 0xK4002A000000000000000
%26 = load x86_fp80*, x86_fp80** %4
store x86_fp80 %25, x86_fp80* %26
%27 = load i32, i32* %6
store i32 %27, i32* %3
br label %28
28: ; preds = %13, %12
%29 = load i32, i32* %3
ret i32 %29
}

LLVM IR (-O2):
define i32 @et_getdigit(x86_fp80* nocapture %0, i32* nocapture %1) {
%3 = load i32, i32* %1
%4 = add nsw i32 %3, 1
store i32 %4, i32* %1
%5 = icmp sgt i32 %3, 15
br i1 %5, label %13, label %6
6: ; preds = %2
%7 = load x86_fp80, x86_fp80* %0
%8 = fptosi x86_fp80 %7 to i32
%9 = sitofp i32 %8 to x86_fp80
%10 = add nsw i32 %8, 48
%11 = fsub x86_fp80 %7, %9
%12 = fmul x86_fp80 %11, 0xK4002A000000000000000
store x86_fp80 %12, x86_fp80* %0
br label %13
13: ; preds = %2, %6
%14 = phi i32 [ %10, %6 ], [ 48, %2 ]
ret i32 %14
}