#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 */
typedef int /*<<< orphan*/ m1;

/* Variables and functions */
int /*<<< orphan*/ disp(int *, int);
int /*<<< orphan*/ free(int *);
int *malloc(int);
int /*<<< orphan*/ multiply(int *, int *, int, int *);
scalar_t__ sqrt(double);
int main(int argc, char *argv[]) {
  int m1[] = {1, 1, 0, 1};
  int m2[] = {2, 2, 0, 2};
  int tot = sizeof(m1) / sizeof(int);
  int sz = (int)sqrt((double)tot);
  int *ret = malloc(tot * sizeof(int));
  multiply(m1, m2, sz, ret);
  disp(ret, sz);
  free(ret);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xe93(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xe90(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xe8d(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xe8a(%rip),%rax
mov    %rax,-0x28(%rbp)
movl   $0x4,-0x34(%rbp)
cvtsi2sdl -0x34(%rbp),%xmm0
call   1070 <sqrt@plt>
mov    %eax,-0x38(%rbp)
movslq -0x34(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x40(%rbp)
lea    -0x20(%rbp),%rdi
lea    -0x30(%rbp),%rsi
mov    -0x38(%rbp),%edx
mov    -0x40(%rbp),%rcx
call   1040 <multiply@plt>
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%esi
call   1060 <disp@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x28,%rsp
movaps 0xeb2(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xeb6(%rip),%xmm0
movaps %xmm0,(%rsp)
movsd  0xe8a(%rip),%xmm0
call   1070 <sqrt@plt>
mov    %rax,%r14
mov    $0x10,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
lea    0x10(%rsp),%rdi
mov    %rsp,%rsi
mov    %r14d,%edx
mov    %rax,%rcx
call   1040 <multiply@plt>
mov    %rbx,%rdi
mov    %r14d,%esi
call   1060 <disp@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.main.m1 = [4 x i32] [i32 1, i32 1, i32 0, i32 1]
@__const.main.m2 = [4 x i32] [i32 2, i32 2, i32 0, i32 2]
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [4 x i32]
%7 = alloca [4 x i32]
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = bitcast [4 x i32]* %6 to i8*
%12 = bitcast [4 x i32]* %7 to i8*
store i32 4, i32* %8
%13 = load i32, i32* %8
%14 = sitofp i32 %13 to double
%15 = call i64 @sqrt(double %14)
%16 = trunc i64 %15 to i32
store i32 %16, i32* %9
%17 = load i32, i32* %8
%18 = sext i32 %17 to i64
%19 = mul i64 %18, 4
%20 = trunc i64 %19 to i32
%21 = call i32* @malloc(i32 %20)
store i32* %21, i32** %10
%22 = getelementptr inbounds [4 x i32], [4 x i32]* %6, i64 0, i64 0
%23 = getelementptr inbounds [4 x i32], [4 x i32]* %7, i64 0, i64 0
%24 = load i32, i32* %9
%25 = load i32*, i32** %10
%26 = call i32 @multiply(i32* %22, i32* %23, i32 %24, i32* %25)
%27 = load i32*, i32** %10
%28 = load i32, i32* %9
%29 = call i32 @disp(i32* %27, i32 %28)
%30 = load i32*, i32** %10
%31 = call i32 @free(i32* %30)
ret i32 0
}

LLVM IR (-O2):
@__const.main.m1 = [4 x i32] [i32 1, i32 1, i32 0, i32 1]
@__const.main.m2 = [4 x i32] [i32 2, i32 2, i32 0, i32 2]
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [4 x i32]
%4 = alloca [4 x i32]
%5 = bitcast [4 x i32]* %3 to i8*
%6 = bitcast [4 x i32]* %4 to i8*
%7 = tail call i64 @sqrt(double 4.000000e+00)
%8 = trunc i64 %7 to i32
%9 = tail call i32* @malloc(i32 16)
%10 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 0
%11 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 0
%12 = call i32 @multiply(i32* %10, i32* %11, i32 %8, i32* %9)
%13 = call i32 @disp(i32* %9, i32 %8)
%14 = call i32 @free(i32* %9)
ret i32 0
}