#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 get_len(char *);
scalar_t__ isfactor(char *, int, int);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ scanf(char *, ...);
int main() {
  int n1, n2, i;
  char *s, *t;
  scanf("%d", &n1);
  s = (char *)malloc((n1 + 1) * sizeof(char));
  scanf("%s", s);
  scanf("%d", &n2);
  t = (char *)malloc((n2 + 1) * sizeof(char));
  scanf("%s", t);
  int max = -1;
  for (i = 0; i < get_len(s) && i < get_len(t); i++) {
    if (isfactor(s, get_len(s), i + 1) && isfactor(t, get_len(t), i + 1))
      max = i;
  }
  s[max + 1] = '\0';
  printf("%s", s);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1070 <scanf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xe70(%rip),%rdi
mov    $0x0,%al
call   1070 <scanf@plt>
lea    0xe5f(%rip),%rdi
lea    -0xc(%rbp),%rsi
mov    $0x0,%al
call   1070 <scanf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
lea    0xe35(%rip),%rdi
mov    $0x0,%al
call   1070 <scanf@plt>
movl   $0xffffffff,-0x24(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <get_len@plt>
mov    -0x2c(%rbp),%ecx
mov    %eax,%edx
xor    %eax,%eax
cmp    %edx,%ecx
mov    %al,-0x25(%rbp)
jge    1220 <main+0xd0>
mov    -0x10(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <get_len@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%eax
cmp    %ecx,%eax
setl   %al
mov    %al,-0x25(%rbp)
mov    -0x25(%rbp),%al
test   $0x1,%al
jne    1230 <main+0xe0>
jmp    12a1 <main+0x151>
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <get_len@plt>
mov    -0x38(%rbp),%rdi
mov    %eax,%esi
mov    -0x10(%rbp),%edx
add    $0x1,%edx
call   1050 <isfactor@plt>
cmp    $0x0,%rax
je     128e <main+0x13e>
mov    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <get_len@plt>
mov    -0x40(%rbp),%rdi
mov    %eax,%esi
mov    -0x10(%rbp),%edx
add    $0x1,%edx
call   1050 <isfactor@plt>
cmp    $0x0,%rax
je     128e <main+0x13e>
mov    -0x10(%rbp),%eax
mov    %eax,-0x24(%rbp)
jmp    1293 <main+0x143>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11e3 <main+0x93>
mov    -0x18(%rbp),%rax
mov    -0x24(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rsi
lea    0xd46(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xe9d(%rip),%r14
xor    %ebx,%ebx
lea    0xc(%rsp),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1070 <scanf@plt>
mov    0xc(%rsp),%edi
add    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,%r15
lea    0xe79(%rip),%rbp
mov    %rbp,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
lea    0x8(%rsp),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1070 <scanf@plt>
mov    0x8(%rsp),%edi
add    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,%r14
mov    %rbp,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
mov    %r15,%rdi
call   1030 <get_len@plt>
mov    $0xffffffff,%r12d
test   %eax,%eax
jg     120e <main+0xbe>
movslq %r12d,%rax
movb   $0x0,0x1(%rax,%r15,1)
lea    0xe1f(%rip),%rdi
mov    %r15,%rsi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
call   1030 <get_len@plt>
mov    %ebp,%ebx
cmp    %eax,%ebp
jge    11d4 <main+0x84>
mov    %r14,%rdi
call   1030 <get_len@plt>
cmp    %eax,%ebx
jge    11d4 <main+0x84>
mov    %r15,%rdi
call   1030 <get_len@plt>
lea    0x1(%rbx),%ebp
mov    %r15,%rdi
mov    %eax,%esi
mov    %ebp,%edx
call   1050 <isfactor@plt>
test   %rax,%rax
je     1200 <main+0xb0>
mov    %r14,%rdi
call   1030 <get_len@plt>
mov    %r14,%rdi
mov    %eax,%esi
mov    %ebp,%edx
call   1050 <isfactor@plt>
test   %rax,%rax
cmove  %r12d,%ebx
mov    %ebx,%r12d
jmp    1200 <main+0xb0>

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [3 x i8] c"%s\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
store i32 0, i32* %1
%8 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%9 = load i32, i32* %2
%10 = add nsw i32 %9, 1
%11 = sext i32 %10 to i64
%12 = mul i64 %11, 1
%13 = trunc i64 %12 to i32
%14 = call i64 @malloc(i32 %13)
%15 = inttoptr i64 %14 to i8*
store i8* %15, i8** %5
%16 = load i8*, i8** %5
%17 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %16)
%18 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%19 = load i32, i32* %3
%20 = add nsw i32 %19, 1
%21 = sext i32 %20 to i64
%22 = mul i64 %21, 1
%23 = trunc i64 %22 to i32
%24 = call i64 @malloc(i32 %23)
%25 = inttoptr i64 %24 to i8*
store i8* %25, i8** %6
%26 = load i8*, i8** %6
%27 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %26)
store i32 -1, i32* %7
store i32 0, i32* %4
br label %28
28: ; preds = %59, %0
%29 = load i32, i32* %4
%30 = load i8*, i8** %5
%31 = call i32 @get_len(i8* %30)
%32 = icmp slt i32 %29, %31
br i1 %32, label %33, label %38
33: ; preds = %28
%34 = load i32, i32* %4
%35 = load i8*, i8** %6
%36 = call i32 @get_len(i8* %35)
%37 = icmp slt i32 %34, %36
br label %38
38: ; preds = %33, %28
%39 = phi i1 [ false, %28 ], [ %37, %33 ]
br i1 %39, label %40, label %62
40: ; preds = %38
%41 = load i8*, i8** %5
%42 = load i8*, i8** %5
%43 = call i32 @get_len(i8* %42)
%44 = load i32, i32* %4
%45 = add nsw i32 %44, 1
%46 = call i64 @isfactor(i8* %41, i32 %43, i32 %45)
%47 = icmp ne i64 %46, 0
br i1 %47, label %48, label %58
48: ; preds = %40
%49 = load i8*, i8** %6
%50 = load i8*, i8** %6
%51 = call i32 @get_len(i8* %50)
%52 = load i32, i32* %4
%53 = add nsw i32 %52, 1
%54 = call i64 @isfactor(i8* %49, i32 %51, i32 %53)
%55 = icmp ne i64 %54, 0
br i1 %55, label %56, label %58
56: ; preds = %48
%57 = load i32, i32* %4
store i32 %57, i32* %7
br label %58
58: ; preds = %56, %48, %40
br label %59
59: ; preds = %58
%60 = load i32, i32* %4
%61 = add nsw i32 %60, 1
store i32 %61, i32* %4
br label %28
62: ; preds = %38
%63 = load i8*, i8** %5
%64 = load i32, i32* %7
%65 = add nsw i32 %64, 1
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds i8, i8* %63, i64 %66
store i8 0, i8* %67
%68 = load i8*, i8** %5
%69 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %68)
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [3 x i8] c"%s\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 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%6 = load i32, i32* %1
%7 = add nsw i32 %6, 1
%8 = call i64 @malloc(i32 %7)
%9 = inttoptr i64 %8 to i8*
%10 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %9)
%11 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%12 = load i32, i32* %2
%13 = add nsw i32 %12, 1
%14 = call i64 @malloc(i32 %13)
%15 = inttoptr i64 %14 to i8*
%16 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %15)
%17 = call i32 @get_len(i8* %9)
%18 = icmp sgt i32 %17, 0
br i1 %18, label %19, label %38
19: ; preds = %0, %34
%20 = phi i32 [ %35, %34 ], [ -1, %0 ]
%21 = phi i32 [ %26, %34 ], [ 0, %0 ]
%22 = call i32 @get_len(i8* %15)
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %38
24: ; preds = %19
%25 = call i32 @get_len(i8* %9)
%26 = add nuw nsw i32 %21, 1
%27 = call i64 @isfactor(i8* %9, i32 %25, i32 %26)
%28 = icmp eq i64 %27, 0
br i1 %28, label %34, label %29
29: ; preds = %24
%30 = call i32 @get_len(i8* %15)
%31 = call i64 @isfactor(i8* %15, i32 %30, i32 %26)
%32 = icmp eq i64 %31, 0
%33 = select i1 %32, i32 %20, i32 %21
br label %34
34: ; preds = %29, %24
%35 = phi i32 [ %20, %24 ], [ %33, %29 ]
%36 = call i32 @get_len(i8* %9)
%37 = icmp slt i32 %26, %36
br i1 %37, label %19, label %38
38: ; preds = %19, %34, %0
%39 = phi i32 [ -1, %0 ], [ %35, %34 ], [ %20, %19 ]
%40 = add nsw i32 %39, 1
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %9, i64 %41
store i8 0, i8* %42
%43 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %9)
ret i32 0
}