#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 sscanf(char const *, char *, float *, char *);
int extract_float(const char *s, void *dest, char **errp) {
  char dummy_buf[4096];
  float value;
  if (sscanf(s, "%f%s", &value, dummy_buf) != 1) {
    *errp = "Found trailing garbage";
    return -1;
  }
  *(float *)dest = value;
  return 0;
}


x86 assembly (clang, -O0):
<extract_float>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1030,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x1020(%rbp),%rcx
lea    0xec7(%rip),%rsi
lea    -0x1024(%rbp),%rdx
call   1030 <sscanf@plt>
cmp    $0x1,%eax
je     1168 <extract_float+0x58>
mov    -0x20(%rbp),%rax
lea    0xeac(%rip),%rcx
mov    %rcx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    117f <extract_float+0x6f>
movss  -0x1024(%rbp),%xmm0
ff
mov    -0x18(%rbp),%rax
movss  %xmm0,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<extract_float>:
push   %r14
push   %rbx
sub    $0x1018,%rsp
mov    %rdx,%r14
mov    %rsi,%rbx
lea    0xed9(%rip),%rsi
lea    0xc(%rsp),%rdx
lea    0x10(%rsp),%rcx
call   1030 <sscanf@plt>
cmp    $0x1,%eax
jne    1149 <extract_float+0x39>
movss  0xc(%rsp),%xmm0
movss  %xmm0,(%rbx)
xor    %eax,%eax
jmp    1158 <extract_float+0x48>
lea    0xeb5(%rip),%rax
mov    %rax,(%r14)
mov    $0xffffffff,%eax
add    $0x1018,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%f%s\00"
@.str.1 = [23 x i8] c"Found trailing garbage\00"
define i32 @extract_float(i8* %0, i8* %1, i8** %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8**
%8 = alloca [4096 x i8]
%9 = alloca float
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8** %2, i8*** %7
%10 = load i8*, i8** %5
%11 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%12 = call i32 @sscanf(i8* %10, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), float* %9, i8* %11)
%13 = icmp ne i32 %12, 1
br i1 %13, label %14, label %16
14: ; preds = %3
%15 = load i8**, i8*** %7
store i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8** %15
store i32 -1, i32* %4
br label %20
16: ; preds = %3
%17 = load float, float* %9
%18 = load i8*, i8** %6
%19 = bitcast i8* %18 to float*
store float %17, float* %19
store i32 0, i32* %4
br label %20
20: ; preds = %16, %14
%21 = load i32, i32* %4
ret i32 %21
}

LLVM IR (-O2):
@.str = [5 x i8] c"%f%s\00"
@.str.1 = [23 x i8] c"Found trailing garbage\00"
define i32 @extract_float(i8* nocapture %0, i8* nocapture writeonly %1, i8** nocapture writeonly %2) {
%4 = alloca [4096 x i8]
%5 = alloca float
%6 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%7 = bitcast float* %5 to i8*
%8 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), float* %5, i8* %6)
%9 = icmp eq i32 %8, 1
br i1 %9, label %11, label %10
10: ; preds = %3
store i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8** %2
br label %14
11: ; preds = %3
%12 = load float, float* %5
%13 = bitcast i8* %1 to float*
store float %12, float* %13
br label %14
14: ; preds = %11, %10
%15 = phi i32 [ -1, %10 ], [ 0, %11 ]
ret i32 %15
}