// File: /workspace/github_c_makefile_star2_O0/ohkimur[P]the-c-programming-language-2nd-edition-solutions/chapter_5/exercise_5_02/getfloat.c
// Function: getfloat
int getfloat(float *pn)
{
  int c, sign;

  while (isspace(c = getch()))
    ;

  if (!isdigit(c) && c != EOF && c != '+' && c != '-' && c != '.')
  {
    ungetch(c);
    return 0;
  }

  sign = (c == '-') ? -1 : 1;

  if (c == '+' || c == '-')
  {
    if (!isdigit(c = getch()))
    {
      ungetch(c);
      ungetch(sign == 1 ? '+' : '-');
      return 0;
    }
  }

  for (*pn = 0; isdigit(c); c = getch())
  {
    *pn = 10 * *pn + (c - '0');
  }

  if (c == '.')
  {
    int i;
    for (i = 1; (c = getch()) && isdigit(c); ++i)
    {
      *pn += (c - '0') / (pow(10, i));
    }
  }

  *pn = *pn * sign;

  if (c != EOF)
  {
    ungetch(c);
  }

  return c;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
callq 0x1060
movq (%rax), %rax
movq %rax, -0x28(%rbp)
callq 0x13e0
movl %eax, %ecx
movq -0x28(%rbp), %rax
movl %ecx, -0x14(%rbp)
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x2000, %eax           # imm = 0x2000
cmpl $0x0, %eax
je 0x11e9
jmp 0x11bc
callq 0x1060
movq (%rax), %rax
movslq -0x14(%rbp), %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x800, %eax            # imm = 0x800
cmpl $0x0, %eax
jne 0x122f
cmpl $-0x1, -0x14(%rbp)
je 0x122f
cmpl $0x2b, -0x14(%rbp)
je 0x122f
cmpl $0x2d, -0x14(%rbp)
je 0x122f
cmpl $0x2e, -0x14(%rbp)
je 0x122f
movl -0x14(%rbp), %edi
callq 0x1430
movl $0x0, -0x4(%rbp)
jmp 0x13ce
movl -0x14(%rbp), %edx
movl $0x1, %eax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
cmpl $0x2d, %edx
cmovel %ecx, %eax
movl %eax, -0x18(%rbp)
cmpl $0x2b, -0x14(%rbp)
je 0x1251
cmpl $0x2d, -0x14(%rbp)
jne 0x12aa
callq 0x1060
movq (%rax), %rax
movq %rax, -0x30(%rbp)
callq 0x13e0
movl %eax, %ecx
movq -0x30(%rbp), %rax
movl %ecx, -0x14(%rbp)
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x800, %eax            # imm = 0x800
cmpl $0x0, %eax
jne 0x12a8
movl -0x14(%rbp), %edi
callq 0x1430
movl -0x18(%rbp), %ecx
movl $0x2d, %edi
movl $0x2b, %eax
cmpl $0x1, %ecx
cmovel %eax, %edi
callq 0x1430
movl $0x0, -0x4(%rbp)
jmp 0x13ce
jmp 0x12aa
movq -0x10(%rbp), %rax
xorps %xmm0, %xmm0
movss %xmm0, (%rax)
callq 0x1060
movq (%rax), %rax
movslq -0x14(%rbp), %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x800, %eax            # imm = 0x800
cmpl $0x0, %eax
je 0x1303
movq -0x10(%rbp), %rax
movss (%rax), %xmm0
movl -0x14(%rbp), %eax
subl $0x30, %eax
cvtsi2ss %eax, %xmm1
movss 0xd27(%rip), %xmm2      # 0x2010
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movq -0x10(%rbp), %rax
movss %xmm0, (%rax)
callq 0x13e0
movl %eax, -0x14(%rbp)
jmp 0x12b5
cmpl $0x2e, -0x14(%rbp)
jne 0x13a1
movl $0x1, -0x1c(%rbp)
callq 0x13e0
movl %eax, %ecx
movl %ecx, -0x14(%rbp)
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x31(%rbp)
je 0x1346
callq 0x1060
movq (%rax), %rax
movslq -0x14(%rbp), %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x800, %eax            # imm = 0x800
cmpl $0x0, %eax
setne %al
movb %al, -0x31(%rbp)
movb -0x31(%rbp), %al
testb $0x1, %al
jne 0x134f
jmp 0x139f
movl -0x14(%rbp), %eax
subl $0x30, %eax
cvtsi2sd %eax, %xmm0
movsd %xmm0, -0x40(%rbp)
cvtsi2sdl -0x1c(%rbp), %xmm1
movsd 0xc9d(%rip), %xmm0      # 0x2008
callq 0x1030
movsd -0x40(%rbp), %xmm1
divsd %xmm0, %xmm1
movq -0x10(%rbp), %rax
movss (%rax), %xmm0
cvtss2sd %xmm0, %xmm0
addsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, (%rax)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x1314
jmp 0x13a1
movq -0x10(%rbp), %rax
movss (%rax), %xmm0
cvtsi2ssl -0x18(%rbp), %xmm1
mulss %xmm1, %xmm0
movq -0x10(%rbp), %rax
movss %xmm0, (%rax)
cmpl $-0x1, -0x14(%rbp)
je 0x13c8
movl -0x14(%rbp), %edi
callq 0x1430
movl -0x14(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopw (%rax,%rax)