#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 */
scalar_t__ errno;
double strtod(char *, char **);
int set_float(float *res, char *val) {
  char *end;
  double d;
  errno = 0;
  d = strtod(val, &end);
  if (*end != '\0')
    return 1;
  if (errno != 0)
    return 1;
  *res = d;
  return 0;
}


x86 assembly (clang, -O0):
<set_float>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    0x2eb9(%rip),%rax
movq   $0x0,(%rax)
mov    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1030 <strtod@plt>
movsd  %xmm0,-0x28(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     115c <set_float+0x4c>
movl   $0x1,-0x4(%rbp)
jmp    1191 <set_float+0x81>
mov    0x2e7d(%rip),%rax
cmpq   $0x0,(%rax)
je     1179 <set_float+0x69>
movl   $0x1,-0x4(%rbp)
jmp    1191 <set_float+0x81>
movsd  -0x28(%rbp),%xmm0
cvtsd2ss %xmm0,%xmm0
mov    -0x10(%rbp),%rax
movss  %xmm0,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_float>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rax
mov    %rdi,%r14
mov    0x2ebf(%rip),%rbx
movq   $0x0,(%rbx)
mov    %rsp,%rsi
mov    %rax,%rdi
call   1030 <strtod@plt>
mov    (%rsp),%rax
cmpb   $0x0,(%rax)
mov    $0x1,%eax
jne    1152 <set_float+0x42>
cmpq   $0x0,(%rbx)
jne    1152 <set_float+0x42>
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,(%r14)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@errno = global i64 0
define i32 @set_float(float* %0, i8* %1) {
%3 = alloca i32
%4 = alloca float*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca double
store float* %0, float** %4
store i8* %1, i8** %5
store i64 0, i64* @errno
%8 = load i8*, i8** %5
%9 = call double @strtod(i8* %8, i8** %6)
store double %9, double* %7
%10 = load i8*, i8** %6
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %2
store i32 1, i32* %3
br label %23
15: ; preds = %2
%16 = load i64, i64* @errno
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %15
store i32 1, i32* %3
br label %23
19: ; preds = %15
%20 = load double, double* %7
%21 = fptrunc double %20 to float
%22 = load float*, float** %4
store float %21, float* %22
store i32 0, i32* %3
br label %23
23: ; preds = %19, %18, %14
%24 = load i32, i32* %3
ret i32 %24
}

LLVM IR (-O2):
@errno = global i64 0
define i32 @set_float(float* nocapture writeonly %0, i8* %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
store i64 0, i64* @errno
%5 = call double @strtod(i8* %1, i8** %3)
%6 = load i8*, i8** %3
%7 = load i8, i8* %6
%8 = icmp eq i8 %7, 0
%9 = load i64, i64* @errno
%10 = icmp eq i64 %9, 0
%11 = select i1 %8, i1 %10, i1 false
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = fptrunc double %5 to float
store float %13, float* %0
br label %14
14: ; preds = %2, %12
%15 = phi i32 [ 0, %12 ], [ 1, %2 ]
ret i32 %15
}