#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*/ function_alloc_in_c(int *, double **, int *, double **);
double *malloc(int);
int /*<<< orphan*/ printf(char *, double);
void run_test_b() {
  int i;
  double *a1;
  double *a2;
  int n1 = 3;
  int n2 = 4;
  a1 = malloc(sizeof(double) * n1);
  a2 = malloc(sizeof(double) * n2);
  function_alloc_in_c(&n1, (double **)&a1, &n2, (double **)&a2);
  for (i = 0; i < n1; i++) {
    printf("a1: %f\n", a1[i]);
  }
  for (i = 0; i < n2; i++) {
    printf("a2: %f\n", a2[i]);
  }
}


x86 assembly (clang, -O0):
<run_test_b>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x3,-0x1c(%rbp)
movl   $0x4,-0x20(%rbp)
movslq -0x1c(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
movslq -0x20(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
lea    -0x1c(%rbp),%rdi
lea    -0x10(%rbp),%rsi
lea    -0x20(%rbp),%rdx
lea    -0x18(%rbp),%rcx
call   1030 <function_alloc_in_c@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11bb <run_test_b+0x8b>
mov    -0x10(%rbp),%rax
movslq -0x4(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xe58(%rip),%rdi
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1188 <run_test_b+0x58>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    11f5 <run_test_b+0xc5>
mov    -0x18(%rbp),%rax
movslq -0x4(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xe26(%rip),%rdi
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    11c2 <run_test_b+0x92>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<run_test_b>:
push   %r14
push   %rbx
sub    $0x18,%rsp
movl   $0x3,0x4(%rsp)
movl   $0x4,(%rsp)
mov    $0x18,%edi
call   1050 <malloc@plt>
mov    %rax,0x10(%rsp)
mov    $0x20,%edi
call   1050 <malloc@plt>
mov    %rax,0x8(%rsp)
lea    0x4(%rsp),%rdi
lea    0x10(%rsp),%rsi
mov    %rsp,%rdx
lea    0x8(%rsp),%rcx
call   1030 <function_alloc_in_c@plt>
cmpl   $0x0,0x4(%rsp)
jle    11b0 <run_test_b+0x80>
xor    %ebx,%ebx
lea    0xe75(%rip),%r14
nopl   0x0(%rax,%rax,1)
mov    0x10(%rsp),%rax
movsd  (%rax,%rbx,8),%xmm0
mov    %r14,%rdi
call   1040 <printf@plt>
add    $0x1,%rbx
movslq 0x4(%rsp),%rax
cmp    %rax,%rbx
jl     1190 <run_test_b+0x60>
cmpl   $0x0,(%rsp)
jle    11df <run_test_b+0xaf>
xor    %ebx,%ebx
lea    0xe49(%rip),%r14
nop
mov    0x8(%rsp),%rax
movsd  (%rax,%rbx,8),%xmm0
mov    %r14,%rdi
call   1040 <printf@plt>
add    $0x1,%rbx
movslq (%rsp),%rax
cmp    %rax,%rbx
jl     11c0 <run_test_b+0x90>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [8 x i8] c"a1: %f\0A\00"
@.str.1 = [8 x i8] c"a2: %f\0A\00"
define void @run_test_b() {
%1 = alloca i32
%2 = alloca double*
%3 = alloca double*
%4 = alloca i32
%5 = alloca i32
store i32 3, i32* %4
store i32 4, i32* %5
%6 = load i32, i32* %4
%7 = sext i32 %6 to i64
%8 = mul i64 8, %7
%9 = trunc i64 %8 to i32
%10 = call double* @malloc(i32 %9)
store double* %10, double** %2
%11 = load i32, i32* %5
%12 = sext i32 %11 to i64
%13 = mul i64 8, %12
%14 = trunc i64 %13 to i32
%15 = call double* @malloc(i32 %14)
store double* %15, double** %3
%16 = call i32 @function_alloc_in_c(i32* %4, double** %2, i32* %5, double** %3)
store i32 0, i32* %1
br label %17
17: ; preds = %28, %0
%18 = load i32, i32* %1
%19 = load i32, i32* %4
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %31
21: ; preds = %17
%22 = load double*, double** %2
%23 = load i32, i32* %1
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds double, double* %22, i64 %24
%26 = load double, double* %25
%27 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), double %26)
br label %28
28: ; preds = %21
%29 = load i32, i32* %1
%30 = add nsw i32 %29, 1
store i32 %30, i32* %1
br label %17
31: ; preds = %17
store i32 0, i32* %1
br label %32
32: ; preds = %43, %31
%33 = load i32, i32* %1
%34 = load i32, i32* %5
%35 = icmp slt i32 %33, %34
br i1 %35, label %36, label %46
36: ; preds = %32
%37 = load double*, double** %3
%38 = load i32, i32* %1
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds double, double* %37, i64 %39
%41 = load double, double* %40
%42 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), double %41)
br label %43
43: ; preds = %36
%44 = load i32, i32* %1
%45 = add nsw i32 %44, 1
store i32 %45, i32* %1
br label %32
46: ; preds = %32
ret void
}

LLVM IR (-O2):
@.str = [8 x i8] c"a1: %f\0A\00"
@.str.1 = [8 x i8] c"a2: %f\0A\00"
define void @run_test_b() {
%1 = alloca double*
%2 = alloca double*
%3 = alloca i32
%4 = alloca i32
%5 = bitcast double** %1 to i8*
%6 = bitcast double** %2 to i8*
%7 = bitcast i32* %3 to i8*
store i32 3, i32* %3
%8 = bitcast i32* %4 to i8*
store i32 4, i32* %4
%9 = tail call double* @malloc(i32 24)
store double* %9, double** %1
%10 = tail call double* @malloc(i32 32)
store double* %10, double** %2
%11 = call i32 @function_alloc_in_c(i32* %3, double** %1, i32* %4, double** %2)
%12 = load i32, i32* %3
%13 = icmp sgt i32 %12, 0
br i1 %13, label %17, label %14
14: ; preds = %17, %0
%15 = load i32, i32* %4
%16 = icmp sgt i32 %15, 0
br i1 %16, label %27, label %37
17: ; preds = %0, %17
%18 = phi i64 [ %23, %17 ], [ 0, %0 ]
%19 = load double*, double** %1
%20 = getelementptr inbounds double, double* %19, i64 %18
%21 = load double, double* %20
%22 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), double %21)
%23 = add nuw nsw i64 %18, 1
%24 = load i32, i32* %3
%25 = sext i32 %24 to i64
%26 = icmp slt i64 %23, %25
br i1 %26, label %17, label %14
27: ; preds = %14, %27
%28 = phi i64 [ %33, %27 ], [ 0, %14 ]
%29 = load double*, double** %2
%30 = getelementptr inbounds double, double* %29, i64 %28
%31 = load double, double* %30
%32 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), double %31)
%33 = add nuw nsw i64 %28, 1
%34 = load i32, i32* %4
%35 = sext i32 %34 to i64
%36 = icmp slt i64 %33, %35
br i1 %36, label %27, label %37
37: ; preds = %27, %14
ret void
}