#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 */
struct fsm {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ fsm_compose(struct fsm *, struct fsm *);
int /*<<< orphan*/ fsm_concat(struct fsm *, int /*<<< orphan*/);
struct fsm *fsm_intersect(struct fsm *, struct fsm *);
int /*<<< orphan*/ fsm_kleene_star(int /*<<< orphan*/);
struct fsm *fsm_lower(int /*<<< orphan*/);
struct fsm *fsm_minimize(struct fsm *);
struct fsm *fsm_parse_regex(char *, int /*<<< orphan*/ *, int /*<<< orphan*/ *);
struct fsm *fsm_substitute_symbol(struct fsm *, char *, char *);
int /*<<< orphan*/ fsm_symbol(char *);
struct fsm *rewrite_tape_m_to_n_of_k(int /*<<< orphan*/, int, int, int);
struct fsm *rewrite_align(struct fsm *upper, struct fsm *lower) {
  struct fsm *first, *second, *third, *align, *align2;
  first = fsm_minimize(rewrite_tape_m_to_n_of_k(
      fsm_concat(upper, fsm_kleene_star(fsm_symbol("@0@"))), 1, 1, 2));
  second = fsm_minimize(rewrite_tape_m_to_n_of_k(
      fsm_concat(lower, fsm_kleene_star(fsm_symbol("@0@"))), 2, 2, 2));
  third = fsm_minimize(
      fsm_parse_regex("~[[? ?]* \"@0@\" \"@0@\" [? ?]*]", NULL, NULL));
  align = fsm_minimize(fsm_intersect(third, fsm_intersect(first, second)));
  align = fsm_minimize(
      fsm_substitute_symbol(align, "@_IDENTITY_SYMBOL_@", "@UNK@"));
  align2 = fsm_minimize(fsm_lower(fsm_compose(
      align,
      fsm_parse_regex("[? ? | \"@UNK@\" \"@UNK@\":\"@ID@\" ]*", NULL, NULL))));
  align2 = fsm_minimize(
      fsm_substitute_symbol(align2, "@UNK@", "@_IDENTITY_SYMBOL_@"));
  return align2;
}


x86 assembly (clang, -O0):
<rewrite_align>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x58(%rbp)
lea    0xe41(%rip),%rdi
call   1050 <fsm_symbol@plt>
mov    %eax,%edi
call   1040 <fsm_kleene_star@plt>
mov    -0x58(%rbp),%rdi
mov    %eax,%esi
call   1070 <fsm_concat@plt>
mov    %eax,%edi
mov    $0x1,%edx
mov    $0x2,%ecx
mov    %edx,%esi
call   1060 <rewrite_tape_m_to_n_of_k@plt>
mov    %rax,%rdi
call   1030 <fsm_minimize@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x50(%rbp)
lea    0xdfc(%rip),%rdi
call   1050 <fsm_symbol@plt>
mov    %eax,%edi
call   1040 <fsm_kleene_star@plt>
mov    -0x50(%rbp),%rdi
mov    %eax,%esi
call   1070 <fsm_concat@plt>
mov    %eax,%edi
mov    $0x2,%ecx
mov    %ecx,%esi
mov    %ecx,%edx
call   1060 <rewrite_tape_m_to_n_of_k@plt>
mov    %rax,%rdi
call   1030 <fsm_minimize@plt>
mov    %rax,-0x20(%rbp)
lea    0xdc6(%rip),%rdi
xor    %eax,%eax
mov    %eax,%edx
mov    %rdx,%rsi
call   1090 <fsm_parse_regex@plt>
mov    %rax,%rdi
call   1030 <fsm_minimize@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   10b0 <fsm_intersect@plt>
mov    -0x48(%rbp),%rdi
mov    %rax,%rsi
call   10b0 <fsm_intersect@plt>
mov    %rax,%rdi
call   1030 <fsm_minimize@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
lea    0xd93(%rip),%rsi
lea    0xda0(%rip),%rdx
call   10c0 <fsm_substitute_symbol@plt>
mov    %rax,%rdi
call   1030 <fsm_minimize@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x40(%rbp)
lea    0xd86(%rip),%rdi
xor    %eax,%eax
mov    %eax,%edx
mov    %rdx,%rsi
call   1090 <fsm_parse_regex@plt>
mov    -0x40(%rbp),%rdi
mov    %rax,%rsi
call   10a0 <fsm_compose@plt>
mov    %eax,%edi
call   1080 <fsm_lower@plt>
mov    %rax,%rdi
call   1030 <fsm_minimize@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
lea    0xd4a(%rip),%rsi
lea    0xd2f(%rip),%rdx
call   10c0 <fsm_substitute_symbol@plt>
mov    %rax,%rdi
call   1030 <fsm_minimize@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rewrite_align>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r12
mov    %rdi,%rbx
lea    0xe4b(%rip),%r15
mov    %r15,%rdi
call   1050 <fsm_symbol@plt>
mov    %eax,%edi
call   1040 <fsm_kleene_star@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1070 <fsm_concat@plt>
mov    %eax,%edi
mov    $0x1,%esi
mov    $0x1,%edx
mov    $0x2,%ecx
call   1060 <rewrite_tape_m_to_n_of_k@plt>
mov    %rax,%rdi
call   1030 <fsm_minimize@plt>
mov    %rax,%r14
mov    %r15,%rdi
call   1050 <fsm_symbol@plt>
mov    %eax,%edi
call   1040 <fsm_kleene_star@plt>
mov    %r12,%rdi
mov    %eax,%esi
call   1070 <fsm_concat@plt>
mov    %eax,%edi
mov    $0x2,%esi
mov    $0x2,%edx
mov    $0x2,%ecx
call   1060 <rewrite_tape_m_to_n_of_k@plt>
mov    %rax,%rdi
call   1030 <fsm_minimize@plt>
mov    %rax,%r15
lea    0xdd4(%rip),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1090 <fsm_parse_regex@plt>
mov    %rax,%rdi
call   1030 <fsm_minimize@plt>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %r15,%rsi
call   10b0 <fsm_intersect@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
call   10b0 <fsm_intersect@plt>
mov    %rax,%rdi
call   1030 <fsm_minimize@plt>
lea    0xdb8(%rip),%r14
lea    0xdc5(%rip),%r15
mov    %rax,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   10c0 <fsm_substitute_symbol@plt>
mov    %rax,%rdi
call   1030 <fsm_minimize@plt>
mov    %rax,%rbx
lea    0xdab(%rip),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1090 <fsm_parse_regex@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
call   10a0 <fsm_compose@plt>
mov    %eax,%edi
call   1080 <fsm_lower@plt>
mov    %rax,%rdi
call   1030 <fsm_minimize@plt>
mov    %rax,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   10c0 <fsm_substitute_symbol@plt>
mov    %rax,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <fsm_minimize@plt>

LLVM IR (-O0):
%struct.fsm = type { i32 }
@.str = [4 x i8] c"@0@\00"
@.str.1 = [29 x i8] c"~[[? ?]* \22@0@\22 \22@0@\22 [? ?]*]\00"
@.str.2 = [20 x i8] c"@_IDENTITY_SYMBOL_@\00"
@.str.3 = [6 x i8] c"@UNK@\00"
@.str.4 = [33 x i8] c"[? ? | \22@UNK@\22 \22@UNK@\22:\22@ID@\22 ]*\00"
define %struct.fsm* @rewrite_align(%struct.fsm* %0, %struct.fsm* %1) {
%3 = alloca %struct.fsm*
%4 = alloca %struct.fsm*
%5 = alloca %struct.fsm*
%6 = alloca %struct.fsm*
%7 = alloca %struct.fsm*
%8 = alloca %struct.fsm*
%9 = alloca %struct.fsm*
store %struct.fsm* %0, %struct.fsm** %3
store %struct.fsm* %1, %struct.fsm** %4
%10 = load %struct.fsm*, %struct.fsm** %3
%11 = call i32 @fsm_symbol(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @fsm_kleene_star(i32 %11)
%13 = call i32 @fsm_concat(%struct.fsm* %10, i32 %12)
%14 = call %struct.fsm* @rewrite_tape_m_to_n_of_k(i32 %13, i32 1, i32 1, i32 2)
%15 = call %struct.fsm* @fsm_minimize(%struct.fsm* %14)
store %struct.fsm* %15, %struct.fsm** %5
%16 = load %struct.fsm*, %struct.fsm** %4
%17 = call i32 @fsm_symbol(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%18 = call i32 @fsm_kleene_star(i32 %17)
%19 = call i32 @fsm_concat(%struct.fsm* %16, i32 %18)
%20 = call %struct.fsm* @rewrite_tape_m_to_n_of_k(i32 %19, i32 2, i32 2, i32 2)
%21 = call %struct.fsm* @fsm_minimize(%struct.fsm* %20)
store %struct.fsm* %21, %struct.fsm** %6
%22 = call %struct.fsm* @fsm_parse_regex(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i32* null, i32* null)
%23 = call %struct.fsm* @fsm_minimize(%struct.fsm* %22)
store %struct.fsm* %23, %struct.fsm** %7
%24 = load %struct.fsm*, %struct.fsm** %7
%25 = load %struct.fsm*, %struct.fsm** %5
%26 = load %struct.fsm*, %struct.fsm** %6
%27 = call %struct.fsm* @fsm_intersect(%struct.fsm* %25, %struct.fsm* %26)
%28 = call %struct.fsm* @fsm_intersect(%struct.fsm* %24, %struct.fsm* %27)
%29 = call %struct.fsm* @fsm_minimize(%struct.fsm* %28)
store %struct.fsm* %29, %struct.fsm** %8
%30 = load %struct.fsm*, %struct.fsm** %8
%31 = call %struct.fsm* @fsm_substitute_symbol(%struct.fsm* %30, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%32 = call %struct.fsm* @fsm_minimize(%struct.fsm* %31)
store %struct.fsm* %32, %struct.fsm** %8
%33 = load %struct.fsm*, %struct.fsm** %8
%34 = call %struct.fsm* @fsm_parse_regex(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i32* null, i32* null)
%35 = call i32 @fsm_compose(%struct.fsm* %33, %struct.fsm* %34)
%36 = call %struct.fsm* @fsm_lower(i32 %35)
%37 = call %struct.fsm* @fsm_minimize(%struct.fsm* %36)
store %struct.fsm* %37, %struct.fsm** %9
%38 = load %struct.fsm*, %struct.fsm** %9
%39 = call %struct.fsm* @fsm_substitute_symbol(%struct.fsm* %38, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%40 = call %struct.fsm* @fsm_minimize(%struct.fsm* %39)
store %struct.fsm* %40, %struct.fsm** %9
%41 = load %struct.fsm*, %struct.fsm** %9
ret %struct.fsm* %41
}

LLVM IR (-O2):
%struct.fsm = type { i32 }
@.str = [4 x i8] c"@0@\00"
@.str.1 = [29 x i8] c"~[[? ?]* \22@0@\22 \22@0@\22 [? ?]*]\00"
@.str.2 = [20 x i8] c"@_IDENTITY_SYMBOL_@\00"
@.str.3 = [6 x i8] c"@UNK@\00"
@.str.4 = [33 x i8] c"[? ? | \22@UNK@\22 \22@UNK@\22:\22@ID@\22 ]*\00"
define %struct.fsm* @rewrite_align(%struct.fsm* %0, %struct.fsm* %1) {
%3 = tail call i32 @fsm_symbol(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32 @fsm_kleene_star(i32 %3)
%5 = tail call i32 @fsm_concat(%struct.fsm* %0, i32 %4)
%6 = tail call %struct.fsm* @rewrite_tape_m_to_n_of_k(i32 %5, i32 1, i32 1, i32 2)
%7 = tail call %struct.fsm* @fsm_minimize(%struct.fsm* %6)
%8 = tail call i32 @fsm_symbol(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 @fsm_kleene_star(i32 %8)
%10 = tail call i32 @fsm_concat(%struct.fsm* %1, i32 %9)
%11 = tail call %struct.fsm* @rewrite_tape_m_to_n_of_k(i32 %10, i32 2, i32 2, i32 2)
%12 = tail call %struct.fsm* @fsm_minimize(%struct.fsm* %11)
%13 = tail call %struct.fsm* @fsm_parse_regex(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i32* null, i32* null)
%14 = tail call %struct.fsm* @fsm_minimize(%struct.fsm* %13)
%15 = tail call %struct.fsm* @fsm_intersect(%struct.fsm* %7, %struct.fsm* %12)
%16 = tail call %struct.fsm* @fsm_intersect(%struct.fsm* %14, %struct.fsm* %15)
%17 = tail call %struct.fsm* @fsm_minimize(%struct.fsm* %16)
%18 = tail call %struct.fsm* @fsm_substitute_symbol(%struct.fsm* %17, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%19 = tail call %struct.fsm* @fsm_minimize(%struct.fsm* %18)
%20 = tail call %struct.fsm* @fsm_parse_regex(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i32* null, i32* null)
%21 = tail call i32 @fsm_compose(%struct.fsm* %19, %struct.fsm* %20)
%22 = tail call %struct.fsm* @fsm_lower(i32 %21)
%23 = tail call %struct.fsm* @fsm_minimize(%struct.fsm* %22)
%24 = tail call %struct.fsm* @fsm_substitute_symbol(%struct.fsm* %23, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%25 = tail call %struct.fsm* @fsm_minimize(%struct.fsm* %24)
ret %struct.fsm* %25
}