#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 LongestCommonSubsequence(int *, int *, int, int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int size1, size2;
  scanf("%d", &size1);
  scanf("%d", &size2);
  int arr1[size1], arr2[size2];
  for (int i = 0; i < size1; i++) {
    scanf("%d", &arr1[i]);
  }
  for (int j = 0; j < size2; j++) {
    scanf("%d", &arr2[j]);
  }
  int l = LongestCommonSubsequence(arr1, arr2, size1, size2);
  printf("Length of Longest Common Subsequence is: %d\n", l);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
mov    %rdi,-0x50(%rbp)
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
mov    -0x50(%rbp),%rdi
lea    -0xc(%rbp),%rsi
call   1050 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
mov    -0xc(%rbp),%eax
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11e3 <main+0xb3>
mov    -0x48(%rbp),%rsi
movslq -0x2c(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe30(%rip),%rdi
call   1050 <scanf@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11ae <main+0x7e>
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    121f <main+0xef>
mov    -0x40(%rbp),%rsi
movslq -0x30(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xdf4(%rip),%rdi
call   1050 <scanf@plt>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    11ea <main+0xba>
mov    -0x40(%rbp),%rsi
mov    -0x48(%rbp),%rdi
mov    -0x8(%rbp),%edx
mov    -0xc(%rbp),%ecx
call   1040 <LongestCommonSubsequence@plt>
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%esi
lea    0xdc4(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x18(%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    $0x18,%rsp
lea    0xeb8(%rip),%rbx
lea    -0x2c(%rbp),%rsi
mov    %rbx,%rdi
call   1050 <scanf@plt>
lea    -0x30(%rbp),%rsi
mov    %rbx,%rdi
call   1050 <scanf@plt>
mov    %rsp,-0x38(%rbp)
mov    -0x2c(%rbp),%eax
mov    %rsp,%r14
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
mov    -0x30(%rbp),%ecx
mov    %rsp,%r15
lea    0xf(,%rcx,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
mov    -0x2c(%rbp),%edx
test   %edx,%edx
jle    11cf <main+0x9f>
xor    %r13d,%r13d
lea    0xe5b(%rip),%r12
mov    %r14,%rbx
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %rbx,%rsi
call   1050 <scanf@plt>
add    $0x1,%r13
movslq -0x2c(%rbp),%rdx
add    $0x4,%rbx
cmp    %rdx,%r13
jl     11b0 <main+0x80>
mov    -0x30(%rbp),%ecx
test   %ecx,%ecx
jle    11ff <main+0xcf>
xor    %r13d,%r13d
lea    0xe23(%rip),%r12
mov    %r15,%rbx
mov    %r12,%rdi
mov    %rbx,%rsi
call   1050 <scanf@plt>
add    $0x1,%r13
movslq -0x30(%rbp),%rcx
add    $0x4,%rbx
cmp    %rcx,%r13
jl     11e0 <main+0xb0>
mov    -0x2c(%rbp),%edx
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <LongestCommonSubsequence@plt>
lea    0xdf2(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
mov    -0x38(%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 = [3 x i8] c"%d\00"
@.str.1 = [45 x i8] c"Length of Longest Common Subsequence is: %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %1
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%12 = load i32, i32* %2
%13 = zext i32 %12 to i64
%14 = call i8* @llvm.stacksave()
store i8* %14, i8** %4
%15 = alloca i32, i64 %13
store i64 %13, i64* %5
%16 = load i32, i32* %3
%17 = zext i32 %16 to i64
%18 = alloca i32, i64 %17
store i64 %17, i64* %6
store i32 0, i32* %7
br label %19
19: ; preds = %28, %0
%20 = load i32, i32* %7
%21 = load i32, i32* %2
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %31
23: ; preds = %19
%24 = load i32, i32* %7
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i32, i32* %15, i64 %25
%27 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %26)
br label %28
28: ; preds = %23
%29 = load i32, i32* %7
%30 = add nsw i32 %29, 1
store i32 %30, i32* %7
br label %19
31: ; preds = %19
store i32 0, i32* %8
br label %32
32: ; preds = %41, %31
%33 = load i32, i32* %8
%34 = load i32, i32* %3
%35 = icmp slt i32 %33, %34
br i1 %35, label %36, label %44
36: ; preds = %32
%37 = load i32, i32* %8
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i32, i32* %18, i64 %38
%40 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %39)
br label %41
41: ; preds = %36
%42 = load i32, i32* %8
%43 = add nsw i32 %42, 1
store i32 %43, i32* %8
br label %32
44: ; preds = %32
%45 = load i32, i32* %2
%46 = load i32, i32* %3
%47 = call i32 @LongestCommonSubsequence(i32* %15, i32* %18, i32 %45, i32 %46)
store i32 %47, i32* %9
%48 = load i32, i32* %9
%49 = call i32 @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0), i32 %48)
store i32 0, i32* %1
%50 = load i8*, i8** %4
%51 = load i32, i32* %1
ret i32 %51
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [45 x i8] c"Length of Longest Common Subsequence is: %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%7 = load i32, i32* %1
%8 = zext i32 %7 to i64
%9 = call i8* @llvm.stacksave()
%10 = alloca i32, i64 %8
%11 = load i32, i32* %2
%12 = zext i32 %11 to i64
%13 = alloca i32, i64 %12
%14 = load i32, i32* %1
%15 = icmp sgt i32 %14, 0
br i1 %15, label %22, label %18
16: ; preds = %22
%17 = load i32, i32* %2
br label %18
18: ; preds = %16, %0
%19 = phi i32 [ %27, %16 ], [ %14, %0 ]
%20 = phi i32 [ %17, %16 ], [ %11, %0 ]
%21 = icmp sgt i32 %20, 0
br i1 %21, label %37, label %32
22: ; preds = %0, %22
%23 = phi i64 [ %26, %22 ], [ 0, %0 ]
%24 = getelementptr inbounds i32, i32* %10, i64 %23
%25 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, 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 %16
30: ; preds = %37
%31 = load i32, i32* %1
br label %32
32: ; preds = %30, %18
%33 = phi i32 [ %19, %18 ], [ %31, %30 ]
%34 = phi i32 [ %20, %18 ], [ %42, %30 ]
%35 = call i32 @LongestCommonSubsequence(i32* %10, i32* %13, i32 %33, i32 %34)
%36 = call i32 @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0), i32 %35)
ret i32 0
37: ; preds = %18, %37
%38 = phi i64 [ %41, %37 ], [ 0, %18 ]
%39 = getelementptr inbounds i32, i32* %13, i64 %38
%40 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %39)
%41 = add nuw nsw i64 %38, 1
%42 = load i32, i32* %2
%43 = sext i32 %42 to i64
%44 = icmp slt i64 %41, %43
br i1 %44, label %37, label %30
}