#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 *);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
char tolower(char);
int /*<<< orphan*/ willus_mem_alloc_warn(void **, scalar_t__, char *, int);
int /*<<< orphan*/ willus_mem_free(double **, char *);
double string_atof(char *s) {
  char *p;
  int i;
  double x;
  static char *funcname = "string_atof";
  willus_mem_alloc_warn((void **)&p, strlen(s) + 1, funcname, 10);
  if (p == NULL)
    return (atof(s));
  strcpy(p, s);
  for (i = 0; p[i] != '\0'; i++)
    if (tolower(p[i]) == 'd')
      p[i] = p[i] + 1;
  x = atof(p);
  willus_mem_free((double **)&p, funcname);
  return (x);
}


x86 assembly (clang, -O0):
<string_atof>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <strlen@plt>
mov    %rax,%rsi
add    $0x1,%rsi
mov    0x2ecd(%rip),%rdx
lea    -0x18(%rbp),%rdi
mov    $0xa,%ecx
call   1030 <willus_mem_alloc_warn@plt>
cmpq   $0x0,-0x18(%rbp)
jne    11af <string_atof+0x4f>
mov    -0x10(%rbp),%rdi
call   1050 <atof@plt>
movsd  %xmm0,-0x8(%rbp)
jmp    124c <string_atof+0xec>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcpy@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     1224 <string_atof+0xc4>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1070 <tolower@plt>
movsbl %al,%eax
cmp    $0x64,%eax
jne    1211 <string_atof+0xb1>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
add    $0x1,%eax
mov    %al,%dl
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
jmp    1216 <string_atof+0xb6>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11c3 <string_atof+0x63>
mov    -0x18(%rbp),%rdi
call   1050 <atof@plt>
movsd  %xmm0,-0x28(%rbp)
lea    -0x18(%rbp),%rdi
mov    0x2e13(%rip),%rsi
call   1080 <willus_mem_free@plt>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<string_atof>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
call   1060 <strlen@plt>
lea    0x1(%rax),%rsi
lea    0xe88(%rip),%rdx
mov    %rsp,%rdi
mov    $0xa,%ecx
call   1030 <willus_mem_alloc_warn@plt>
mov    (%rsp),%rdi
test   %rdi,%rdi
je     11f9 <string_atof+0x99>
mov    %rbx,%rsi
call   1040 <strcpy@plt>
mov    (%rsp),%rdi
mov    (%rdi),%al
test   %al,%al
je     11d7 <string_atof+0x77>
xor    %ebx,%ebx
jmp    11c1 <string_atof+0x61>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    (%rsp),%rdi
movzbl 0x1(%rdi,%rbx,1),%eax
add    $0x1,%rbx
test   %al,%al
je     11d7 <string_atof+0x77>
movsbl %al,%edi
call   1070 <tolower@plt>
cmp    $0x64,%al
jne    11b0 <string_atof+0x50>
mov    (%rsp),%rax
addb   $0x1,(%rax,%rbx,1)
jmp    11b0 <string_atof+0x50>
call   1050 <atof@plt>
movsd  %xmm0,0x8(%rsp)
lea    0xe17(%rip),%rsi
mov    %rsp,%rdi
call   1080 <willus_mem_free@plt>
movsd  0x8(%rsp),%xmm0
jmp    1201 <string_atof+0xa1>
mov    %rbx,%rdi
call   1050 <atof@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@string_atof.funcname = internal global i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i32 0, i32 0)
@.str = [12 x i8] c"string_atof\00"
define double @string_atof(i8* %0) {
%2 = alloca double
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca double
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = call i64 @strlen(i8* %7)
%9 = add nsw i64 %8, 1
%10 = load i8*, i8** @string_atof.funcname
%11 = call i32 @willus_mem_alloc_warn(i8** %4, i64 %9, i8* %10, i32 10)
%12 = load i8*, i8** %4
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %17
14: ; preds = %1
%15 = load i8*, i8** %3
%16 = call double @atof(i8* %15)
store double %16, double* %2
br label %62
17: ; preds = %1
%18 = load i8*, i8** %4
%19 = load i8*, i8** %3
%20 = call i32 @strcpy(i8* %18, i8* %19)
store i32 0, i32* %5
br label %21
21: ; preds = %52, %17
%22 = load i8*, i8** %4
%23 = load i32, i32* %5
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %22, i64 %24
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %55
29: ; preds = %21
%30 = load i8*, i8** %4
%31 = load i32, i32* %5
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %30, i64 %32
%34 = load i8, i8* %33
%35 = call signext i8 @tolower(i8 signext %34)
%36 = sext i8 %35 to i32
%37 = icmp eq i32 %36, 100
br i1 %37, label %38, label %51
38: ; preds = %29
%39 = load i8*, i8** %4
%40 = load i32, i32* %5
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %39, i64 %41
%43 = load i8, i8* %42
%44 = sext i8 %43 to i32
%45 = add nsw i32 %44, 1
%46 = trunc i32 %45 to i8
%47 = load i8*, i8** %4
%48 = load i32, i32* %5
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i8, i8* %47, i64 %49
store i8 %46, i8* %50
br label %51
51: ; preds = %38, %29
br label %52
52: ; preds = %51
%53 = load i32, i32* %5
%54 = add nsw i32 %53, 1
store i32 %54, i32* %5
br label %21
55: ; preds = %21
%56 = load i8*, i8** %4
%57 = call double @atof(i8* %56)
store double %57, double* %6
%58 = bitcast i8** %4 to double**
%59 = load i8*, i8** @string_atof.funcname
%60 = call i32 @willus_mem_free(double** %58, i8* %59)
%61 = load double, double* %6
store double %61, double* %2
br label %62
62: ; preds = %55, %14
%63 = load double, double* %2
ret double %63
}

LLVM IR (-O2):
@.str = [12 x i8] c"string_atof\00"
define double @string_atof(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
%4 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%5 = add nsw i64 %4, 1
%6 = call i32 @willus_mem_alloc_warn(i8** %2, i64 %5, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 10)
%7 = load i8*, i8** %2
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = call double @atof(i8* %0)
br label %37
11: ; preds = %1
%12 = call i32 @strcpy(i8* %7, i8* %0)
%13 = load i8*, i8** %2
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 0
br i1 %15, label %32, label %16
16: ; preds = %11, %26
%17 = phi i64 [ %27, %26 ], [ 0, %11 ]
%18 = phi i8 [ %30, %26 ], [ %14, %11 ]
%19 = call signext i8 @tolower(i8 signext %18)
%20 = icmp eq i8 %19, 100
br i1 %20, label %21, label %26
21: ; preds = %16
%22 = load i8*, i8** %2
%23 = getelementptr inbounds i8, i8* %22, i64 %17
%24 = load i8, i8* %23
%25 = add i8 %24, 1
store i8 %25, i8* %23
br label %26
26: ; preds = %16, %21
%27 = add nuw i64 %17, 1
%28 = load i8*, i8** %2
%29 = getelementptr inbounds i8, i8* %28, i64 %27
%30 = load i8, i8* %29
%31 = icmp eq i8 %30, 0
br i1 %31, label %32, label %16
32: ; preds = %26, %11
%33 = phi i8* [ %13, %11 ], [ %28, %26 ]
%34 = call double @atof(i8* %33)
%35 = bitcast i8** %2 to double**
%36 = call i32 @willus_mem_free(double** %35, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %37
37: ; preds = %32, %9
%38 = phi double [ %10, %9 ], [ %34, %32 ]
ret double %38
}