#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 opt_isvalidnumber(char *);
int /*<<< orphan*/ opt_warning(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, double);
double opt_atof(char *s) {
  int valid;
  double x;
  x = atof(s);
  valid = opt_isvalidnumber(s);
  if (!valid) {
    do {
      char gstr[1024];
      sprintf(gstr, "String [%s] is not a valid number, will use [%g]", s, x);
      opt_warning(gstr);
    } while (0);
  }
  return x;
}


x86 assembly (clang, -O0):
<opt_atof>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <atof@plt>
movsd  %xmm0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <opt_isvalidnumber@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    11a5 <opt_atof+0x65>
jmp    1178 <opt_atof+0x38>
lea    -0x420(%rbp),%rdi
mov    -0x8(%rbp),%rdx
movsd  -0x18(%rbp),%xmm0
lea    0xe71(%rip),%rsi
call   1060 <sprintf@plt>
lea    -0x420(%rbp),%rdi
call   1040 <opt_warning@plt>
jmp    11a5 <opt_atof+0x65>
movsd  -0x18(%rbp),%xmm0
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<opt_atof>:
push   %r14
push   %rbx
sub    $0x418,%rsp
mov    %rdi,%rbx
call   1030 <atof@plt>
movsd  %xmm0,0x8(%rsp)
mov    %rbx,%rdi
call   1050 <opt_isvalidnumber@plt>
test   %eax,%eax
jne    1189 <opt_atof+0x49>
lea    0xe95(%rip),%rsi
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    %rbx,%rdx
movsd  0x8(%rsp),%xmm0
call   1060 <sprintf@plt>
mov    %r14,%rdi
call   1040 <opt_warning@plt>
movsd  0x8(%rsp),%xmm0
add    $0x418,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [49 x i8] c"String [%s] is not a valid number, will use [%g]\00"
define double @opt_atof(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca double
%5 = alloca [1024 x i8]
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call double @atof(i8* %6)
store double %7, double* %4
%8 = load i8*, i8** %2
%9 = call i32 @opt_isvalidnumber(i8* %8)
store i32 %9, i32* %3
%10 = load i32, i32* %3
%11 = icmp ne i32 %10, 0
br i1 %11, label %21, label %12
12: ; preds = %1
br label %13
13: ; preds = %12
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%15 = load i8*, i8** %2
%16 = load double, double* %4
%17 = call i32 @sprintf(i8* %14, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i8* %15, double %16)
%18 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%19 = call i32 @opt_warning(i8* %18)
br label %20
20: ; preds = %13
br label %21
21: ; preds = %20, %1
%22 = load double, double* %4
ret double %22
}

LLVM IR (-O2):
@.str = [49 x i8] c"String [%s] is not a valid number, will use [%g]\00"
define double @opt_atof(i8* %0) {
%2 = alloca [1024 x i8]
%3 = tail call double @atof(i8* %0)
%4 = tail call i32 @opt_isvalidnumber(i8* %0)
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %10
6: ; preds = %1
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%8 = call i32 @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i8* %0, double %3)
%9 = call i32 @opt_warning(i8* %7)
br label %10
10: ; preds = %6, %1
ret double %3
}