#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*/ assign_array_(double *, int *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ malloc(int);
int /*<<< orphan*/ print_array_();
int /*<<< orphan*/ printf(char *);
int main() {
  int n, i;
  double *x;
  n = 5;
  x = (double *)malloc(sizeof(double) * n);
  if (x == NULL) {
    printf("Malloc did not success\n");
    exit(0);
  } else {
    printf("Malloc succeeded\n");
  }
  for (i = 0; i < n; i++)
    x[i] = (double)i;
  assign_array_(x, &n);
  print_array_();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x5,-0x8(%rbp)
movslq -0x8(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1197 <main+0x47>
lea    0xe75(%rip),%rdi
call   1030 <printf@plt>
xor    %edi,%edi
call   1070 <exit@plt>
lea    0xe7a(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11d6 <main+0x86>
cvtsi2sdl -0xc(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11aa <main+0x5a>
mov    -0x18(%rbp),%rdi
lea    -0x8(%rbp),%rsi
call   1060 <assign_array_@plt>
mov    $0x0,%al
call   1040 <print_array_@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
movl   $0x5,0xc(%rsp)
mov    $0x28,%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     11d6 <main+0x86>
mov    %rax,%rbx
lea    0xe8a(%rip),%rdi
call   1030 <puts@plt>
movq   $0x0,(%rbx)
movabs $0x3ff0000000000000,%rax
mov    %rax,0x8(%rbx)
movabs $0x4000000000000000,%rax
mov    %rax,0x10(%rbx)
movabs $0x4008000000000000,%rax
mov    %rax,0x18(%rbx)
movabs $0x4010000000000000,%rax
mov    %rax,0x20(%rbx)
lea    0xc(%rsp),%rsi
mov    %rbx,%rdi
call   1060 <assign_array_@plt>
xor    %eax,%eax
call   1040 <print_array_@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe34(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1070 <exit@plt>

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

LLVM IR (-O2):
@str = [17 x i8] c"Malloc succeeded\00"
@str.2 = [23 x i8] c"Malloc did not success\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
store i32 5, i32* %1
%3 = tail call i64 @malloc(i32 40)
%4 = inttoptr i64 %3 to double*
%5 = icmp eq i64 %3, 0
br i1 %5, label %6, label %9
6: ; preds = %0
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.2, i64 0, i64 0))
%8 = tail call i32 @exit(i32 0)
unreachable
9: ; preds = %0
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
store double 0.000000e+00, double* %4
%11 = getelementptr inbounds double, double* %4, i64 1
store double 1.000000e+00, double* %11
%12 = getelementptr inbounds double, double* %4, i64 2
store double 2.000000e+00, double* %12
%13 = getelementptr inbounds double, double* %4, i64 3
store double 3.000000e+00, double* %13
%14 = getelementptr inbounds double, double* %4, i64 4
store double 4.000000e+00, double* %14
%15 = call i32 @assign_array_(double* %4, i32* %1)
%16 = call i32 (...) @print_array_()
ret i32 0
}