#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*/ display(int *, int);
scalar_t__ malloc(int);
int poly_add(int *, int, int *, int, int *);
int /*<<< orphan*/ poly_read(int *, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, int *);
void main() {
  int n1, n2, n3;
  int *a, *b, *c;
  printf("Enter the no.of terms in first expression: ");
  scanf("%d", &n1);
  printf("Enter the no.of terms in second expression: ");
  scanf("%d", &n2);
  a = (int *)malloc(2 * n1 * sizeof(int));
  b = (int *)malloc(2 * n2 * sizeof(int));
  c = (int *)malloc(2 * (n1 + n2) * sizeof(int));
  printf("Enter the first expression terms:");
  poly_read(a, n1);
  printf("first expression in memory: ");
  display(a, n1);
  printf("Enter the second expression terms: ");
  poly_read(b, n2);
  printf("second expression in memory: ");
  display(b, n2);
  n3 = poly_add(a, n1, b, n2, c);
  printf("Resultant expression: ");
  display(c, n3);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    0xe91(%rip),%rdi
call   1050 <printf@plt>
lea    0xeb1(%rip),%rdi
lea    -0x4(%rbp),%rsi
call   1070 <scanf@plt>
lea    0xea4(%rip),%rdi
call   1050 <printf@plt>
lea    0xe95(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1070 <scanf@plt>
mov    -0x4(%rbp),%eax
shl    $0x1,%eax
cltq
shl    $0x2,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%eax
shl    $0x1,%eax
cltq
shl    $0x2,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x4(%rbp),%eax
add    -0x8(%rbp),%eax
shl    $0x1,%eax
cltq
shl    $0x2,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
lea    0xe6d(%rip),%rdi
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x4(%rbp),%esi
call   1030 <poly_read@plt>
lea    0xe77(%rip),%rdi
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x4(%rbp),%esi
call   1040 <display@plt>
lea    0xe7c(%rip),%rdi
call   1050 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1030 <poly_read@plt>
lea    0xe88(%rip),%rdi
call   1050 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1040 <display@plt>
mov    -0x18(%rbp),%rdi
mov    -0x4(%rbp),%esi
mov    -0x20(%rbp),%rdx
mov    -0x8(%rbp),%ecx
mov    -0x28(%rbp),%r8
call   1080 <poly_add@plt>
mov    %eax,-0xc(%rbp)
lea    0xe74(%rip),%rdi
call   1050 <printf@plt>
mov    -0x28(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1040 <display@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xe90(%rip),%rdi
call   1050 <printf@plt>
lea    0xeb0(%rip),%rbx
lea    0xc(%rsp),%rsi
mov    %rbx,%rdi
call   1070 <scanf@plt>
lea    0xe9f(%rip),%rdi
call   1050 <printf@plt>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1070 <scanf@plt>
mov    0xc(%rsp),%edi
shl    $0x3,%edi
call   1060 <malloc@plt>
mov    %rax,%r15
mov    0x8(%rsp),%edi
shl    $0x3,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    0x8(%rsp),%edi
add    0xc(%rsp),%edi
shl    $0x3,%edi
call   1060 <malloc@plt>
mov    %rax,%r14
lea    0xe82(%rip),%rdi
call   1050 <printf@plt>
mov    0xc(%rsp),%esi
mov    %r15,%rdi
call   1030 <poly_read@plt>
lea    0xe8c(%rip),%rdi
call   1050 <printf@plt>
mov    0xc(%rsp),%esi
mov    %r15,%rdi
call   1040 <display@plt>
lea    0xe91(%rip),%rdi
call   1050 <printf@plt>
mov    0x8(%rsp),%esi
mov    %rbx,%rdi
call   1030 <poly_read@plt>
lea    0xe9d(%rip),%rdi
call   1050 <printf@plt>
mov    0x8(%rsp),%esi
mov    %rbx,%rdi
call   1040 <display@plt>
mov    0xc(%rsp),%esi
mov    0x8(%rsp),%ecx
mov    %r15,%rdi
mov    %rbx,%rdx
mov    %r14,%r8
call   1080 <poly_add@plt>
mov    %eax,%ebx
lea    0xe8b(%rip),%rdi
call   1050 <printf@plt>
mov    %r14,%rdi
mov    %ebx,%esi
call   1040 <display@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [44 x i8] c"Enter the no.of terms in first expression: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [45 x i8] c"Enter the no.of terms in second expression: \00"
@.str.3 = [34 x i8] c"Enter the first expression terms:\00"
@.str.4 = [29 x i8] c"first expression in memory: \00"
@.str.5 = [36 x i8] c"Enter the second expression terms: \00"
@.str.6 = [30 x i8] c"second expression in memory: \00"
@.str.7 = [23 x i8] c"Resultant expression: \00"
define void @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32*
%7 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%9 = call i32 @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0))
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%11 = load i32, i32* %1
%12 = mul nsw i32 2, %11
%13 = sext i32 %12 to i64
%14 = mul i64 %13, 4
%15 = trunc i64 %14 to i32
%16 = call i64 @malloc(i32 %15)
%17 = inttoptr i64 %16 to i32*
store i32* %17, i32** %4
%18 = load i32, i32* %2
%19 = mul nsw i32 2, %18
%20 = sext i32 %19 to i64
%21 = mul i64 %20, 4
%22 = trunc i64 %21 to i32
%23 = call i64 @malloc(i32 %22)
%24 = inttoptr i64 %23 to i32*
store i32* %24, i32** %5
%25 = load i32, i32* %1
%26 = load i32, i32* %2
%27 = add nsw i32 %25, %26
%28 = mul nsw i32 2, %27
%29 = sext i32 %28 to i64
%30 = mul i64 %29, 4
%31 = trunc i64 %30 to i32
%32 = call i64 @malloc(i32 %31)
%33 = inttoptr i64 %32 to i32*
store i32* %33, i32** %6
%34 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0))
%35 = load i32*, i32** %4
%36 = load i32, i32* %1
%37 = call i32 @poly_read(i32* %35, i32 %36)
%38 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0))
%39 = load i32*, i32** %4
%40 = load i32, i32* %1
%41 = call i32 @display(i32* %39, i32 %40)
%42 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0))
%43 = load i32*, i32** %5
%44 = load i32, i32* %2
%45 = call i32 @poly_read(i32* %43, i32 %44)
%46 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.6, i64 0, i64 0))
%47 = load i32*, i32** %5
%48 = load i32, i32* %2
%49 = call i32 @display(i32* %47, i32 %48)
%50 = load i32*, i32** %4
%51 = load i32, i32* %1
%52 = load i32*, i32** %5
%53 = load i32, i32* %2
%54 = load i32*, i32** %6
%55 = call i32 @poly_add(i32* %50, i32 %51, i32* %52, i32 %53, i32* %54)
store i32 %55, i32* %3
%56 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0))
%57 = load i32*, i32** %6
%58 = load i32, i32* %3
%59 = call i32 @display(i32* %57, i32 %58)
ret void
}

LLVM IR (-O2):
@.str = [44 x i8] c"Enter the no.of terms in first expression: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [45 x i8] c"Enter the no.of terms in second expression: \00"
@.str.3 = [34 x i8] c"Enter the first expression terms:\00"
@.str.4 = [29 x i8] c"first expression in memory: \00"
@.str.5 = [36 x i8] c"Enter the second expression terms: \00"
@.str.6 = [30 x i8] c"second expression in memory: \00"
@.str.7 = [23 x i8] c"Resultant expression: \00"
define void @main() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%7 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%9 = load i32, i32* %1
%10 = shl i32 %9, 3
%11 = call i64 @malloc(i32 %10)
%12 = inttoptr i64 %11 to i32*
%13 = load i32, i32* %2
%14 = shl i32 %13, 3
%15 = call i64 @malloc(i32 %14)
%16 = inttoptr i64 %15 to i32*
%17 = load i32, i32* %1
%18 = load i32, i32* %2
%19 = add nsw i32 %18, %17
%20 = shl i32 %19, 3
%21 = call i64 @malloc(i32 %20)
%22 = inttoptr i64 %21 to i32*
%23 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0))
%24 = load i32, i32* %1
%25 = call i32 @poly_read(i32* %12, i32 %24)
%26 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0))
%27 = load i32, i32* %1
%28 = call i32 @display(i32* %12, i32 %27)
%29 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0))
%30 = load i32, i32* %2
%31 = call i32 @poly_read(i32* %16, i32 %30)
%32 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.6, i64 0, i64 0))
%33 = load i32, i32* %2
%34 = call i32 @display(i32* %16, i32 %33)
%35 = load i32, i32* %1
%36 = load i32, i32* %2
%37 = call i32 @poly_add(i32* %12, i32 %35, i32* %16, i32 %36, i32* %22)
%38 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0))
%39 = call i32 @display(i32* %22, i32 %37)
ret void
}