#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, i;
  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(n1 * sizeof(int));
  for (i = 0; i < n1; i++) {
    a[i] = (int *)malloc(2 * sizeof(int));
  }
  b = (int **)malloc(n2 * sizeof(int));
  for (i = 0; i < n2; i++) {
    b[i] = (int *)malloc(2 * sizeof(int));
  }
  c = (int **)malloc((n1 + n2) * sizeof(int));
  for (i = 0; i < (n1 + n2); i++) {
    c[i] = (int *)malloc(2 * 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>
movslq -0x4(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11ed <main+0x8d>
mov    $0x8,%edi
call   1060 <malloc@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11ba <main+0x5a>
movslq -0x8(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    123a <main+0xda>
mov    $0x8,%edi
call   1060 <malloc@plt>
mov    %rax,%rdx
mov    -0x20(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1207 <main+0xa7>
mov    -0x4(%rbp),%eax
add    -0x8(%rbp),%eax
cltq
shl    $0x2,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    -0x4(%rbp),%ecx
add    -0x8(%rbp),%ecx
cmp    %ecx,%eax
jge    1290 <main+0x130>
mov    $0x8,%edi
call   1060 <malloc@plt>
mov    %rax,%rdx
mov    -0x28(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1258 <main+0xf8>
lea    0xdc5(%rip),%rdi
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x4(%rbp),%esi
call   1030 <poly_read@plt>
lea    0xdcf(%rip),%rdi
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x4(%rbp),%esi
call   1040 <display@plt>
lea    0xdd4(%rip),%rdi
call   1050 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1030 <poly_read@plt>
lea    0xde0(%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    0xdcc(%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   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xe92(%rip),%rdi
call   1050 <printf@plt>
lea    0xeb2(%rip),%rbx
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1070 <scanf@plt>
lea    0xea3(%rip),%rdi
call   1050 <printf@plt>
lea    0x4(%rsp),%rsi
mov    %rbx,%rdi
call   1070 <scanf@plt>
mov    (%rsp),%edi
shl    $0x2,%edi
call   1060 <malloc@plt>
mov    %rax,%r14
cmpl   $0x0,(%rsp)
jle    11db <main+0x7b>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    $0x8,%edi
call   1060 <malloc@plt>
mov    %rax,(%r14,%rbx,8)
add    $0x1,%rbx
movslq (%rsp),%rax
cmp    %rax,%rbx
jl     11c0 <main+0x60>
mov    0x4(%rsp),%edi
shl    $0x2,%edi
call   1060 <malloc@plt>
mov    %rax,%r15
mov    0x4(%rsp),%edi
test   %edi,%edi
jle    121c <main+0xbc>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    $0x8,%edi
call   1060 <malloc@plt>
mov    %rax,(%r15,%rbx,8)
add    $0x1,%rbx
movslq 0x4(%rsp),%rdi
cmp    %rdi,%rbx
jl     1200 <main+0xa0>
add    (%rsp),%edi
shl    $0x2,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    0x4(%rsp),%eax
add    (%rsp),%eax
jle    1263 <main+0x103>
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
mov    $0x8,%edi
call   1060 <malloc@plt>
mov    %rax,(%rbx,%rbp,8)
add    $0x1,%rbp
movslq (%rsp),%rax
movslq 0x4(%rsp),%rcx
add    %rax,%rcx
cmp    %rcx,%rbp
jl     1240 <main+0xe0>
lea    0xdf2(%rip),%rdi
call   1050 <printf@plt>
mov    (%rsp),%esi
mov    %r14,%rdi
call   1030 <poly_read@plt>
lea    0xdfd(%rip),%rdi
call   1050 <printf@plt>
mov    (%rsp),%esi
mov    %r14,%rdi
call   1040 <display@plt>
lea    0xe03(%rip),%rdi
call   1050 <printf@plt>
mov    0x4(%rsp),%esi
mov    %r15,%rdi
call   1030 <poly_read@plt>
lea    0xe0f(%rip),%rdi
call   1050 <printf@plt>
mov    0x4(%rsp),%esi
mov    %r15,%rdi
call   1040 <display@plt>
mov    (%rsp),%esi
mov    0x4(%rsp),%ecx
mov    %r14,%rdi
mov    %r15,%rdx
mov    %rbx,%r8
call   1080 <poly_add@plt>
mov    %eax,%ebp
lea    0xdfe(%rip),%rdi
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1040 <display@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
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 = alloca i32**
%8 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%10 = call i32 @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0))
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%12 = load i32, i32* %1
%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*** %5
store i32 0, i32* %4
br label %18
18: ; preds = %29, %0
%19 = load i32, i32* %4
%20 = load i32, i32* %1
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %32
22: ; preds = %18
%23 = call i64 @malloc(i32 8)
%24 = inttoptr i64 %23 to i32*
%25 = load i32**, i32*** %5
%26 = load i32, i32* %4
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i32*, i32** %25, i64 %27
store i32* %24, i32** %28
br label %29
29: ; preds = %22
%30 = load i32, i32* %4
%31 = add nsw i32 %30, 1
store i32 %31, i32* %4
br label %18
32: ; preds = %18
%33 = load i32, i32* %2
%34 = sext i32 %33 to i64
%35 = mul i64 %34, 4
%36 = trunc i64 %35 to i32
%37 = call i64 @malloc(i32 %36)
%38 = inttoptr i64 %37 to i32**
store i32** %38, i32*** %6
store i32 0, i32* %4
br label %39
39: ; preds = %50, %32
%40 = load i32, i32* %4
%41 = load i32, i32* %2
%42 = icmp slt i32 %40, %41
br i1 %42, label %43, label %53
43: ; preds = %39
%44 = call i64 @malloc(i32 8)
%45 = inttoptr i64 %44 to i32*
%46 = load i32**, i32*** %6
%47 = load i32, i32* %4
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i32*, i32** %46, i64 %48
store i32* %45, i32** %49
br label %50
50: ; preds = %43
%51 = load i32, i32* %4
%52 = add nsw i32 %51, 1
store i32 %52, i32* %4
br label %39
53: ; preds = %39
%54 = load i32, i32* %1
%55 = load i32, i32* %2
%56 = add nsw i32 %54, %55
%57 = sext i32 %56 to i64
%58 = mul i64 %57, 4
%59 = trunc i64 %58 to i32
%60 = call i64 @malloc(i32 %59)
%61 = inttoptr i64 %60 to i32**
store i32** %61, i32*** %7
store i32 0, i32* %4
br label %62
62: ; preds = %75, %53
%63 = load i32, i32* %4
%64 = load i32, i32* %1
%65 = load i32, i32* %2
%66 = add nsw i32 %64, %65
%67 = icmp slt i32 %63, %66
br i1 %67, label %68, label %78
68: ; preds = %62
%69 = call i64 @malloc(i32 8)
%70 = inttoptr i64 %69 to i32*
%71 = load i32**, i32*** %7
%72 = load i32, i32* %4
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds i32*, i32** %71, i64 %73
store i32* %70, i32** %74
br label %75
75: ; preds = %68
%76 = load i32, i32* %4
%77 = add nsw i32 %76, 1
store i32 %77, i32* %4
br label %62
78: ; preds = %62
%79 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0))
%80 = load i32**, i32*** %5
%81 = load i32, i32* %1
%82 = call i32 @poly_read(i32** %80, i32 %81)
%83 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0))
%84 = load i32**, i32*** %5
%85 = load i32, i32* %1
%86 = call i32 @display(i32** %84, i32 %85)
%87 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0))
%88 = load i32**, i32*** %6
%89 = load i32, i32* %2
%90 = call i32 @poly_read(i32** %88, i32 %89)
%91 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.6, i64 0, i64 0))
%92 = load i32**, i32*** %6
%93 = load i32, i32* %2
%94 = call i32 @display(i32** %92, i32 %93)
%95 = load i32**, i32*** %5
%96 = load i32, i32* %1
%97 = load i32**, i32*** %6
%98 = load i32, i32* %2
%99 = load i32**, i32*** %7
%100 = call i32 @poly_add(i32** %95, i32 %96, i32** %97, i32 %98, i32** %99)
store i32 %100, i32* %3
%101 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0))
%102 = load i32**, i32*** %7
%103 = load i32, i32* %3
%104 = call i32 @display(i32** %102, i32 %103)
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, 2
%11 = call i64 @malloc(i32 %10)
%12 = inttoptr i64 %11 to i32**
%13 = load i32, i32* %1
%14 = icmp sgt i32 %13, 0
br i1 %14, label %15, label %24
15: ; preds = %0, %15
%16 = phi i64 [ %20, %15 ], [ 0, %0 ]
%17 = call i64 @malloc(i32 8)
%18 = inttoptr i64 %17 to i32*
%19 = getelementptr inbounds i32*, i32** %12, i64 %16
store i32* %18, i32** %19
%20 = add nuw nsw i64 %16, 1
%21 = load i32, i32* %1
%22 = sext i32 %21 to i64
%23 = icmp slt i64 %20, %22
br i1 %23, label %15, label %24
24: ; preds = %15, %0
%25 = load i32, i32* %2
%26 = shl i32 %25, 2
%27 = call i64 @malloc(i32 %26)
%28 = inttoptr i64 %27 to i32**
%29 = load i32, i32* %2
%30 = icmp sgt i32 %29, 0
br i1 %30, label %31, label %40
31: ; preds = %24, %31
%32 = phi i64 [ %36, %31 ], [ 0, %24 ]
%33 = call i64 @malloc(i32 8)
%34 = inttoptr i64 %33 to i32*
%35 = getelementptr inbounds i32*, i32** %28, i64 %32
store i32* %34, i32** %35
%36 = add nuw nsw i64 %32, 1
%37 = load i32, i32* %2
%38 = sext i32 %37 to i64
%39 = icmp slt i64 %36, %38
br i1 %39, label %31, label %40
40: ; preds = %31, %24
%41 = phi i32 [ %29, %24 ], [ %37, %31 ]
%42 = load i32, i32* %1
%43 = add nsw i32 %42, %41
%44 = shl i32 %43, 2
%45 = call i64 @malloc(i32 %44)
%46 = inttoptr i64 %45 to i32**
%47 = load i32, i32* %1
%48 = load i32, i32* %2
%49 = add nsw i32 %48, %47
%50 = icmp sgt i32 %49, 0
br i1 %50, label %51, label %62
51: ; preds = %40, %51
%52 = phi i64 [ %56, %51 ], [ 0, %40 ]
%53 = call i64 @malloc(i32 8)
%54 = inttoptr i64 %53 to i32*
%55 = getelementptr inbounds i32*, i32** %46, i64 %52
store i32* %54, i32** %55
%56 = add nuw nsw i64 %52, 1
%57 = load i32, i32* %1
%58 = load i32, i32* %2
%59 = add nsw i32 %58, %57
%60 = sext i32 %59 to i64
%61 = icmp slt i64 %56, %60
br i1 %61, label %51, label %62
62: ; preds = %51, %40
%63 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0))
%64 = load i32, i32* %1
%65 = call i32 @poly_read(i32** %12, i32 %64)
%66 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0))
%67 = load i32, i32* %1
%68 = call i32 @display(i32** %12, i32 %67)
%69 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0))
%70 = load i32, i32* %2
%71 = call i32 @poly_read(i32** %28, i32 %70)
%72 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.6, i64 0, i64 0))
%73 = load i32, i32* %2
%74 = call i32 @display(i32** %28, i32 %73)
%75 = load i32, i32* %1
%76 = load i32, i32* %2
%77 = call i32 @poly_add(i32** %12, i32 %75, i32** %28, i32 %76, i32** %46)
%78 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0))
%79 = call i32 @display(i32** %46, i32 %77)
ret void
}