#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 myAtoF(char *, double *);
size_t strlen(char *);
int myAtoF_Len(char *s, size_t len, double *value) {
  char c_temp;
  int ierr;
  if (strlen(s) <= len) {
    return myAtoF(s, value);
  } else {
    c_temp = s[len];
    s[len] = '\0';
    ierr = myAtoF(s, value);
    s[len] = c_temp;
    return ierr;
  }
}


x86 assembly (clang, -O0):
<myAtoF_Len>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
cmp    -0x18(%rbp),%rax
ja     115c <myAtoF_Len+0x3c>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <myAtoF@plt>
mov    %eax,-0x4(%rbp)
jmp    119a <myAtoF_Len+0x7a>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x21(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <myAtoF@plt>
mov    %eax,-0x28(%rbp)
mov    -0x21(%rbp),%dl
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<myAtoF_Len>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%rbx
call   1030 <strlen@plt>
cmp    %r14,%rax
jbe    115d <myAtoF_Len+0x3d>
mov    (%rbx,%r14,1),%bpl
movb   $0x0,(%rbx,%r14,1)
mov    %rbx,%rdi
mov    %r15,%rsi
call   1040 <myAtoF@plt>
mov    %bpl,(%rbx,%r14,1)
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rbx,%rdi
mov    %r15,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <myAtoF@plt>

LLVM IR (-O0):
define i32 @myAtoF_Len(i8* %0, i64 %1, double* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca double*
%8 = alloca i8
%9 = alloca i32
store i8* %0, i8** %5
store i64 %1, i64* %6
store double* %2, double** %7
%10 = load i8*, i8** %5
%11 = call i64 @strlen(i8* %10)
%12 = load i64, i64* %6
%13 = icmp ule i64 %11, %12
br i1 %13, label %14, label %18
14: ; preds = %3
%15 = load i8*, i8** %5
%16 = load double*, double** %7
%17 = call i32 @myAtoF(i8* %15, double* %16)
store i32 %17, i32* %4
br label %34
18: ; preds = %3
%19 = load i8*, i8** %5
%20 = load i64, i64* %6
%21 = getelementptr inbounds i8, i8* %19, i64 %20
%22 = load i8, i8* %21
store i8 %22, i8* %8
%23 = load i8*, i8** %5
%24 = load i64, i64* %6
%25 = getelementptr inbounds i8, i8* %23, i64 %24
store i8 0, i8* %25
%26 = load i8*, i8** %5
%27 = load double*, double** %7
%28 = call i32 @myAtoF(i8* %26, double* %27)
store i32 %28, i32* %9
%29 = load i8, i8* %8
%30 = load i8*, i8** %5
%31 = load i64, i64* %6
%32 = getelementptr inbounds i8, i8* %30, i64 %31
store i8 %29, i8* %32
%33 = load i32, i32* %9
store i32 %33, i32* %4
br label %34
34: ; preds = %18, %14
%35 = load i32, i32* %4
ret i32 %35
}

LLVM IR (-O2):
define i32 @myAtoF_Len(i8* %0, i64 %1, double* %2) {
%4 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%5 = icmp ugt i64 %4, %1
br i1 %5, label %8, label %6
6: ; preds = %3
%7 = tail call i32 @myAtoF(i8* %0, double* %2)
br label %12
8: ; preds = %3
%9 = getelementptr inbounds i8, i8* %0, i64 %1
%10 = load i8, i8* %9
store i8 0, i8* %9
%11 = tail call i32 @myAtoF(i8* %0, double* %2)
store i8 %10, i8* %9
br label %12
12: ; preds = %8, %6
%13 = phi i32 [ %7, %6 ], [ %11, %8 ]
ret i32 %13
}