#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 /*<<< orphan*/ assert(int);
float *malloc(int);
unsigned int read_floats(char const *, float *, int);
int read_v(const char *str, float **v) {
  *v = malloc(4 * sizeof(**v));
  unsigned int size = read_floats(str, *v, 4);
  assert(size >= 3);
  (*v)[3] = size >= 4 ? (*v)[3] : 1.0;
  return 0;
}


x86 assembly (clang, -O0):
<read_v>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x10,%edi
call   1050 <malloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    $0x4,%edx
call   1030 <read_floats@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x3,-0x14(%rbp)
setae  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
cmpl   $0x4,-0x14(%rbp)
jb     11a1 <read_v+0x71>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movss  0xc(%rax),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    11b3 <read_v+0x83>
movsd  0xe57(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    11b3 <read_v+0x83>
movsd  -0x20(%rbp),%xmm0
cvtsd2ss %xmm0,%xmm0
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movss  %xmm0,0xc(%rax)
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_v>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%r14
mov    $0x10,%edi
call   1050 <malloc@plt>
mov    %rax,(%rbx)
mov    %r14,%rdi
mov    %rax,%rsi
mov    $0x4,%edx
call   1030 <read_floats@plt>
mov    %eax,%ebp
xor    %edi,%edi
cmp    $0x3,%eax
setae  %dil
call   1040 <assert@plt>
mov    (%rbx),%rax
cmp    $0x4,%ebp
jb     1176 <read_v+0x46>
movss  0xc(%rax),%xmm0
jmp    117e <read_v+0x4e>
movss  0xe82(%rip),%xmm0
movss  %xmm0,0xc(%rax)
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @read_v(i8* %0, float** %1) {
%3 = alloca i8*
%4 = alloca float**
%5 = alloca i32
store i8* %0, i8** %3
store float** %1, float*** %4
%6 = call float* @malloc(i32 16)
%7 = load float**, float*** %4
store float* %6, float** %7
%8 = load i8*, i8** %3
%9 = load float**, float*** %4
%10 = load float*, float** %9
%11 = call i32 @read_floats(i8* %8, float* %10, i32 4)
store i32 %11, i32* %5
%12 = load i32, i32* %5
%13 = icmp uge i32 %12, 3
%14 = zext i1 %13 to i32
%15 = call i32 @assert(i32 %14)
%16 = load i32, i32* %5
%17 = icmp uge i32 %16, 4
br i1 %17, label %18, label %24
18: ; preds = %2
%19 = load float**, float*** %4
%20 = load float*, float** %19
%21 = getelementptr inbounds float, float* %20, i64 3
%22 = load float, float* %21
%23 = fpext float %22 to double
br label %25
24: ; preds = %2
br label %25
25: ; preds = %24, %18
%26 = phi double [ %23, %18 ], [ 1.000000e+00, %24 ]
%27 = fptrunc double %26 to float
%28 = load float**, float*** %4
%29 = load float*, float** %28
%30 = getelementptr inbounds float, float* %29, i64 3
store float %27, float* %30
ret i32 0
}

LLVM IR (-O2):
define i32 @read_v(i8* %0, float** nocapture %1) {
%3 = tail call float* @malloc(i32 16)
store float* %3, float** %1
%4 = tail call i32 @read_floats(i8* %0, float* %3, i32 4)
%5 = icmp ugt i32 %4, 2
%6 = zext i1 %5 to i32
%7 = tail call i32 @assert(i32 %6)
%8 = icmp ugt i32 %4, 3
%9 = load float*, float** %1
br i1 %8, label %10, label %13
10: ; preds = %2
%11 = getelementptr inbounds float, float* %9, i64 3
%12 = load float, float* %11
br label %13
13: ; preds = %2, %10
%14 = phi float [ %12, %10 ], [ 1.000000e+00, %2 ]
%15 = getelementptr inbounds float, float* %9, i64 3
store float %14, float* %15
ret i32 0
}