// File: /workspace/github_c_makefile_star2_O3/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, %r14
movl 0x2e96(%rip), %eax      # 0x4060
leaq 0x2e9f(%rip), %r12      # 0x4070
movq (%r14), %r13
testl %eax, %eax
jle 0x11e6
decl %eax
movl %eax, 0x2e80(%rip)      # 0x4060
movl (%r12,%rax,4), %r15d
jmp 0x11f4
callq 0x1060
movl %eax, %r15d
movl 0x2e6c(%rip), %eax      # 0x4060
movslq %r15d, %rcx
testb $0x20, 0x1(%r13,%rcx,2)
jne 0x11d1
movq (%r14), %r13
movzwl (%r13,%rcx,2), %ecx
btl $0xb, %ecx
jb 0x122f
leal 0x1(%r15), %edx
cmpl $0x2f, %edx
ja 0x1421
movabsq $0xd00000000001, %rsi   # imm = 0xD00000000001
btq %rdx, %rsi
jae 0x1421
cmpl $0x2d, %r15d
setne %dl
je 0x123e
cmpl $0x2b, %r15d
jne 0x1250
testl %eax, %eax
jle 0x1255
decl %eax
movl %eax, 0x2e16(%rip)      # 0x4060
movl (%r12,%rax,4), %ebp
jmp 0x1260
movl %r15d, %ebp
jmp 0x129c
movl %edx, %ebp
callq 0x1060
movl %ebp, %edx
movl %eax, %ebp
movslq %ebp, %rax
testb $0x8, 0x1(%r13,%rax,2)
jne 0x1293
movslq 0x2dee(%rip), %rcx      # 0x4060
cmpq $0x64, %rcx
jl 0x13ee
leaq 0xd99(%rip), %rdi       # 0x201c
callq 0x1030
movl 0x2dd2(%rip), %eax      # 0x4060
jmp 0x13fb
movq (%r14), %r13
movzwl (%r13,%rax,2), %ecx
xorl %r15d, %r15d
movb %dl, %r15b
movl $0x0, (%rbx)
btl $0xb, %ecx
jae 0x130b
movl 0x2dac(%rip), %eax      # 0x4060
movss 0xd48(%rip), %xmm2      # 0x2004
addl $-0x30, %ebp
xorps %xmm0, %xmm0
cvtsi2ss %ebp, %xmm0
movss (%rbx), %xmm1
mulss %xmm2, %xmm1
addss %xmm0, %xmm1
movss %xmm1, (%rbx)
testl %eax, %eax
jle 0x12e8
decl %eax
movl %eax, 0x2d7e(%rip)      # 0x4060
movl (%r12,%rax,4), %ebp
jmp 0x1300
callq 0x1060
movss 0xd0f(%rip), %xmm2      # 0x2004
movl %eax, %ebp
movl 0x2d63(%rip), %eax      # 0x4060
movq (%r14), %r13
movslq %ebp, %rcx
testb $0x8, 0x1(%r13,%rcx,2)
jne 0x12bc
leal -0x1(,%r15,2), %r15d
cmpl $0x2e, %ebp
jne 0x1393
movl $0x1, %r13d
movl 0x2d3c(%rip), %eax      # 0x4060
testl %eax, %eax
jle 0x1336
decl %eax
movl %eax, 0x2d30(%rip)      # 0x4060
movl (%r12,%rax,4), %ebp
jmp 0x133d
callq 0x1060
movl %eax, %ebp
testl %ebp, %ebp
je 0x13b2
movq (%r14), %rax
movslq %ebp, %rcx
testb $0x8, 0x1(%rax,%rcx,2)
je 0x1393
addl $-0x30, %ebp
xorps %xmm0, %xmm0
cvtsi2sd %ebp, %xmm0
movsd %xmm0, (%rsp)
xorps %xmm1, %xmm1
cvtsi2sd %r13d, %xmm1
movsd 0xc9b(%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 0x131e
xorps %xmm0, %xmm0
cvtsi2ss %r15d, %xmm0
mulss (%rbx), %xmm0
movss %xmm0, (%rbx)
cmpl $-0x1, %ebp
jne 0x13c4
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jmp 0x1434
xorps %xmm0, %xmm0
cvtsi2ss %r15d, %xmm0
mulss (%rbx), %xmm0
movss %xmm0, (%rbx)
xorl %ebp, %ebp
movslq 0x2c95(%rip), %rax      # 0x4060
cmpq $0x64, %rax
jl 0x13df
leaq 0xc44(%rip), %rdi       # 0x201c
callq 0x1030
jmp 0x1434
leal 0x1(%rax), %ecx
movl %ecx, 0x2c78(%rip)      # 0x4060
movl %ebp, (%r12,%rax,4)
jmp 0x1434
leal 0x1(%rcx), %eax
movl %eax, 0x2c69(%rip)      # 0x4060
movl %ebp, (%r12,%rcx,4)
cmpl $0x64, %eax
jge 0x1426
xorl %ecx, %ecx
cmpl $0x2d, %r15d
sete %cl
leal 0x2b(,%rcx,2), %ecx
leal 0x1(%rax), %edx
movl %edx, 0x2c47(%rip)      # 0x4060
cltq
movl %ecx, (%r12,%rax,4)
jmp 0x1432
cmpl $0x64, %eax
jl 0x1445
leaq 0xbef(%rip), %rdi       # 0x201c
callq 0x1030
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leal 0x1(%rax), %ecx
movl %ecx, 0x2c12(%rip)      # 0x4060
cltq
movl %r15d, (%r12,%rax,4)
jmp 0x1432