#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*/ exit(int);
int /*<<< orphan*/ free(double *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *);
int main(int argc, char **argv) {
  double *l1 = (double *)malloc((sizeof(double)) * 400000000);
  int i;
  if (!l1) {
    printf("cannot allocate\n");
    exit(1);
  }
  for (i = 0; i < 400000000; i++)
    l1[i] = i;
  free(l1);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0xbebc2000,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1185 <main+0x45>
lea    0xe8a(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x17d78400,-0x1c(%rbp)
jge    11b9 <main+0x79>
cvtsi2sdl -0x1c(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    118c <main+0x4c>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
mov    $0xbebc2000,%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     11e8 <main+0xa8>
movdqa 0xea4(%rip),%xmm0
mov    $0x6,%ecx
movdqa 0xea7(%rip),%xmm1
movdqa 0xeaf(%rip),%xmm2
movdqa 0xeb7(%rip),%xmm3
movdqa 0xebf(%rip),%xmm4
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movdqa %xmm0,%xmm5
cvtdq2pd %xmm0,%xmm6
paddd  %xmm1,%xmm5
cvtdq2pd %xmm5,%xmm5
movups %xmm6,-0x30(%rax,%rcx,8)
movups %xmm5,-0x20(%rax,%rcx,8)
movdqa %xmm0,%xmm5
paddd  %xmm2,%xmm5
movdqa %xmm0,%xmm6
cvtdq2pd %xmm5,%xmm5
paddd  %xmm3,%xmm6
cvtdq2pd %xmm6,%xmm6
movups %xmm5,-0x10(%rax,%rcx,8)
movups %xmm6,(%rax,%rcx,8)
paddd  %xmm4,%xmm0
add    $0x8,%rcx
cmp    $0x17d78406,%rcx
jne    1190 <main+0x50>
mov    %rax,%rdi
call   1030 <free@plt>
xor    %eax,%eax
pop    %rcx
ret
lea    0xe61(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [17 x i8] c"cannot allocate\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca double*
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i64 @malloc(i32 -1094967296)
%9 = inttoptr i64 %8 to double*
store double* %9, double** %6
%10 = load double*, double** %6
%11 = icmp ne double* %10, null
br i1 %11, label %15, label %12
12: ; preds = %2
%13 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %2
store i32 0, i32* %7
br label %16
16: ; preds = %26, %15
%17 = load i32, i32* %7
%18 = icmp slt i32 %17, 400000000
br i1 %18, label %19, label %29
19: ; preds = %16
%20 = load i32, i32* %7
%21 = sitofp i32 %20 to double
%22 = load double*, double** %6
%23 = load i32, i32* %7
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds double, double* %22, i64 %24
store double %21, double* %25
br label %26
26: ; preds = %19
%27 = load i32, i32* %7
%28 = add nsw i32 %27, 1
store i32 %28, i32* %7
br label %16
29: ; preds = %16
%30 = load double*, double** %6
%31 = call i32 @free(double* %30)
ret i32 0
}

LLVM IR (-O2):
@str = [16 x i8] c"cannot allocate\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i64 @malloc(i32 -1094967296)
%4 = inttoptr i64 %3 to double*
%5 = icmp eq i64 %3, 0
br i1 %5, label %28, label %6
6: ; preds = %2, %6
%7 = phi i64 [ %25, %6 ], [ 0, %2 ]
%8 = phi <2 x i32> [ %26, %6 ], [ <i32 0, i32 1>, %2 ]
%9 = add <2 x i32> %8, <i32 2, i32 2>
%10 = sitofp <2 x i32> %8 to <2 x double>
%11 = sitofp <2 x i32> %9 to <2 x double>
%12 = getelementptr inbounds double, double* %4, i64 %7
%13 = bitcast double* %12 to <2 x double>*
store <2 x double> %10, <2 x double>* %13
%14 = getelementptr inbounds double, double* %12, i64 2
%15 = bitcast double* %14 to <2 x double>*
store <2 x double> %11, <2 x double>* %15
%16 = or i64 %7, 4
%17 = add <2 x i32> %8, <i32 4, i32 4>
%18 = add <2 x i32> %8, <i32 6, i32 6>
%19 = sitofp <2 x i32> %17 to <2 x double>
%20 = sitofp <2 x i32> %18 to <2 x double>
%21 = getelementptr inbounds double, double* %4, i64 %16
%22 = bitcast double* %21 to <2 x double>*
store <2 x double> %19, <2 x double>* %22
%23 = getelementptr inbounds double, double* %21, i64 2
%24 = bitcast double* %23 to <2 x double>*
store <2 x double> %20, <2 x double>* %24
%25 = add nuw nsw i64 %7, 8
%26 = add <2 x i32> %8, <i32 8, i32 8>
%27 = icmp eq i64 %25, 400000000
br i1 %27, label %31, label %6
28: ; preds = %2
%29 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
%30 = tail call i32 @exit(i32 1)
unreachable
31: ; preds = %6
%32 = tail call i32 @free(double* %4)
ret i32 0
}