#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 *, int /*<<< orphan*/);
int /*<<< orphan*/ fsm_concat(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ fsm_concat_n(int /*<<< orphan*/, int);
int /*<<< orphan*/ fsm_cross_product(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ fsm_empty_string();
int /*<<< orphan*/ fsm_identity();
int /*<<< orphan*/ fsm_kleene_star(int /*<<< orphan*/);
int /*<<< orphan*/ fsm_lower(int /*<<< orphan*/);
struct fsm *fsm_minimize(int /*<<< orphan*/);
struct fsm *rewrite_tape_m_to_n_of_k(struct fsm *lang, int m, int n, int k) {
  return fsm_minimize(fsm_lower(fsm_compose(
      lang,
      fsm_kleene_star(fsm_concat(
          fsm_concat_n(fsm_cross_product(fsm_empty_string(), fsm_identity()),
                       m - 1),
          fsm_concat(fsm_concat_n(fsm_identity(), n - m + 1),
                     fsm_concat_n(
                         fsm_cross_product(fsm_empty_string(), fsm_identity()),
                         k - n)))))));
}


x86 assembly (clang, -O0):
<rewrite_tape_m_to_n_of_k>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1050 <fsm_empty_string@plt>
mov    %eax,-0x30(%rbp)
mov    $0x0,%al
call   1060 <fsm_identity@plt>
mov    -0x30(%rbp),%edi
mov    %eax,%esi
call   10a0 <fsm_cross_product@plt>
mov    %eax,%edi
mov    -0xc(%rbp),%esi
sub    $0x1,%esi
call   10b0 <fsm_concat_n@plt>
mov    %eax,-0x24(%rbp)
mov    $0x0,%al
call   1060 <fsm_identity@plt>
mov    %eax,%edi
mov    -0x10(%rbp),%esi
sub    -0xc(%rbp),%esi
add    $0x1,%esi
call   10b0 <fsm_concat_n@plt>
mov    %eax,-0x28(%rbp)
mov    $0x0,%al
call   1050 <fsm_empty_string@plt>
mov    %eax,-0x2c(%rbp)
mov    $0x0,%al
call   1060 <fsm_identity@plt>
mov    -0x2c(%rbp),%edi
mov    %eax,%esi
call   10a0 <fsm_cross_product@plt>
mov    %eax,%edi
mov    -0x14(%rbp),%esi
sub    -0x10(%rbp),%esi
call   10b0 <fsm_concat_n@plt>
mov    -0x28(%rbp),%edi
mov    %eax,%esi
call   1070 <fsm_concat@plt>
mov    -0x24(%rbp),%edi
mov    %eax,%esi
call   1070 <fsm_concat@plt>
mov    %eax,%edi
call   1040 <fsm_kleene_star@plt>
mov    -0x20(%rbp),%rdi
mov    %eax,%esi
call   1090 <fsm_compose@plt>
mov    %eax,%edi
call   1080 <fsm_lower@plt>
mov    %eax,%edi
call   1030 <fsm_minimize@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rewrite_tape_m_to_n_of_k>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r13d
mov    %edx,%r12d
mov    %esi,%ebx
mov    %rdi,%r14
xor    %eax,%eax
call   1050 <fsm_empty_string@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1060 <fsm_identity@plt>
mov    %ebp,%edi
mov    %eax,%esi
call   10a0 <fsm_cross_product@plt>
lea    -0x1(%rbx),%esi
mov    %eax,%edi
call   10b0 <fsm_concat_n@plt>
mov    %eax,%r15d
xor    %eax,%eax
call   1060 <fsm_identity@plt>
mov    %r12d,%esi
sub    %ebx,%esi
add    $0x1,%esi
mov    %eax,%edi
call   10b0 <fsm_concat_n@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1050 <fsm_empty_string@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1060 <fsm_identity@plt>
mov    %ebp,%edi
mov    %eax,%esi
call   10a0 <fsm_cross_product@plt>
sub    %r12d,%r13d
mov    %eax,%edi
mov    %r13d,%esi
call   10b0 <fsm_concat_n@plt>
mov    %ebx,%edi
mov    %eax,%esi
call   1070 <fsm_concat@plt>
mov    %r15d,%edi
mov    %eax,%esi
call   1070 <fsm_concat@plt>
mov    %eax,%edi
call   1040 <fsm_kleene_star@plt>
mov    %r14,%rdi
mov    %eax,%esi
call   1090 <fsm_compose@plt>
mov    %eax,%edi
call   1080 <fsm_lower@plt>
mov    %eax,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fsm_minimize@plt>

LLVM IR (-O0):
%struct.fsm = type { i32 }
define %struct.fsm* @rewrite_tape_m_to_n_of_k(%struct.fsm* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca %struct.fsm*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store %struct.fsm* %0, %struct.fsm** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%9 = load %struct.fsm*, %struct.fsm** %5
%10 = call i32 (...) @fsm_empty_string()
%11 = call i32 (...) @fsm_identity()
%12 = call i32 @fsm_cross_product(i32 %10, i32 %11)
%13 = load i32, i32* %6
%14 = sub nsw i32 %13, 1
%15 = call i32 @fsm_concat_n(i32 %12, i32 %14)
%16 = call i32 (...) @fsm_identity()
%17 = load i32, i32* %7
%18 = load i32, i32* %6
%19 = sub nsw i32 %17, %18
%20 = add nsw i32 %19, 1
%21 = call i32 @fsm_concat_n(i32 %16, i32 %20)
%22 = call i32 (...) @fsm_empty_string()
%23 = call i32 (...) @fsm_identity()
%24 = call i32 @fsm_cross_product(i32 %22, i32 %23)
%25 = load i32, i32* %8
%26 = load i32, i32* %7
%27 = sub nsw i32 %25, %26
%28 = call i32 @fsm_concat_n(i32 %24, i32 %27)
%29 = call i32 @fsm_concat(i32 %21, i32 %28)
%30 = call i32 @fsm_concat(i32 %15, i32 %29)
%31 = call i32 @fsm_kleene_star(i32 %30)
%32 = call i32 @fsm_compose(%struct.fsm* %9, i32 %31)
%33 = call i32 @fsm_lower(i32 %32)
%34 = call %struct.fsm* @fsm_minimize(i32 %33)
ret %struct.fsm* %34
}

LLVM IR (-O2):
%struct.fsm = type { i32 }
define %struct.fsm* @rewrite_tape_m_to_n_of_k(%struct.fsm* %0, i32 %1, i32 %2, i32 %3) {
%5 = tail call i32 (...) @fsm_empty_string()
%6 = tail call i32 (...) @fsm_identity()
%7 = tail call i32 @fsm_cross_product(i32 %5, i32 %6)
%8 = add nsw i32 %1, -1
%9 = tail call i32 @fsm_concat_n(i32 %7, i32 %8)
%10 = tail call i32 (...) @fsm_identity()
%11 = sub i32 1, %1
%12 = add i32 %11, %2
%13 = tail call i32 @fsm_concat_n(i32 %10, i32 %12)
%14 = tail call i32 (...) @fsm_empty_string()
%15 = tail call i32 (...) @fsm_identity()
%16 = tail call i32 @fsm_cross_product(i32 %14, i32 %15)
%17 = sub nsw i32 %3, %2
%18 = tail call i32 @fsm_concat_n(i32 %16, i32 %17)
%19 = tail call i32 @fsm_concat(i32 %13, i32 %18)
%20 = tail call i32 @fsm_concat(i32 %9, i32 %19)
%21 = tail call i32 @fsm_kleene_star(i32 %20)
%22 = tail call i32 @fsm_compose(%struct.fsm* %0, i32 %21)
%23 = tail call i32 @fsm_lower(i32 %22)
%24 = tail call %struct.fsm* @fsm_minimize(i32 %23)
ret %struct.fsm* %24
}