// File: /workspace/github_c_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
callq 0x1070
movq %rax, %r15
leaq 0x2ea5(%rip), %r12      # 0x4070
movq (%r15), %r13
movl 0x2e8c(%rip), %eax      # 0x4060
testl %eax, %eax
jle 0x11e6
decl %eax
movl %eax, 0x2e80(%rip)      # 0x4060
movl (%r12,%rax,4), %r14d
jmp 0x11ee
callq 0x1060
movl %eax, %r14d
movslq %r14d, %rax
testb $0x20, 0x1(%r13,%rax,2)
jne 0x11cb
movq (%r15), %rbp
movzwl (%rbp,%rax,2), %eax
btl $0xb, %eax
jb 0x1228
leal 0x1(%r14), %eax
cmpl $0x2f, %eax
ja 0x13fd
movabsq $0xd00000000001, %rcx   # imm = 0xD00000000001
btq %rax, %rcx
jae 0x13fd
cmpl $0x2d, %r14d
setne %r13b
je 0x1238
cmpl $0x2b, %r14d
jne 0x1284
movl 0x2e22(%rip), %eax      # 0x4060
testl %eax, %eax
jle 0x1250
decl %eax
movl %eax, 0x2e16(%rip)      # 0x4060
movl (%r12,%rax,4), %eax
jmp 0x1255
callq 0x1060
movslq %eax, %rcx
testb $0x8, 0x1(%rbp,%rcx,2)
jne 0x1281
movslq 0x2dfa(%rip), %rcx      # 0x4060
cmpq $0x64, %rcx
jl 0x13c4
leaq 0xda5(%rip), %rdi       # 0x201c
callq 0x1030
jmp 0x13d1
movl %eax, %r14d
xorl %eax, %eax
movb %r13b, %al
movq %rax, %r13
movl $0x0, (%rbx)
movq (%r15), %rax
movslq %r14d, %rcx
testb $0x8, 0x1(%rax,%rcx,2)
je 0x12f8
movss 0xd5d(%rip), %xmm2      # 0x2004
addl $-0x30, %r14d
xorps %xmm0, %xmm0
cvtsi2ss %r14d, %xmm0
movss (%rbx), %xmm1
mulss %xmm2, %xmm1
addss %xmm0, %xmm1
movss %xmm1, (%rbx)
movl 0x2d97(%rip), %eax      # 0x4060
testl %eax, %eax
jle 0x12db
decl %eax
movl %eax, 0x2d8b(%rip)      # 0x4060
movl (%r12,%rax,4), %r14d
jmp 0x12eb
callq 0x1060
movss 0xd1c(%rip), %xmm2      # 0x2004
movl %eax, %r14d
movq (%r15), %rax
movslq %r14d, %rcx
testb $0x8, 0x1(%rax,%rcx,2)
jne 0x12a7
leal -0x1(,%r13,2), %ebp
cmpl $0x2e, %r14d
jne 0x1385
movl $0x1, %r13d
movl 0x2d4e(%rip), %eax      # 0x4060
testl %eax, %eax
jle 0x1324
decl %eax
movl %eax, 0x2d42(%rip)      # 0x4060
movl (%r12,%rax,4), %r14d
jmp 0x132c
callq 0x1060
movl %eax, %r14d
testl %r14d, %r14d
je 0x1385
movq (%r15), %rax
movslq %r14d, %rcx
testb $0x8, 0x1(%rax,%rcx,2)
je 0x1385
addl $-0x30, %r14d
xorps %xmm0, %xmm0
cvtsi2sd %r14d, %xmm0
movsd %xmm0, (%rsp)
xorps %xmm1, %xmm1
cvtsi2sd %r13d, %xmm1
movsd 0xca9(%rip), %xmm0      # 0x2008
callq 0x1040
movsd (%rsp), %xmm1
divsd %xmm0, %xmm1
xorps %xmm0, %xmm0
cvtss2sd (%rbx), %xmm0
addsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, (%rbx)
incl %r13d
jmp 0x130c
xorps %xmm0, %xmm0
cvtsi2ss %ebp, %xmm0
mulss (%rbx), %xmm0
movss %xmm0, (%rbx)
cmpl $-0x1, %r14d
je 0x1419
movslq 0x2cbf(%rip), %rax      # 0x4060
cmpq $0x64, %rax
jl 0x13b5
leaq 0xc6e(%rip), %rdi       # 0x201c
callq 0x1030
jmp 0x1419
leal 0x1(%rax), %ecx
movl %ecx, 0x2ca2(%rip)      # 0x4060
movl %r14d, (%r12,%rax,4)
jmp 0x1419
leal 0x1(%rcx), %edx
movl %edx, 0x2c93(%rip)      # 0x4060
movl %eax, (%r12,%rcx,4)
movslq 0x2c88(%rip), %rax      # 0x4060
cmpq $0x64, %rax
jge 0x140a
xorl %ecx, %ecx
cmpl $0x2d, %r14d
sete %cl
leal 0x2b(,%rcx,2), %ecx
leal 0x1(%rax), %edx
movl %edx, 0x2c69(%rip)      # 0x4060
movl %ecx, (%r12,%rax,4)
jmp 0x1416
movslq 0x2c5c(%rip), %rax      # 0x4060
cmpq $0x64, %rax
jl 0x142b
leaq 0xc0b(%rip), %rdi       # 0x201c
callq 0x1030
xorl %r14d, %r14d
movl %r14d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leal 0x1(%rax), %ecx
movl %ecx, 0x2c2c(%rip)      # 0x4060
movl %r14d, (%r12,%rax,4)
jmp 0x1416