#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 */
scalar_t__ check_fact(char *, int, int);
int gcd(int, int);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, char);
int /*<<< orphan*/ scanf(char *, ...);
int main() {
  int l1, l2, i;
  scanf("%d", &l1);
  char *s1 = (char *)malloc(l1 * sizeof(char));
  scanf("%s", s1);
  scanf("%d", &l2);
  char *s2 = (char *)malloc(l2 * sizeof(char));
  scanf("%s", s2);
  int a = gcd(l1, l2);
  if (check_fact(s1, l1, a) && check_fact(s2, l2, a)) {
    for (i = 0; i < a; i++)
      printf("%c", *(s1 + i));
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1060 <scanf@plt>
movslq -0x8(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xe74(%rip),%rdi
mov    $0x0,%al
call   1060 <scanf@plt>
lea    0xe63(%rip),%rdi
lea    -0xc(%rbp),%rsi
mov    $0x0,%al
call   1060 <scanf@plt>
movslq -0xc(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
lea    0xe3d(%rip),%rdi
mov    $0x0,%al
call   1060 <scanf@plt>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1070 <gcd@plt>
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%esi
mov    -0x24(%rbp),%edx
call   1040 <check_fact@plt>
cmp    $0x0,%rax
je     124b <main+0xfb>
mov    -0x20(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x24(%rbp),%edx
call   1040 <check_fact@plt>
cmp    $0x0,%rax
je     124b <main+0xfb>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1246 <main+0xf6>
mov    -0x18(%rbp),%rax
movslq -0x10(%rbp),%rcx
lea    0xdd7(%rip),%rdi
movsbl (%rax,%rcx,1),%esi
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1214 <main+0xc4>
jmp    124b <main+0xfb>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xea2(%rip),%r14
lea    0x4(%rsp),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1060 <scanf@plt>
mov    0x4(%rsp),%edi
call   1050 <malloc@plt>
mov    %rax,%r15
lea    0xe83(%rip),%rbp
mov    %rbp,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
mov    %rsp,%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1060 <scanf@plt>
mov    (%rsp),%edi
call   1050 <malloc@plt>
mov    %rax,%r14
mov    %rbp,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
mov    0x4(%rsp),%edi
mov    (%rsp),%esi
call   1070 <gcd@plt>
mov    %eax,%ebp
mov    0x4(%rsp),%esi
mov    %r15,%rdi
mov    %eax,%edx
call   1040 <check_fact@plt>
test   %rax,%rax
je     1216 <main+0xc6>
mov    (%rsp),%esi
mov    %r14,%rdi
mov    %ebp,%edx
call   1040 <check_fact@plt>
test   %rax,%rax
je     1216 <main+0xc6>
test   %ebp,%ebp
jle    1216 <main+0xc6>
mov    %ebp,%ebx
xor    %ebp,%ebp
lea    0xe12(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsbl (%r15,%rbp,1),%esi
mov    %r14,%rdi
call   1030 <printf@plt>
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    1200 <main+0xb0>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [3 x i8] c"%c\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 = sext i32 %9 to i64
%11 = mul i64 %10, 1
%12 = trunc i64 %11 to i32
%13 = call i64 @malloc(i32 %12)
%14 = inttoptr i64 %13 to i8*
store i8* %14, i8** %5
%15 = load i8*, i8** %5
%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 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%18 = load i32, i32* %3
%19 = sext i32 %18 to i64
%20 = mul i64 %19, 1
%21 = trunc i64 %20 to i32
%22 = call i64 @malloc(i32 %21)
%23 = inttoptr i64 %22 to i8*
store i8* %23, i8** %6
%24 = load i8*, i8** %6
%25 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %24)
%26 = load i32, i32* %2
%27 = load i32, i32* %3
%28 = call i32 @gcd(i32 %26, i32 %27)
store i32 %28, i32* %7
%29 = load i8*, i8** %5
%30 = load i32, i32* %2
%31 = load i32, i32* %7
%32 = call i64 @check_fact(i8* %29, i32 %30, i32 %31)
%33 = icmp ne i64 %32, 0
br i1 %33, label %34, label %56
34: ; preds = %0
%35 = load i8*, i8** %6
%36 = load i32, i32* %3
%37 = load i32, i32* %7
%38 = call i64 @check_fact(i8* %35, i32 %36, i32 %37)
%39 = icmp ne i64 %38, 0
br i1 %39, label %40, label %56
40: ; preds = %34
store i32 0, i32* %4
br label %41
41: ; preds = %52, %40
%42 = load i32, i32* %4
%43 = load i32, i32* %7
%44 = icmp slt i32 %42, %43
br i1 %44, label %45, label %55
45: ; preds = %41
%46 = load i8*, i8** %5
%47 = load i32, i32* %4
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8, i8* %46, i64 %48
%50 = load i8, i8* %49
%51 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8 signext %50)
br label %52
52: ; preds = %45
%53 = load i32, i32* %4
%54 = add nsw i32 %53, 1
store i32 %54, i32* %4
br label %41
55: ; preds = %41
br label %56
56: ; preds = %55, %34, %0
ret i32 0
}

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