#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));
  if (d < 0.)
    d = 4.;
  *((float *)(p1 + 16)) = 0.f;
  d = *((double *)(p1 + 16));
  if (d < 0.)
    d = 4.;
  *((float *)(p1 + 28)) = 0.f;
  d = *((double *)(p1 + 24));
  if (d < 0.)
    d = 4.;
  d = *((double *)(p1 + 34));
  if (d < 0.)
    d = 4.;
  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)
xorps  %xmm0,%xmm0
ucomisd -0x20(%rbp),%xmm0
jbe    11a9 <main+0x79>
movsd  0xe5c(%rip),%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)
xorps  %xmm0,%xmm0
ucomisd -0x20(%rbp),%xmm0
jbe    11de <main+0xae>
movsd  0xe27(%rip),%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)
xorps  %xmm0,%xmm0
ucomisd -0x20(%rbp),%xmm0
jbe    1213 <main+0xe3>
movsd  0xdf2(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movsd  0x22(%rax),%xmm0
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x20(%rbp),%xmm0
jbe    123c <main+0x10c>
movsd  0xdc9(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
lea    0xdd4(%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    1280 <main+0x150>
movsd  0xd85(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
lea    0xdb2(%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 double, double* %4
%22 = fcmp olt double %21, 0.000000e+00
br i1 %22, label %23, label %24
23: ; preds = %16
store double 4.000000e+00, double* %4
br label %24
24: ; preds = %23, %16
%25 = load i8*, i8** %2
%26 = getelementptr inbounds i8, i8* %25, i64 16
%27 = bitcast i8* %26 to float*
store float 0.000000e+00, float* %27
%28 = load i8*, i8** %2
%29 = getelementptr inbounds i8, i8* %28, i64 16
%30 = bitcast i8* %29 to double*
%31 = load double, double* %30
store double %31, double* %4
%32 = load double, double* %4
%33 = fcmp olt double %32, 0.000000e+00
br i1 %33, label %34, label %35
34: ; preds = %24
store double 4.000000e+00, double* %4
br label %35
35: ; preds = %34, %24
%36 = load i8*, i8** %2
%37 = getelementptr inbounds i8, i8* %36, i64 28
%38 = bitcast i8* %37 to float*
store float 0.000000e+00, float* %38
%39 = load i8*, i8** %2
%40 = getelementptr inbounds i8, i8* %39, i64 24
%41 = bitcast i8* %40 to double*
%42 = load double, double* %41
store double %42, double* %4
%43 = load double, double* %4
%44 = fcmp olt double %43, 0.000000e+00
br i1 %44, label %45, label %46
45: ; preds = %35
store double 4.000000e+00, double* %4
br label %46
46: ; preds = %45, %35
%47 = load i8*, i8** %2
%48 = getelementptr inbounds i8, i8* %47, i64 34
%49 = bitcast i8* %48 to double*
%50 = load double, double* %49
store double %50, double* %4
%51 = load double, double* %4
%52 = fcmp olt double %51, 0.000000e+00
br i1 %52, label %53, label %54
53: ; preds = %46
store double 4.000000e+00, double* %4
br label %54
54: ; preds = %53, %46
%55 = load i8*, i8** %2
%56 = call i32 @free(i8* %55)
%57 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%58 = getelementptr inbounds [2 x double], [2 x double]* %5, i64 0, i64 0
store double 0.000000e+00, double* %58
store i32 1, i32* %6
%59 = load i32, i32* %6
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds [2 x double], [2 x double]* %5, i64 0, i64 %60
%62 = load double, double* %61
%63 = fcmp olt double %62, 0.000000e+00
br i1 %63, label %64, label %65
64: ; preds = %54
store double 4.000000e+00, double* %4
br label %65
65: ; preds = %64, %54
%66 = 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
}