#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__ memchr(char *, char, int);
int strlen(char *);
int /*<<< orphan*/ strncat(char *, char *, int);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *strtok(char *, char *);
double GetCorrectString(char string[256]) {
  char *position = (char *)memchr(string, 'E', strlen(string));
  char delimeter = '+';
  if (position == NULL) {
    char *temp = (char *)memchr(string, delimeter, strlen(string));
    if (temp == NULL) {
      delimeter = '-';
    }
    char delimeter_string[1];
    delimeter_string[0] = delimeter;
    char buffer[512];
    char *pointer = strtok(string, "+-");
    strncpy(buffer, pointer, strlen(pointer));
    strncat(buffer, "E", 1);
    strncat(buffer, delimeter_string, 1);
    pointer = strtok(NULL, "+-");
    strncat(buffer, pointer, strlen(pointer));
    return atof(buffer);
  }
  return atof(string);
}


x86 assembly (clang, -O0):
<GetCorrectString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x270,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x240(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x240(%rbp),%rdi
mov    %eax,%edx
mov    $0x45,%esi
call   1070 <memchr@plt>
mov    %rax,-0x18(%rbp)
movb   $0x2b,-0x19(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    12e1 <GetCorrectString+0x181>
mov    -0x10(%rbp),%rax
mov    %rax,-0x250(%rbp)
mov    -0x19(%rbp),%al
mov    %al,-0x241(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x250(%rbp),%rdi
mov    %eax,%edx
mov    -0x241(%rbp),%al
movsbl %al,%esi
call   1070 <memchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11f0 <GetCorrectString+0x90>
movb   $0x2d,-0x19(%rbp)
mov    -0x19(%rbp),%al
mov    %al,-0x29(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xdff(%rip),%rsi
call   1080 <strtok@plt>
mov    %rax,-0x238(%rbp)
lea    -0x230(%rbp),%rax
mov    %rax,-0x270(%rbp)
mov    -0x238(%rbp),%rax
mov    %rax,-0x268(%rbp)
mov    -0x238(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x270(%rbp),%rdi
mov    -0x268(%rbp),%rsi
mov    %eax,%edx
call   1030 <strncpy@plt>
lea    -0x230(%rbp),%rdi
lea    0xdab(%rip),%rsi
mov    $0x1,%edx
call   1060 <strncat@plt>
lea    -0x230(%rbp),%rdi
lea    -0x29(%rbp),%rsi
mov    $0x1,%edx
call   1060 <strncat@plt>
xor    %eax,%eax
mov    %eax,%edi
lea    0xd7e(%rip),%rsi
call   1080 <strtok@plt>
mov    %rax,-0x238(%rbp)
lea    -0x230(%rbp),%rax
mov    %rax,-0x260(%rbp)
mov    -0x238(%rbp),%rax
mov    %rax,-0x258(%rbp)
mov    -0x238(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x260(%rbp),%rdi
mov    -0x258(%rbp),%rsi
mov    %eax,%edx
call   1060 <strncat@plt>
lea    -0x230(%rbp),%rdi
call   1040 <atof@plt>
movsd  %xmm0,-0x8(%rbp)
jmp    12ef <GetCorrectString+0x18f>
mov    -0x10(%rbp),%rdi
call   1040 <atof@plt>
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x270,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GetCorrectString>:
push   %r15
push   %r14
push   %rbx
sub    $0x210,%rsp
mov    %rdi,%rbx
call   1050 <strlen@plt>
mov    %rbx,%rdi
mov    $0x45,%esi
mov    %eax,%edx
call   1070 <memchr@plt>
test   %rax,%rax
je     119c <GetCorrectString+0x3c>
mov    %rbx,%rdi
add    $0x210,%rsp
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <atof@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %rbx,%rdi
mov    $0x2b,%esi
mov    %eax,%edx
call   1070 <memchr@plt>
test   %rax,%rax
sete   %al
add    %al,%al
add    $0x2b,%al
mov    %al,0xf(%rsp)
lea    0xe38(%rip),%r14
mov    %rbx,%rdi
mov    %r14,%rsi
call   1080 <strtok@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <strlen@plt>
lea    0x10(%rsp),%r15
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <strncpy@plt>
lea    0xe0c(%rip),%rsi
mov    %r15,%rdi
mov    $0x1,%edx
call   1060 <strncat@plt>
lea    0xf(%rsp),%rsi
mov    %r15,%rdi
mov    $0x1,%edx
call   1060 <strncat@plt>
xor    %edi,%edi
mov    %r14,%rsi
call   1080 <strtok@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <strlen@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1060 <strncat@plt>
mov    %r15,%rdi
call   1040 <atof@plt>
add    $0x210,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"+-\00"
@.str.1 = [2 x i8] c"E\00"
define double @GetCorrectString(i8* %0) {
%2 = alloca double
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8
%6 = alloca i8*
%7 = alloca [1 x i8]
%8 = alloca [512 x i8]
%9 = alloca i8*
store i8* %0, i8** %3
%10 = load i8*, i8** %3
%11 = load i8*, i8** %3
%12 = call i32 @strlen(i8* %11)
%13 = call i64 @memchr(i8* %10, i8 signext 69, i32 %12)
%14 = inttoptr i64 %13 to i8*
store i8* %14, i8** %4
store i8 43, i8* %5
%15 = load i8*, i8** %4
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %50
17: ; preds = %1
%18 = load i8*, i8** %3
%19 = load i8, i8* %5
%20 = load i8*, i8** %3
%21 = call i32 @strlen(i8* %20)
%22 = call i64 @memchr(i8* %18, i8 signext %19, i32 %21)
%23 = inttoptr i64 %22 to i8*
store i8* %23, i8** %6
%24 = load i8*, i8** %6
%25 = icmp eq i8* %24, null
br i1 %25, label %26, label %27
26: ; preds = %17
store i8 45, i8* %5
br label %27
27: ; preds = %26, %17
%28 = load i8, i8* %5
%29 = getelementptr inbounds [1 x i8], [1 x i8]* %7, i64 0, i64 0
store i8 %28, i8* %29
%30 = load i8*, i8** %3
%31 = call i8* @strtok(i8* %30, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i8* %31, i8** %9
%32 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%33 = load i8*, i8** %9
%34 = load i8*, i8** %9
%35 = call i32 @strlen(i8* %34)
%36 = call i32 @strncpy(i8* %32, i8* %33, i32 %35)
%37 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%38 = call i32 @strncat(i8* %37, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
%39 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%40 = getelementptr inbounds [1 x i8], [1 x i8]* %7, i64 0, i64 0
%41 = call i32 @strncat(i8* %39, i8* %40, i32 1)
%42 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i8* %42, i8** %9
%43 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%44 = load i8*, i8** %9
%45 = load i8*, i8** %9
%46 = call i32 @strlen(i8* %45)
%47 = call i32 @strncat(i8* %43, i8* %44, i32 %46)
%48 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%49 = call double @atof(i8* %48)
store double %49, double* %2
br label %53
50: ; preds = %1
%51 = load i8*, i8** %3
%52 = call double @atof(i8* %51)
store double %52, double* %2
br label %53
53: ; preds = %50, %27
%54 = load double, double* %2
ret double %54
}

LLVM IR (-O2):
@.str = [3 x i8] c"+-\00"
@.str.1 = [2 x i8] c"E\00"
define double @GetCorrectString(i8* %0) {
%2 = alloca [1 x i8]
%3 = alloca [512 x i8]
%4 = tail call i32 @strlen(i8* %0)
%5 = tail call i64 @memchr(i8* %0, i8 signext 69, i32 %4)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %23
7: ; preds = %1
%8 = tail call i32 @strlen(i8* %0)
%9 = tail call i64 @memchr(i8* %0, i8 signext 43, i32 %8)
%10 = icmp eq i64 %9, 0
%11 = select i1 %10, i8 45, i8 43
%12 = getelementptr inbounds [1 x i8], [1 x i8]* %2, i64 0, i64 0
store i8 %11, i8* %12
%13 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%14 = tail call i8* @strtok(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%15 = tail call i32 @strlen(i8* %14)
%16 = call i32 @strncpy(i8* %13, i8* %14, i32 %15)
%17 = call i32 @strncat(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
%18 = call i32 @strncat(i8* %13, i8* %12, i32 1)
%19 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%20 = call i32 @strlen(i8* %19)
%21 = call i32 @strncat(i8* %13, i8* %19, i32 %20)
%22 = call double @atof(i8* %13)
br label %25
23: ; preds = %1
%24 = tail call double @atof(i8* %0)
br label %25
25: ; preds = %23, %7
%26 = phi double [ %22, %7 ], [ %24, %23 ]
ret double %26
}