#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 *);
int main() {
  int l1, l2, i;
  scanf("%d", &l1);
  char *s1 = (char *)malloc(l1 * sizeof(char));
  scanf("%d", &l2);
  char *s2 = (char *)malloc(l2 * sizeof(char));
  int a = gcd(l1, l2);
  for (i = 0; i < a; i++)
    printf("%c", *(s1 + i));
  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
call   1060 <scanf@plt>
movslq -0x8(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
lea    0xe77(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1060 <scanf@plt>
movslq -0xc(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1070 <gcd@plt>
mov    %eax,-0x24(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    11ec <main+0x9c>
mov    -0x18(%rbp),%rax
movslq -0x10(%rbp),%rcx
lea    0xe2e(%rip),%rdi
movsbl (%rax,%rcx,1),%esi
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11ba <main+0x6a>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%esi
mov    -0x24(%rbp),%edx
call   1040 <check_fact@plt>
cmp    $0x0,%rax
je     125c <main+0x10c>
mov    -0x20(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x24(%rbp),%edx
call   1040 <check_fact@plt>
cmp    $0x0,%rax
je     125c <main+0x10c>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1257 <main+0x107>
mov    -0x18(%rbp),%rax
movslq -0x10(%rbp),%rcx
lea    0xdc3(%rip),%rdi
movsbl (%rax,%rcx,1),%esi
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1225 <main+0xd5>
jmp    125c <main+0x10c>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xe9e(%rip),%rbp
lea    0x4(%rsp),%rsi
mov    %rbp,%rdi
call   1060 <scanf@plt>
mov    0x4(%rsp),%edi
call   1050 <malloc@plt>
mov    %rax,%r13
mov    %rsp,%rsi
mov    %rbp,%rdi
call   1060 <scanf@plt>
mov    (%rsp),%edi
call   1050 <malloc@plt>
mov    %rax,%r14
mov    0x4(%rsp),%edi
mov    (%rsp),%esi
call   1070 <gcd@plt>
mov    %eax,%r15d
test   %eax,%eax
jle    11c7 <main+0x77>
mov    %r15d,%ebp
xor    %ebx,%ebx
lea    0xe53(%rip),%r12
movsbl 0x0(%r13,%rbx,1),%esi
mov    %r12,%rdi
call   1030 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    11b0 <main+0x60>
mov    0x4(%rsp),%esi
mov    %r13,%rdi
mov    %r15d,%edx
call   1040 <check_fact@plt>
test   %rax,%rax
je     1217 <main+0xc7>
mov    (%rsp),%esi
mov    %r14,%rdi
mov    %r15d,%edx
call   1040 <check_fact@plt>
test   %rax,%rax
je     1217 <main+0xc7>
test   %r15d,%r15d
jle    1217 <main+0xc7>
mov    %r15d,%ebp
xor    %ebx,%ebx
lea    0xe04(%rip),%r14
nop
movsbl 0x0(%r13,%rbx,1),%esi
mov    %r14,%rdi
call   1030 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1200 <main+0xb0>
xor    %eax,%eax
add    $0x8,%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 = [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 @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 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%16 = load i32, i32* %3
%17 = sext i32 %16 to i64
%18 = mul i64 %17, 1
%19 = trunc i64 %18 to i32
%20 = call i64 @malloc(i32 %19)
%21 = inttoptr i64 %20 to i8*
store i8* %21, i8** %6
%22 = load i32, i32* %2
%23 = load i32, i32* %3
%24 = call i32 @gcd(i32 %22, i32 %23)
store i32 %24, i32* %7
store i32 0, i32* %4
br label %25
25: ; preds = %36, %0
%26 = load i32, i32* %4
%27 = load i32, i32* %7
%28 = icmp slt i32 %26, %27
br i1 %28, label %29, label %39
29: ; preds = %25
%30 = load i8*, i8** %5
%31 = load i32, i32* %4
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %30, i64 %32
%34 = load i8, i8* %33
%35 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8 signext %34)
br label %36
36: ; preds = %29
%37 = load i32, i32* %4
%38 = add nsw i32 %37, 1
store i32 %38, i32* %4
br label %25
39: ; preds = %25
%40 = load i8*, i8** %5
%41 = load i32, i32* %2
%42 = load i32, i32* %7
%43 = call i64 @check_fact(i8* %40, i32 %41, i32 %42)
%44 = icmp ne i64 %43, 0
br i1 %44, label %45, label %67
45: ; preds = %39
%46 = load i8*, i8** %6
%47 = load i32, i32* %3
%48 = load i32, i32* %7
%49 = call i64 @check_fact(i8* %46, i32 %47, i32 %48)
%50 = icmp ne i64 %49, 0
br i1 %50, label %51, label %67
51: ; preds = %45
store i32 0, i32* %4
br label %52
52: ; preds = %63, %51
%53 = load i32, i32* %4
%54 = load i32, i32* %7
%55 = icmp slt i32 %53, %54
br i1 %55, label %56, label %66
56: ; preds = %52
%57 = load i8*, i8** %5
%58 = load i32, i32* %4
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i8, i8* %57, i64 %59
%61 = load i8, i8* %60
%62 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8 signext %61)
br label %63
63: ; preds = %56
%64 = load i32, i32* %4
%65 = add nsw i32 %64, 1
store i32 %65, i32* %4
br label %52
66: ; preds = %52
br label %67
67: ; preds = %66, %45, %39
ret i32 0
}

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