#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 */
int readdec(unsigned char *, int, int, double *);
int readsigned(unsigned char *s, int len, int i, double *v) {
  int i0 = i, i2;
  double sgn = 1, val;
  if (i >= len) {
    *v = 0;
    return len;
  }
  if (s[i] == '+') {
    i++;
  } else if (s[i] == '-') {
    i++;
    sgn = -1;
  }
  i2 = readdec(s, len, i, &val);
  if (i0 == i && i2 == i) {
    *v = 0;
    return i0;
  }
  *v = sgn * val;
  return i2;
}


x86 assembly (clang, -O0):
<readsigned>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x24(%rbp)
movsd  0xecc(%rip),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jl     115b <readsigned+0x4b>
mov    -0x20(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax)
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    120a <readsigned+0xfa>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0x2b,%eax
jne    117e <readsigned+0x6e>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11ae <readsigned+0x9e>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0x2d,%eax
jne    11a9 <readsigned+0x99>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
movsd  0xe64(%rip),%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    11ae <readsigned+0x9e>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
lea    -0x38(%rbp),%rcx
call   1030 <readdec@plt>
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x18(%rbp),%eax
jne    11f2 <readsigned+0xe2>
mov    -0x28(%rbp),%eax
cmp    -0x18(%rbp),%eax
jne    11f2 <readsigned+0xe2>
mov    -0x20(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax)
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    120a <readsigned+0xfa>
movsd  -0x30(%rbp),%xmm0
mulsd  -0x38(%rbp),%xmm0
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readsigned>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rcx,%r14
xorpd  %xmm0,%xmm0
cmp    %esi,%edx
jge    1145 <readsigned+0x35>
mov    %edx,%ebx
movslq %edx,%rax
mov    (%rdi,%rax,1),%al
cmp    $0x2d,%al
je     1149 <readsigned+0x39>
movsd  0xec9(%rip),%xmm0
movsd  %xmm0,(%rsp)
cmp    $0x2b,%al
jne    115b <readsigned+0x4b>
lea    0x1(%rbx),%ebp
jmp    115d <readsigned+0x4d>
mov    %esi,%ebx
jmp    1182 <readsigned+0x72>
lea    0x1(%rbx),%ebp
movsd  0xeb4(%rip),%xmm0
movsd  %xmm0,(%rsp)
jmp    115d <readsigned+0x4d>
mov    %ebx,%ebp
lea    0x8(%rsp),%rcx
mov    %ebp,%edx
call   1030 <readdec@plt>
cmp    %ebx,%ebp
xorpd  %xmm0,%xmm0
jne    1175 <readsigned+0x65>
cmp    %ebp,%eax
je     1182 <readsigned+0x72>
movsd  (%rsp),%xmm0
mulsd  0x8(%rsp),%xmm0
mov    %eax,%ebx
movsd  %xmm0,(%r14)
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @readsigned(i8* %0, i32 %1, i32 %2, double* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca double*
%10 = alloca i32
%11 = alloca i32
%12 = alloca double
%13 = alloca double
store i8* %0, i8** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store double* %3, double** %9
%14 = load i32, i32* %8
store i32 %14, i32* %10
store double 1.000000e+00, double* %12
%15 = load i32, i32* %8
%16 = load i32, i32* %7
%17 = icmp sge i32 %15, %16
br i1 %17, label %18, label %21
18: ; preds = %4
%19 = load double*, double** %9
store double 0.000000e+00, double* %19
%20 = load i32, i32* %7
store i32 %20, i32* %5
br label %65
21: ; preds = %4
%22 = load i8*, i8** %6
%23 = load i32, i32* %8
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %22, i64 %24
%26 = load i8, i8* %25
%27 = zext i8 %26 to i32
%28 = icmp eq i32 %27, 43
br i1 %28, label %29, label %32
29: ; preds = %21
%30 = load i32, i32* %8
%31 = add nsw i32 %30, 1
store i32 %31, i32* %8
br label %44
32: ; preds = %21
%33 = load i8*, i8** %6
%34 = load i32, i32* %8
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %33, i64 %35
%37 = load i8, i8* %36
%38 = zext i8 %37 to i32
%39 = icmp eq i32 %38, 45
br i1 %39, label %40, label %43
40: ; preds = %32
%41 = load i32, i32* %8
%42 = add nsw i32 %41, 1
store i32 %42, i32* %8
store double -1.000000e+00, double* %12
br label %43
43: ; preds = %40, %32
br label %44
44: ; preds = %43, %29
%45 = load i8*, i8** %6
%46 = load i32, i32* %7
%47 = load i32, i32* %8
%48 = call i32 @readdec(i8* %45, i32 %46, i32 %47, double* %13)
store i32 %48, i32* %11
%49 = load i32, i32* %10
%50 = load i32, i32* %8
%51 = icmp eq i32 %49, %50
br i1 %51, label %52, label %59
52: ; preds = %44
%53 = load i32, i32* %11
%54 = load i32, i32* %8
%55 = icmp eq i32 %53, %54
br i1 %55, label %56, label %59
56: ; preds = %52
%57 = load double*, double** %9
store double 0.000000e+00, double* %57
%58 = load i32, i32* %10
store i32 %58, i32* %5
br label %65
59: ; preds = %52, %44
%60 = load double, double* %12
%61 = load double, double* %13
%62 = fmul double %60, %61
%63 = load double*, double** %9
store double %62, double* %63
%64 = load i32, i32* %11
store i32 %64, i32* %5
br label %65
65: ; preds = %59, %56, %18
%66 = load i32, i32* %5
ret i32 %66
}

LLVM IR (-O2):
define i32 @readsigned(i8* %0, i32 %1, i32 %2, double* nocapture writeonly %3) {
%5 = alloca double
%6 = bitcast double* %5 to i8*
%7 = icmp slt i32 %2, %1
br i1 %7, label %8, label %26
8: ; preds = %4
%9 = sext i32 %2 to i64
%10 = getelementptr inbounds i8, i8* %0, i64 %9
%11 = load i8, i8* %10
switch i8 %11, label %16 [
i8 43, label %12
i8 45, label %14
]
12: ; preds = %8
%13 = add nsw i32 %2, 1
br label %16
14: ; preds = %8
%15 = add nsw i32 %2, 1
br label %16
16: ; preds = %8, %14, %12
%17 = phi i32 [ %13, %12 ], [ %15, %14 ], [ %2, %8 ]
%18 = phi double [ 1.000000e+00, %12 ], [ -1.000000e+00, %14 ], [ 1.000000e+00, %8 ]
%19 = call i32 @readdec(i8* %0, i32 %1, i32 %17, double* %5)
%20 = icmp eq i32 %17, %2
%21 = icmp eq i32 %19, %17
%22 = select i1 %20, i1 %21, i1 false
br i1 %22, label %26, label %23
23: ; preds = %16
%24 = load double, double* %5
%25 = fmul double %18, %24
br label %26
26: ; preds = %16, %4, %23
%27 = phi double [ %25, %23 ], [ 0.000000e+00, %4 ], [ 0.000000e+00, %16 ]
%28 = phi i32 [ %19, %23 ], [ %1, %4 ], [ %2, %16 ]
store double %27, double* %3
ret i32 %28
}