#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 */
unsigned char _n_base_val(char);
double ReadFraction(char *string[], int base) {
  unsigned char digit;
  double quotient = 0, divider = 1;
  digit = _n_base_val(**string);
  while (digit < base) {
    quotient = quotient * base + digit;
    divider *= base;
    *string += 1;
    digit = _n_base_val(**string);
  }
  return (quotient / divider);
}


x86 assembly (clang, -O0):
<ReadFraction>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xed1(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%edi
call   1030 <_n_base_val@plt>
mov    %al,-0xd(%rbp)
movzbl -0xd(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11a6 <ReadFraction+0x96>
movsd  -0x18(%rbp),%xmm0
cvtsi2sdl -0xc(%rbp),%xmm2
movzbl -0xd(%rbp),%eax
cvtsi2sd %eax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
cvtsi2sdl -0xc(%rbp),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
add    $0x1,%rcx
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%edi
call   1030 <_n_base_val@plt>
mov    %al,-0xd(%rbp)
jmp    1146 <ReadFraction+0x36>
movsd  -0x18(%rbp),%xmm0
divsd  -0x20(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ReadFraction>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %esi,%ebp
mov    %rdi,%rbx
mov    (%rdi),%rax
movsbl (%rax),%edi
call   1030 <_n_base_val@plt>
movzbl %al,%ecx
xorpd  %xmm0,%xmm0
cmp    %ebp,%ecx
jge    11a1 <ReadFraction+0x91>
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
movsd  %xmm0,(%rsp)
xorpd  %xmm0,%xmm0
movsd  0xeb7(%rip),%xmm2
nopl   0x0(%rax)
movzbl %al,%eax
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
movsd  (%rsp),%xmm3
mulsd  %xmm3,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,0x10(%rsp)
mulsd  %xmm3,%xmm2
movsd  %xmm2,0x8(%rsp)
mov    (%rbx),%rax
lea    0x1(%rax),%rcx
mov    %rcx,(%rbx)
movsbl 0x1(%rax),%edi
call   1030 <_n_base_val@plt>
movsd  0x8(%rsp),%xmm2
movsd  0x10(%rsp),%xmm0
movzbl %al,%ecx
cmp    %ebp,%ecx
jl     1150 <ReadFraction+0x40>
divsd  %xmm2,%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define double @ReadFraction(i8** %0, i32 %1) {
%3 = alloca i8**
%4 = alloca i32
%5 = alloca i8
%6 = alloca double
%7 = alloca double
store i8** %0, i8*** %3
store i32 %1, i32* %4
store double 0.000000e+00, double* %6
store double 1.000000e+00, double* %7
%8 = load i8**, i8*** %3
%9 = load i8*, i8** %8
%10 = load i8, i8* %9
%11 = call zeroext i8 @_n_base_val(i8 signext %10)
store i8 %11, i8* %5
br label %12
12: ; preds = %17, %2
%13 = load i8, i8* %5
%14 = zext i8 %13 to i32
%15 = load i32, i32* %4
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %36
17: ; preds = %12
%18 = load double, double* %6
%19 = load i32, i32* %4
%20 = sitofp i32 %19 to double
%21 = load i8, i8* %5
%22 = zext i8 %21 to i32
%23 = sitofp i32 %22 to double
%24 = call double @llvm.fmuladd.f64(double %18, double %20, double %23)
store double %24, double* %6
%25 = load i32, i32* %4
%26 = sitofp i32 %25 to double
%27 = load double, double* %7
%28 = fmul double %27, %26
store double %28, double* %7
%29 = load i8**, i8*** %3
%30 = load i8*, i8** %29
%31 = getelementptr inbounds i8, i8* %30, i64 1
store i8* %31, i8** %29
%32 = load i8**, i8*** %3
%33 = load i8*, i8** %32
%34 = load i8, i8* %33
%35 = call zeroext i8 @_n_base_val(i8 signext %34)
store i8 %35, i8* %5
br label %12
36: ; preds = %12
%37 = load double, double* %6
%38 = load double, double* %7
%39 = fdiv double %37, %38
ret double %39
}

LLVM IR (-O2):
define double @ReadFraction(i8** nocapture %0, i32 %1) {
%3 = load i8*, i8** %0
%4 = load i8, i8* %3
%5 = tail call zeroext i8 @_n_base_val(i8 signext %4)
%6 = zext i8 %5 to i32
%7 = icmp slt i32 %6, %1
br i1 %7, label %8, label %25
8: ; preds = %2
%9 = sitofp i32 %1 to double
br label %10
10: ; preds = %8, %10
%11 = phi double [ 1.000000e+00, %8 ], [ %16, %10 ]
%12 = phi double [ 0.000000e+00, %8 ], [ %15, %10 ]
%13 = phi i8 [ %5, %8 ], [ %20, %10 ]
%14 = uitofp i8 %13 to double
%15 = tail call double @llvm.fmuladd.f64(double %12, double %9, double %14)
%16 = fmul double %11, %9
%17 = load i8*, i8** %0
%18 = getelementptr inbounds i8, i8* %17, i64 1
store i8* %18, i8** %0
%19 = load i8, i8* %18
%20 = tail call zeroext i8 @_n_base_val(i8 signext %19)
%21 = zext i8 %20 to i32
%22 = icmp slt i32 %21, %1
br i1 %22, label %10, label %23
23: ; preds = %10
%24 = fdiv double %15, %16
br label %25
25: ; preds = %23, %2
%26 = phi double [ %24, %23 ], [ 0.000000e+00, %2 ]
ret double %26
}