#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 */
float NAN;
scalar_t__ errno;
scalar_t__ isdigit(char const);
float strtof(char const *, int /*<<< orphan*/ *);
float tkh_decode_voltage(const char *s) {
  int ndp = 0;
  const char *c = s;
  int n = 0;
  for (; n < 5 && *c; c = c + 1) {
    if (isdigit(*c))
      n++;
    else if (*c == '.') {
      if (ndp < 1)
        ndp++;
      else
        return NAN;
    } else
      return NAN;
  }
  if (n > 4 || ndp != 1)
    return NAN;
  errno = 0;
  float v = strtof(s, NULL);
  if (errno) {
    errno = 0;
    return NAN;
  } else
    return v;
}


x86 assembly (clang, -O0):
<tkh_decode_voltage>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
xor    %eax,%eax
cmpl   $0x5,-0x24(%rbp)
mov    %al,-0x29(%rbp)
jge    1161 <tkh_decode_voltage+0x41>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    1171 <tkh_decode_voltage+0x51>
jmp    1207 <tkh_decode_voltage+0xe7>
mov    -0x20(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     1195 <tkh_decode_voltage+0x75>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11f1 <tkh_decode_voltage+0xd1>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    11d7 <tkh_decode_voltage+0xb7>
cmpl   $0x1,-0x14(%rbp)
jge    11bd <tkh_decode_voltage+0x9d>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11d2 <tkh_decode_voltage+0xb2>
mov    0x2e34(%rip),%rax
movss  (%rax),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    128e <tkh_decode_voltage+0x16e>
jmp    11ec <tkh_decode_voltage+0xcc>
mov    0x2e1a(%rip),%rax
movss  (%rax),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    128e <tkh_decode_voltage+0x16e>
jmp    11f1 <tkh_decode_voltage+0xd1>
jmp    11f6 <tkh_decode_voltage+0xd6>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1142 <tkh_decode_voltage+0x22>
cmpl   $0x4,-0x24(%rbp)
jg     121b <tkh_decode_voltage+0xfb>
cmpl   $0x1,-0x14(%rbp)
je     1230 <tkh_decode_voltage+0x110>
mov    0x2dd6(%rip),%rax
movss  (%rax),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    128e <tkh_decode_voltage+0x16e>
mov    0x2da1(%rip),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <strtof@plt>
movss  %xmm0,-0x28(%rbp)
mov    0x2d81(%rip),%rax
cmpq   $0x0,(%rax)
je     1284 <tkh_decode_voltage+0x164>
mov    0x2d70(%rip),%rax
movq   $0x0,(%rax)
mov    0x2d82(%rip),%rax
movss  (%rax),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    128e <tkh_decode_voltage+0x16e>
movss  -0x28(%rbp),%xmm0
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tkh_decode_voltage>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %ebp,%ebp
mov    %rdi,%rbx
xor    %r15d,%r15d
jmp    114c <tkh_decode_voltage+0x2c>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%ebp
add    $0x1,%rbx
cmp    $0x5,%ebp
jge    119d <tkh_decode_voltage+0x7d>
movzbl (%rbx),%eax
test   %al,%al
je     1172 <tkh_decode_voltage+0x52>
movsbl %al,%edi
call   1030 <isdigit@plt>
test   %rax,%rax
jne    1140 <tkh_decode_voltage+0x20>
cmpb   $0x2e,(%rbx)
jne    119d <tkh_decode_voltage+0x7d>
test   %r15d,%r15d
mov    $0x1,%r15d
jle    1143 <tkh_decode_voltage+0x23>
jmp    119d <tkh_decode_voltage+0x7d>
cmp    $0x1,%r15d
jne    119d <tkh_decode_voltage+0x7d>
mov    0x2e59(%rip),%rbx
movq   $0x0,(%rbx)
mov    %r14,%rdi
xor    %esi,%esi
call   1040 <strtof@plt>
cmpq   $0x0,(%rbx)
je     11a8 <tkh_decode_voltage+0x88>
movq   $0x0,(%rbx)
mov    0x2e54(%rip),%rax
movss  (%rax),%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@NAN = global float 0.000000e+00
@errno = global i64 0
define float @tkh_decode_voltage(i8* nocapture %0) {
br label %2
2: ; preds = %1, %22
%3 = phi i32 [ 0, %1 ], [ %24, %22 ]
%4 = phi i8* [ %0, %1 ], [ %25, %22 ]
%5 = phi i32 [ 0, %1 ], [ %23, %22 ]
%6 = load i8, i8* %4
%7 = icmp eq i8 %6, 0
br i1 %7, label %27, label %8
8: ; preds = %2
%9 = tail call i64 @isdigit(i8 signext %6)
%10 = icmp eq i64 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %8
%12 = add nsw i32 %3, 1
br label %22
13: ; preds = %8
%14 = load i8, i8* %4
%15 = icmp eq i8 %14, 46
br i1 %15, label %16, label %20
16: ; preds = %13
%17 = icmp slt i32 %5, 1
br i1 %17, label %22, label %18
18: ; preds = %16
%19 = load float, float* @NAN
br label %37
20: ; preds = %13
%21 = load float, float* @NAN
br label %37
22: ; preds = %16, %11
%23 = phi i32 [ %5, %11 ], [ 1, %16 ]
%24 = phi i32 [ %12, %11 ], [ %3, %16 ]
%25 = getelementptr inbounds i8, i8* %4, i64 1
%26 = icmp slt i32 %24, 5
br i1 %26, label %2, label %29
27: ; preds = %2
%28 = icmp eq i32 %5, 1
br i1 %28, label %31, label %29
29: ; preds = %22, %27
%30 = load float, float* @NAN
br label %37
31: ; preds = %27
store i64 0, i64* @errno
%32 = tail call float @strtof(i8* nocapture %0, i32* null)
%33 = load i64, i64* @errno
%34 = icmp eq i64 %33, 0
br i1 %34, label %37, label %35
35: ; preds = %31
store i64 0, i64* @errno
%36 = load float, float* @NAN
br label %37
37: ; preds = %35, %31, %29, %20, %18
%38 = phi float [ %19, %18 ], [ %21, %20 ], [ %30, %29 ], [ %36, %35 ], [ %32, %31 ]
ret float %38
}