#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 */
float atof(char *);
int field_end(char *);
float csv_get_float(char *start) {
  int length = field_end(start);
  if (length == 0)
    return 0;
  char tmp = start[length];
  start[length] = 0;
  float out = atof(start);
  start[length] = tmp;
  return out;
}


x86 assembly (clang, -O0):
<csv_get_float>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <field_end@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    114f <csv_get_float+0x2f>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    118f <csv_get_float+0x6f>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x15(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
call   1030 <atof@plt>
movss  %xmm0,-0x1c(%rbp)
mov    -0x15(%rbp),%dl
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
movss  -0x1c(%rbp),%xmm0
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<csv_get_float>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
call   1040 <field_end@plt>
test   %eax,%eax
je     114a <csv_get_float+0x2a>
movslq %eax,%r14
mov    (%rbx,%r14,1),%bpl
movb   $0x0,(%rbx,%r14,1)
mov    %rbx,%rdi
call   1030 <atof@plt>
mov    %bpl,(%rbx,%r14,1)
jmp    114d <csv_get_float+0x2d>
xorps  %xmm0,%xmm0
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define float @csv_get_float(i8* %0) {
%2 = alloca float
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8
%6 = alloca float
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = call i32 @field_end(i8* %7)
store i32 %8, i32* %4
%9 = load i32, i32* %4
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %1
store float 0.000000e+00, float* %2
br label %30
12: ; preds = %1
%13 = load i8*, i8** %3
%14 = load i32, i32* %4
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %13, i64 %15
%17 = load i8, i8* %16
store i8 %17, i8* %5
%18 = load i8*, i8** %3
%19 = load i32, i32* %4
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %18, i64 %20
store i8 0, i8* %21
%22 = load i8*, i8** %3
%23 = call float @atof(i8* %22)
store float %23, float* %6
%24 = load i8, i8* %5
%25 = load i8*, i8** %3
%26 = load i32, i32* %4
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
store i8 %24, i8* %28
%29 = load float, float* %6
store float %29, float* %2
br label %30
30: ; preds = %12, %11
%31 = load float, float* %2
ret float %31
}

LLVM IR (-O2):
define float @csv_get_float(i8* %0) {
%2 = tail call i32 @field_end(i8* %0)
%3 = icmp eq i32 %2, 0
br i1 %3, label %9, label %4
4: ; preds = %1
%5 = sext i32 %2 to i64
%6 = getelementptr inbounds i8, i8* %0, i64 %5
%7 = load i8, i8* %6
store i8 0, i8* %6
%8 = tail call float @atof(i8* %0)
store i8 %7, i8* %6
br label %9
9: ; preds = %1, %4
%10 = phi float [ %8, %4 ], [ 0.000000e+00, %1 ]
ret float %10
}