#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 */
char get_char();
int /*<<< orphan*/ isdigit(char);
int /*<<< orphan*/ unget_char(char);
double read_decimal(char c) {
  double d = 0;
  double n = 10;
  for (;;) {
    if (!isdigit(c)) {
      unget_char(c);
      break;
    }
    d += (c - '0') / n;
    n *= 10;
    c = get_char();
  }
  return d;
}


x86 assembly (clang, -O0):
<read_decimal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  0xeb2(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsbl -0x1(%rbp),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%eax
jne    1173 <read_decimal+0x43>
movsbl -0x1(%rbp),%edi
call   1050 <unget_char@plt>
jmp    11ae <read_decimal+0x7e>
movsbl -0x1(%rbp),%eax
sub    $0x30,%eax
cvtsi2sd %eax,%xmm0
divsd  -0x18(%rbp),%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  0xe6b(%rip),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    $0x0,%al
call   1040 <get_char@plt>
mov    %al,-0x1(%rbp)
jmp    1153 <read_decimal+0x23>
movsd  -0x10(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_decimal>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
call   1030 <isdigit@plt>
xorpd  %xmm0,%xmm0
test   %eax,%eax
je     11aa <read_decimal+0x7a>
movsd  %xmm0,(%rsp)
movsd  0xeaf(%rip),%xmm2
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsbl %bl,%eax
add    $0xffffffd0,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
divsd  %xmm2,%xmm0
movsd  (%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
mulsd  0xe79(%rip),%xmm2
movsd  %xmm2,0x8(%rsp)
xor    %eax,%eax
call   1040 <get_char@plt>
mov    %eax,%ebx
movsbl %al,%edi
call   1030 <isdigit@plt>
movsd  0x8(%rsp),%xmm2
test   %eax,%eax
jne    1160 <read_decimal+0x30>
jmp    11af <read_decimal+0x7f>
movsd  %xmm0,(%rsp)
movsbl %bl,%edi
call   1050 <unget_char@plt>
movsd  (%rsp),%xmm0
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define double @read_decimal(i8 signext %0) {
%2 = alloca i8
%3 = alloca double
%4 = alloca double
store i8 %0, i8* %2
store double 0.000000e+00, double* %3
store double 1.000000e+01, double* %4
br label %5
5: ; preds = %12, %1
%6 = load i8, i8* %2
%7 = call i32 @isdigit(i8 signext %6)
%8 = icmp ne i32 %7, 0
br i1 %8, label %12, label %9
9: ; preds = %5
%10 = load i8, i8* %2
%11 = call i32 @unget_char(i8 signext %10)
br label %24
12: ; preds = %5
%13 = load i8, i8* %2
%14 = sext i8 %13 to i32
%15 = sub nsw i32 %14, 48
%16 = sitofp i32 %15 to double
%17 = load double, double* %4
%18 = fdiv double %16, %17
%19 = load double, double* %3
%20 = fadd double %19, %18
store double %20, double* %3
%21 = load double, double* %4
%22 = fmul double %21, 1.000000e+01
store double %22, double* %4
%23 = call signext i8 (...) @get_char()
store i8 %23, i8* %2
br label %5
24: ; preds = %9
%25 = load double, double* %3
ret double %25
}

LLVM IR (-O2):
define double @read_decimal(i8 signext %0) {
%2 = tail call i32 @isdigit(i8 signext %0)
%3 = icmp eq i32 %2, 0
br i1 %3, label %4, label %8
4: ; preds = %8, %1
%5 = phi i8 [ %0, %1 ], [ %18, %8 ]
%6 = phi double [ 0.000000e+00, %1 ], [ %16, %8 ]
%7 = tail call i32 @unget_char(i8 signext %5)
ret double %6
8: ; preds = %1, %8
%9 = phi double [ %17, %8 ], [ 1.000000e+01, %1 ]
%10 = phi double [ %16, %8 ], [ 0.000000e+00, %1 ]
%11 = phi i8 [ %18, %8 ], [ %0, %1 ]
%12 = sext i8 %11 to i32
%13 = add nsw i32 %12, -48
%14 = sitofp i32 %13 to double
%15 = fdiv double %14, %9
%16 = fadd double %10, %15
%17 = fmul double %9, 1.000000e+01
%18 = tail call signext i8 (...) @get_char()
%19 = tail call i32 @isdigit(i8 signext %18)
%20 = icmp eq i32 %19, 0
br i1 %20, label %4, label %8
}