#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*/ free(void *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *);
int main() {
  char *p1;
  float f;
  double d;
  double da[2];
  int i;
  printf("testing floats on heap\n");
  p1 = (char *)malloc(64);
  f = *((float *)p1);
  if (f < 0.f)
    d = 4.;
  d = *((double *)(p1 + 8));
  *((float *)(p1 + 16)) = 0.f;
  d = *((double *)(p1 + 16));
  *((float *)(p1 + 28)) = 0.f;
  d = *((double *)(p1 + 24));
  d = *((double *)(p1 + 34));
  free((void *)p1);
  printf("testing floats on stack\n");
  da[0] = 0.;
  i = 1;
  if (da[i] < 0.f)
    d = 4.;
  printf("all done\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xec2(%rip),%rdi
call   1040 <printf@plt>
mov    $0x40,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movss  (%rax),%xmm0
movss  %xmm0,-0x14(%rbp)
xorps  %xmm0,%xmm0
ucomiss -0x14(%rbp),%xmm0
jbe    1180 <main+0x50>
movsd  0xe85(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
xorps  %xmm0,%xmm0
movss  %xmm0,0x10(%rax)
mov    -0x10(%rbp),%rax
movsd  0x10(%rax),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
xorps  %xmm0,%xmm0
movss  %xmm0,0x1c(%rax)
mov    -0x10(%rbp),%rax
movsd  0x18(%rax),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movsd  0x22(%rax),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
lea    0xe40(%rip),%rdi
call   1040 <printf@plt>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
movl   $0x1,-0x34(%rbp)
movslq -0x34(%rbp),%rax
xorps  %xmm0,%xmm0
ucomisd -0x30(%rbp,%rax,8),%xmm0
jbe    1214 <main+0xe4>
movsd  0xdf1(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
lea    0xe1e(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xec8(%rip),%rdi
call   1040 <puts@plt>
mov    $0x40,%edi
call   1050 <malloc@plt>
movl   $0x0,0x10(%rax)
movl   $0x0,0x1c(%rax)
mov    %rax,%rdi
call   1030 <free@plt>
lea    0xeb3(%rip),%rdi
call   1040 <puts@plt>
lea    0xebf(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [24 x i8] c"testing floats on heap\0A\00"
@.str.1 = [25 x i8] c"testing floats on stack\0A\00"
@.str.2 = [10 x i8] c"all done\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca float
%4 = alloca double
%5 = alloca [2 x double]
%6 = alloca i32
store i32 0, i32* %1
%7 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%8 = call i64 @malloc(i32 64)
%9 = inttoptr i64 %8 to i8*
store i8* %9, i8** %2
%10 = load i8*, i8** %2
%11 = bitcast i8* %10 to float*
%12 = load float, float* %11
store float %12, float* %3
%13 = load float, float* %3
%14 = fcmp olt float %13, 0.000000e+00
br i1 %14, label %15, label %16
15: ; preds = %0
store double 4.000000e+00, double* %4
br label %16
16: ; preds = %15, %0
%17 = load i8*, i8** %2
%18 = getelementptr inbounds i8, i8* %17, i64 8
%19 = bitcast i8* %18 to double*
%20 = load double, double* %19
store double %20, double* %4
%21 = load i8*, i8** %2
%22 = getelementptr inbounds i8, i8* %21, i64 16
%23 = bitcast i8* %22 to float*
store float 0.000000e+00, float* %23
%24 = load i8*, i8** %2
%25 = getelementptr inbounds i8, i8* %24, i64 16
%26 = bitcast i8* %25 to double*
%27 = load double, double* %26
store double %27, double* %4
%28 = load i8*, i8** %2
%29 = getelementptr inbounds i8, i8* %28, i64 28
%30 = bitcast i8* %29 to float*
store float 0.000000e+00, float* %30
%31 = load i8*, i8** %2
%32 = getelementptr inbounds i8, i8* %31, i64 24
%33 = bitcast i8* %32 to double*
%34 = load double, double* %33
store double %34, double* %4
%35 = load i8*, i8** %2
%36 = getelementptr inbounds i8, i8* %35, i64 34
%37 = bitcast i8* %36 to double*
%38 = load double, double* %37
store double %38, double* %4
%39 = load i8*, i8** %2
%40 = call i32 @free(i8* %39)
%41 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%42 = getelementptr inbounds [2 x double], [2 x double]* %5, i64 0, i64 0
store double 0.000000e+00, double* %42
store i32 1, i32* %6
%43 = load i32, i32* %6
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [2 x double], [2 x double]* %5, i64 0, i64 %44
%46 = load double, double* %45
%47 = fcmp olt double %46, 0.000000e+00
br i1 %47, label %48, label %49
48: ; preds = %16
store double 4.000000e+00, double* %4
br label %49
49: ; preds = %48, %16
%50 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@str = [23 x i8] c"testing floats on heap\00"
@str.3 = [24 x i8] c"testing floats on stack\00"
@str.4 = [9 x i8] c"all done\00"
define i32 @main() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
%2 = tail call i64 @malloc(i32 64)
%3 = inttoptr i64 %2 to i8*
%4 = getelementptr inbounds i8, i8* %3, i64 16
%5 = bitcast i8* %4 to float*
store float 0.000000e+00, float* %5
%6 = getelementptr inbounds i8, i8* %3, i64 28
%7 = bitcast i8* %6 to float*
store float 0.000000e+00, float* %7
%8 = tail call i32 @free(i8* %3)
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.3, i64 0, i64 0))
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str.4, i64 0, i64 0))
ret i32 0
}