#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*/ free(int *);
int *intersection(int *, int *, int, int, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *, ...);
int main() {
  int n1, n2, n3, i;
  printf("Enter no. of elements in array 1, 2 and 3: ");
  scanf("%d %d %d", &n1, &n2, &n3);
  int arr1[n1], arr2[n2], arr3[n3];
  printf("Enter the elements in array-1 in sorted order: \n");
  for (i = 0; i < n1; i++)
    scanf("%d", &arr1[i]);
  printf("Enter the elements in array-2 in sorted order: \n");
  for (i = 0; i < n2; i++)
    scanf("%d", &arr2[i]);
  printf("Enter the elements in array-3 in sorted order: \n");
  for (i = 0; i < n3; i++)
    scanf("%d", &arr3[i]);
  int n;
  int *arr = intersection(arr1, arr2, n1, n2, n);
  arr = intersection(arr, arr3, n, n3, n);
  printf("\nCommon elements in all 3 arrays are: \n");
  for (i = 0; i < n; i++)
    printf("%d ", arr[i]);
  free(arr);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
xor    %eax,%eax
mov    %al,-0x61(%rbp)
call   1040 <printf@plt>
mov    -0x61(%rbp),%al
lea    0xec2(%rip),%rdi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
lea    -0x10(%rbp),%rcx
call   1060 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x60(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
mov    -0xc(%rbp),%eax
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x58(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%eax
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x50(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x38(%rbp)
lea    0xe4c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    122e <main+0xee>
mov    -0x60(%rbp),%rsi
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe19(%rip),%rdi
mov    $0x0,%al
call   1060 <scanf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11f7 <main+0xb7>
lea    0xe31(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    127a <main+0x13a>
mov    -0x58(%rbp),%rsi
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xdcd(%rip),%rdi
mov    $0x0,%al
call   1060 <scanf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1243 <main+0x103>
lea    0xe16(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    12c6 <main+0x186>
mov    -0x50(%rbp),%rsi
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xd81(%rip),%rdi
mov    $0x0,%al
call   1060 <scanf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    128f <main+0x14f>
mov    -0x58(%rbp),%rsi
mov    -0x60(%rbp),%rdi
mov    -0x8(%rbp),%edx
mov    -0xc(%rbp),%ecx
mov    -0x3c(%rbp),%r8d
call   1050 <intersection@plt>
mov    -0x50(%rbp),%rsi
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rdi
mov    -0x3c(%rbp),%edx
mov    -0x10(%rbp),%ecx
mov    -0x3c(%rbp),%r8d
call   1050 <intersection@plt>
mov    %rax,-0x48(%rbp)
lea    0xdc5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x3c(%rbp),%eax
jge    1344 <main+0x204>
mov    -0x48(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xdc1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1311 <main+0x1d1>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
lea    0xe98(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xeb6(%rip),%rdi
lea    -0x34(%rbp),%rsi
lea    -0x30(%rbp),%rdx
lea    -0x2c(%rbp),%rcx
xor    %eax,%eax
call   1070 <scanf@plt>
mov    %rsp,-0x48(%rbp)
mov    -0x34(%rbp),%eax
mov    %rsp,%rcx
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    -0x30(%rbp),%eax
mov    %rsp,%r15
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
mov    -0x2c(%rbp),%eax
mov    %rsp,%r12
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
lea    0xe55(%rip),%rdi
call   1040 <puts@plt>
cmpl   $0x0,-0x34(%rbp)
jle    121e <main+0xce>
lea    0xe40(%rip),%r13
mov    -0x40(%rbp),%rbx
xor    %r14d,%r14d
nopl   0x0(%rax)
mov    %r13,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
add    $0x1,%r14
movslq -0x34(%rbp),%rax
add    $0x4,%rbx
cmp    %rax,%r14
jl     1200 <main+0xb0>
lea    0xe40(%rip),%rdi
call   1040 <puts@plt>
cmpl   $0x0,-0x30(%rbp)
jle    125e <main+0x10e>
lea    0xdfb(%rip),%r13
mov    %r15,%r14
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    %r13,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
add    $0x1,%rbx
movslq -0x30(%rbp),%rax
add    $0x4,%r14
cmp    %rax,%rbx
jl     1240 <main+0xf0>
lea    0xe30(%rip),%rdi
call   1040 <puts@plt>
cmpl   $0x0,-0x2c(%rbp)
jle    129e <main+0x14e>
lea    0xdbb(%rip),%r13
mov    %r12,%r14
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    %r13,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
add    $0x1,%rbx
movslq -0x2c(%rbp),%rax
add    $0x4,%r14
cmp    %rax,%rbx
jl     1280 <main+0x130>
mov    -0x34(%rbp),%edx
mov    -0x30(%rbp),%ecx
mov    -0x40(%rbp),%rdi
mov    %r15,%rsi
call   1060 <intersection@plt>
mov    -0x2c(%rbp),%ecx
mov    %rax,%rdi
mov    %r12,%rsi
call   1060 <intersection@plt>
mov    %rax,%rbx
lea    0xdfd(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    -0x48(%rbp),%rsp
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [44 x i8] c"Enter no. of elements in array 1, 2 and 3: \00"
@.str.1 = [9 x i8] c"%d %d %d\00"
@.str.2 = [49 x i8] c"Enter the elements in array-1 in sorted order: \0A\00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [49 x i8] c"Enter the elements in array-2 in sorted order: \0A\00"
@.str.5 = [49 x i8] c"Enter the elements in array-3 in sorted order: \0A\00"
@.str.6 = [40 x i8] c"\0ACommon elements in all 3 arrays are: \0A\00"
@.str.7 = [4 x i8] c"%d \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca i32
%11 = alloca i32*
store i32 0, i32* %1
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
%13 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32* %2, i32* %3, i32* %4)
%14 = load i32, i32* %2
%15 = zext i32 %14 to i64
%16 = call i8* @llvm.stacksave()
store i8* %16, i8** %6
%17 = alloca i32, i64 %15
store i64 %15, i64* %7
%18 = load i32, i32* %3
%19 = zext i32 %18 to i64
%20 = alloca i32, i64 %19
store i64 %19, i64* %8
%21 = load i32, i32* %4
%22 = zext i32 %21 to i64
%23 = alloca i32, i64 %22
store i64 %22, i64* %9
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %5
br label %25
25: ; preds = %34, %0
%26 = load i32, i32* %5
%27 = load i32, i32* %2
%28 = icmp slt i32 %26, %27
br i1 %28, label %29, label %37
29: ; preds = %25
%30 = load i32, i32* %5
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i32, i32* %17, i64 %31
%33 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %32)
br label %34
34: ; preds = %29
%35 = load i32, i32* %5
%36 = add nsw i32 %35, 1
store i32 %36, i32* %5
br label %25
37: ; preds = %25
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %5
br label %39
39: ; preds = %48, %37
%40 = load i32, i32* %5
%41 = load i32, i32* %3
%42 = icmp slt i32 %40, %41
br i1 %42, label %43, label %51
43: ; preds = %39
%44 = load i32, i32* %5
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i32, i32* %20, i64 %45
%47 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %46)
br label %48
48: ; preds = %43
%49 = load i32, i32* %5
%50 = add nsw i32 %49, 1
store i32 %50, i32* %5
br label %39
51: ; preds = %39
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %5
br label %53
53: ; preds = %62, %51
%54 = load i32, i32* %5
%55 = load i32, i32* %4
%56 = icmp slt i32 %54, %55
br i1 %56, label %57, label %65
57: ; preds = %53
%58 = load i32, i32* %5
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i32, i32* %23, i64 %59
%61 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %60)
br label %62
62: ; preds = %57
%63 = load i32, i32* %5
%64 = add nsw i32 %63, 1
store i32 %64, i32* %5
br label %53
65: ; preds = %53
%66 = load i32, i32* %2
%67 = load i32, i32* %3
%68 = load i32, i32* %10
%69 = call i32* @intersection(i32* %17, i32* %20, i32 %66, i32 %67, i32 %68)
store i32* %69, i32** %11
%70 = load i32*, i32** %11
%71 = load i32, i32* %10
%72 = load i32, i32* %4
%73 = load i32, i32* %10
%74 = call i32* @intersection(i32* %70, i32* %23, i32 %71, i32 %72, i32 %73)
store i32* %74, i32** %11
%75 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.6, i64 0, i64 0))
store i32 0, i32* %5
br label %76
76: ; preds = %87, %65
%77 = load i32, i32* %5
%78 = load i32, i32* %10
%79 = icmp slt i32 %77, %78
br i1 %79, label %80, label %90
80: ; preds = %76
%81 = load i32*, i32** %11
%82 = load i32, i32* %5
%83 = sext i32 %82 to i64
%84 = getelementptr inbounds i32, i32* %81, i64 %83
%85 = load i32, i32* %84
%86 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i32 %85)
br label %87
87: ; preds = %80
%88 = load i32, i32* %5
%89 = add nsw i32 %88, 1
store i32 %89, i32* %5
br label %76
90: ; preds = %76
%91 = load i32*, i32** %11
%92 = call i32 @free(i32* %91)
store i32 0, i32* %1
%93 = load i8*, i8** %6
%94 = load i32, i32* %1
ret i32 %94
}

LLVM IR (-O2):
@.str = [44 x i8] c"Enter no. of elements in array 1, 2 and 3: \00"
@.str.1 = [9 x i8] c"%d %d %d\00"
@.str.3 = [3 x i8] c"%d\00"
@str = [48 x i8] c"Enter the elements in array-1 in sorted order: \00"
@str.8 = [48 x i8] c"Enter the elements in array-2 in sorted order: \00"
@str.9 = [48 x i8] c"Enter the elements in array-3 in sorted order: \00"
@str.10 = [39 x i8] c"\0ACommon elements in all 3 arrays are: \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = bitcast i32* %1 to i8*
%5 = bitcast i32* %2 to i8*
%6 = bitcast i32* %3 to i8*
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
%8 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32* %1, i32* %2, i32* %3)
%9 = load i32, i32* %1
%10 = zext i32 %9 to i64
%11 = call i8* @llvm.stacksave()
%12 = alloca i32, i64 %10
%13 = load i32, i32* %2
%14 = zext i32 %13 to i64
%15 = alloca i32, i64 %14
%16 = load i32, i32* %3
%17 = zext i32 %16 to i64
%18 = alloca i32, i64 %17
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @str, i64 0, i64 0))
%20 = load i32, i32* %1
%21 = icmp sgt i32 %20, 0
br i1 %21, label %22, label %30
22: ; preds = %0, %22
%23 = phi i64 [ %26, %22 ], [ 0, %0 ]
%24 = getelementptr inbounds i32, i32* %12, i64 %23
%25 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %24)
%26 = add nuw nsw i64 %23, 1
%27 = load i32, i32* %1
%28 = sext i32 %27 to i64
%29 = icmp slt i64 %26, %28
br i1 %29, label %22, label %30
30: ; preds = %22, %0
%31 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @str.8, i64 0, i64 0))
%32 = load i32, i32* %2
%33 = icmp sgt i32 %32, 0
br i1 %33, label %34, label %42
34: ; preds = %30, %34
%35 = phi i64 [ %38, %34 ], [ 0, %30 ]
%36 = getelementptr inbounds i32, i32* %15, i64 %35
%37 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %36)
%38 = add nuw nsw i64 %35, 1
%39 = load i32, i32* %2
%40 = sext i32 %39 to i64
%41 = icmp slt i64 %38, %40
br i1 %41, label %34, label %42
42: ; preds = %34, %30
%43 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @str.9, i64 0, i64 0))
%44 = load i32, i32* %3
%45 = icmp sgt i32 %44, 0
br i1 %45, label %46, label %54
46: ; preds = %42, %46
%47 = phi i64 [ %50, %46 ], [ 0, %42 ]
%48 = getelementptr inbounds i32, i32* %18, i64 %47
%49 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %48)
%50 = add nuw nsw i64 %47, 1
%51 = load i32, i32* %3
%52 = sext i32 %51 to i64
%53 = icmp slt i64 %50, %52
br i1 %53, label %46, label %54
54: ; preds = %46, %42
%55 = load i32, i32* %1
%56 = load i32, i32* %2
%57 = call i32* @intersection(i32* %12, i32* %15, i32 %55, i32 %56, i32 undef)
%58 = load i32, i32* %3
%59 = call i32* @intersection(i32* %57, i32* %18, i32 undef, i32 %58, i32 undef)
%60 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str.10, i64 0, i64 0))
%61 = call i32 @free(i32* %59)
ret i32 0
}