#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 */
double atof(char *);
scalar_t__ isspace(char);
int strlen(char *);
double atofs(char *s) {
  char last;
  int len;
  double suff = 1.0;
  len = strlen(s);
  while (len > 1 && isspace(s[len - 1]))
    --len;
  last = s[len - 1];
  s[len - 1] = '\0';
  switch (last) {
  case 'g':
  case 'G':
    suff *= 1e3;
  case 'm':
  case 'M':
    suff *= 1e3;
  case 'k':
  case 'K':
    suff *= 1e3;
    suff *= atof(s);
    s[len - 1] = last;
    return suff;
  }
  s[len - 1] = last;
  return atof(s);
}


x86 assembly (clang, -O0):
<atofs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movsd  0xebc(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x18(%rbp)
xor    %eax,%eax
cmpl   $0x1,-0x18(%rbp)
mov    %al,-0x21(%rbp)
jle    1184 <atofs+0x54>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%edi
call   1050 <isspace@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    1194 <atofs+0x64>
jmp    11a2 <atofs+0x72>
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
jmp    1155 <atofs+0x25>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
add    $0xffffffff,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x11(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
add    $0xffffffff,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
movsbl -0x11(%rbp),%eax
mov    %eax,-0x28(%rbp)
sub    $0x47,%eax
je     1230 <atofs+0x100>
jmp    11db <atofs+0xab>
mov    -0x28(%rbp),%eax
sub    $0x4b,%eax
je     1254 <atofs+0x124>
jmp    11ec <atofs+0xbc>
mov    -0x28(%rbp),%eax
sub    $0x4d,%eax
je     1242 <atofs+0x112>
jmp    11fd <atofs+0xcd>
mov    -0x28(%rbp),%eax
sub    $0x67,%eax
je     1230 <atofs+0x100>
jmp    120e <atofs+0xde>
mov    -0x28(%rbp),%eax
sub    $0x6b,%eax
je     1254 <atofs+0x124>
jmp    121f <atofs+0xef>
mov    -0x28(%rbp),%eax
sub    $0x6d,%eax
je     1242 <atofs+0x112>
jmp    129b <atofs+0x16b>
movsd  0xdd0(%rip),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xdbe(%rip),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xdac(%rip),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <atof@plt>
mulsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x11(%rbp),%dl
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12bc <atofs+0x18c>
mov    -0x11(%rbp),%dl
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
call   1030 <atof@plt>
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<atofs>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r15
call   1040 <strlen@plt>
mov    %eax,%ebp
test   %eax,%eax
mov    $0x1,%r14d
cmovle %eax,%r14d
mov    %eax,%ebx
add    $0xffffffff,%ebx
add    %r15,%rbx
cs nopw 0x0(%rax,%rax,1)
nop
cmp    $0x2,%ebp
jl     117f <atofs+0x4f>
movsbl (%rbx),%edi
call   1050 <isspace@plt>
add    $0xffffffff,%ebp
add    $0xffffffffffffffff,%rbx
test   %rax,%rax
jne    1160 <atofs+0x30>
add    $0x1,%ebp
mov    %ebp,%r14d
movslq %r14d,%rbp
movsbl -0x1(%rbp,%r15,1),%r14d
movb   $0x0,-0x1(%rbp,%r15,1)
mov    %r14d,%eax
add    $0xffffffb9,%eax
cmp    $0x26,%eax
ja     1207 <atofs+0xd7>
movabs $0x100000001,%rcx
bt     %rax,%rcx
jb     11dd <atofs+0xad>
movabs $0x1000000010,%rcx
bt     %rax,%rcx
jb     11d3 <atofs+0xa3>
movabs $0x4000000040,%rcx
bt     %rax,%rcx
jae    1207 <atofs+0xd7>
movsd  0xe37(%rip),%xmm0
jmp    11e5 <atofs+0xb5>
movsd  0xe25(%rip),%xmm0
jmp    11e5 <atofs+0xb5>
movsd  0xe2b(%rip),%xmm0
movsd  %xmm0,(%rsp)
mov    %r15,%rdi
call   1030 <atof@plt>
mulsd  (%rsp),%xmm0
mov    %r14b,-0x1(%r15,%rbp,1)
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r14b,-0x1(%r15,%rbp,1)
mov    %r15,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <atof@plt>

LLVM IR (-O0):
define double @atofs(i8* %0) {
%2 = alloca double
%3 = alloca i8*
%4 = alloca i8
%5 = alloca i32
%6 = alloca double
store i8* %0, i8** %3
store double 1.000000e+00, double* %6
%7 = load i8*, i8** %3
%8 = call i32 @strlen(i8* %7)
store i32 %8, i32* %5
br label %9
9: ; preds = %23, %1
%10 = load i32, i32* %5
%11 = icmp sgt i32 %10, 1
br i1 %11, label %12, label %21
12: ; preds = %9
%13 = load i8*, i8** %3
%14 = load i32, i32* %5
%15 = sub nsw i32 %14, 1
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %13, i64 %16
%18 = load i8, i8* %17
%19 = call i64 @isspace(i8 signext %18)
%20 = icmp ne i64 %19, 0
br label %21
21: ; preds = %12, %9
%22 = phi i1 [ false, %9 ], [ %20, %12 ]
br i1 %22, label %23, label %26
23: ; preds = %21
%24 = load i32, i32* %5
%25 = add nsw i32 %24, -1
store i32 %25, i32* %5
br label %9
26: ; preds = %21
%27 = load i8*, i8** %3
%28 = load i32, i32* %5
%29 = sub nsw i32 %28, 1
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %27, i64 %30
%32 = load i8, i8* %31
store i8 %32, i8* %4
%33 = load i8*, i8** %3
%34 = load i32, i32* %5
%35 = sub nsw i32 %34, 1
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %33, i64 %36
store i8 0, i8* %37
%38 = load i8, i8* %4
%39 = sext i8 %38 to i32
switch i32 %39, label %60 [
i32 103, label %40
i32 71, label %40
i32 109, label %43
i32 77, label %43
i32 107, label %46
i32 75, label %46
]
40: ; preds = %26, %26
%41 = load double, double* %6
%42 = fmul double %41, 1.000000e+03
store double %42, double* %6
br label %43
43: ; preds = %26, %26, %40
%44 = load double, double* %6
%45 = fmul double %44, 1.000000e+03
store double %45, double* %6
br label %46
46: ; preds = %26, %26, %43
%47 = load double, double* %6
%48 = fmul double %47, 1.000000e+03
store double %48, double* %6
%49 = load i8*, i8** %3
%50 = call double @atof(i8* %49)
%51 = load double, double* %6
%52 = fmul double %51, %50
store double %52, double* %6
%53 = load i8, i8* %4
%54 = load i8*, i8** %3
%55 = load i32, i32* %5
%56 = sub nsw i32 %55, 1
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i8, i8* %54, i64 %57
store i8 %53, i8* %58
%59 = load double, double* %6
store double %59, double* %2
br label %69
60: ; preds = %26
%61 = load i8, i8* %4
%62 = load i8*, i8** %3
%63 = load i32, i32* %5
%64 = sub nsw i32 %63, 1
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds i8, i8* %62, i64 %65
store i8 %61, i8* %66
%67 = load i8*, i8** %3
%68 = call double @atof(i8* %67)
store double %68, double* %2
br label %69
69: ; preds = %60, %46
%70 = load double, double* %2
ret double %70
}

LLVM IR (-O2):
define double @atofs(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = zext i32 %2 to i64
%4 = call i32 @llvm.smin.i32(i32 %2, i32 1)
br label %5
5: ; preds = %9, %1
%6 = phi i64 [ %10, %9 ], [ %3, %1 ]
%7 = trunc i64 %6 to i32
%8 = icmp sgt i32 %7, 1
br i1 %8, label %9, label %18
9: ; preds = %5
%10 = add nsw i64 %6, -1
%11 = and i64 %10, 4294967295
%12 = getelementptr inbounds i8, i8* %0, i64 %11
%13 = load i8, i8* %12
%14 = tail call i64 @isspace(i8 signext %13)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %5
16: ; preds = %9
%17 = trunc i64 %6 to i32
br label %18
18: ; preds = %5, %16
%19 = phi i32 [ %17, %16 ], [ %4, %5 ]
%20 = add nsw i32 %19, -1
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %0, i64 %21
%23 = load i8, i8* %22
store i8 0, i8* %22
%24 = sext i8 %23 to i32
switch i32 %24, label %32 [
i32 103, label %25
i32 71, label %25
i32 109, label %26
i32 77, label %26
i32 107, label %28
i32 75, label %28
]
25: ; preds = %18, %18
br label %26
26: ; preds = %18, %18, %25
%27 = phi double [ 1.000000e+06, %18 ], [ 1.000000e+06, %18 ], [ 1.000000e+09, %25 ]
br label %28
28: ; preds = %18, %18, %26
%29 = phi double [ 1.000000e+03, %18 ], [ 1.000000e+03, %18 ], [ %27, %26 ]
%30 = tail call double @atof(i8* %0)
%31 = fmul double %29, %30
store i8 %23, i8* %22
br label %34
32: ; preds = %18
store i8 %23, i8* %22
%33 = tail call double @atof(i8* %0)
br label %34
34: ; preds = %32, %28
%35 = phi double [ %33, %32 ], [ %31, %28 ]
ret double %35
}