#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int get_num_in_zone(int, int, int, int, int, int);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ write_tetrs(int /*<<< orphan*/ *, int, int, int, int, int,
                               int);
int main() {
  FILE *file;
  char file_name[50];
  int N = 4;
  int M = 10;
  for (int n = 0; n < N; n++) {
    sprintf(file_name, "cube-zone-%d.zmsh", n);
    file = fopen(file_name, "w");
    int last_k_num = -1;
    if (n == 0 || n == N - 1) {
      last_k_num = M - 1;
    } else {
      last_k_num = M;
    }
    int num_of_layers = M;
    if (n != 0)
      num_of_layers++;
    if (n != N - 1)
      num_of_layers++;
    fprintf(file, "$MeshFormat\n2 0 8\n$EndMeshFormat\n$Nodes\n%d\n",
            N * M * N * M * num_of_layers);
    int num = 0;
    int cur_num;
    int rem_num;
    int k;
    k = n * M - 1;
    for (int j = 0; j < N * M; j++)
      for (int i = 0; i < N * M; i++) {
        rem_num = get_num_in_zone(i, j, k, n - 1, N, M);
        cur_num = get_num_in_zone(i, j, k, n, N, M);
        if (cur_num >= 0 && rem_num >= 0)
          fprintf(file, "%d %d %d\n", -cur_num, n - 1, rem_num);
      }
    for (int k = n * M; k < (n + 1) * M; k++)
      for (int j = 0; j < N * M; j++)
        for (int i = 0; i < N * M; i++) {
          cur_num = get_num_in_zone(i, j, k, n, N, M);
          if (cur_num >= 0)
            fprintf(file, "%d %d %d %d\n", cur_num, i, j, k);
        }
    k = (n + 1) * M;
    for (int j = 0; j < N * M; j++)
      for (int i = 0; i < N * M; i++) {
        rem_num = get_num_in_zone(i, j, k, n + 1, N, M);
        cur_num = get_num_in_zone(i, j, k, n, N, M);
        if (cur_num >= 0 && rem_num >= 0)
          fprintf(file, "%d %d %d\n", -cur_num, n + 1, rem_num);
      }
    fprintf(file, "$EndNodes\n$Elements\n%d\n",
            (N * M - 1) * (N * M - 1) * (num_of_layers - 1) * 6);
    int tetr_num = 1;
    for (int k = 0; k < num_of_layers - 1; k++)
      for (int j = 0; j < N * M - 1; j++)
        for (int i = 0; i < N * M - 1; i++) {
          write_tetrs(file, tetr_num, i, j, k, N, M);
          tetr_num += 6;
        }
    fprintf(file, "$EndElements\n");
    fclose(file);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x4,-0x54(%rbp)
movl   $0xa,-0x58(%rbp)
movl   $0x0,-0x5c(%rbp)
mov    -0x5c(%rbp),%eax
cmp    -0x54(%rbp),%eax
jge    165c <main+0x4fc>
lea    -0x50(%rbp),%rdi
mov    -0x5c(%rbp),%edx
lea    0xe5f(%rip),%rsi
call   1060 <sprintf@plt>
lea    -0x50(%rbp),%rdi
lea    0xe61(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
movl   $0xffffffff,-0x60(%rbp)
cmpl   $0x0,-0x5c(%rbp)
je     11dc <main+0x7c>
mov    -0x5c(%rbp),%eax
mov    -0x54(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jne    11ea <main+0x8a>
mov    -0x58(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x60(%rbp)
jmp    11f0 <main+0x90>
mov    -0x58(%rbp),%eax
mov    %eax,-0x60(%rbp)
mov    -0x58(%rbp),%eax
mov    %eax,-0x64(%rbp)
cmpl   $0x0,-0x5c(%rbp)
je     1209 <main+0xa9>
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
mov    -0x5c(%rbp),%eax
mov    -0x54(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
je     1223 <main+0xc3>
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x54(%rbp),%edx
imul   -0x58(%rbp),%edx
imul   -0x54(%rbp),%edx
imul   -0x58(%rbp),%edx
imul   -0x64(%rbp),%edx
lea    0xdd3(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x0,-0x68(%rbp)
mov    -0x5c(%rbp),%eax
imul   -0x58(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x74(%rbp)
movl   $0x0,-0x78(%rbp)
mov    -0x78(%rbp),%eax
mov    -0x54(%rbp),%ecx
imul   -0x58(%rbp),%ecx
cmp    %ecx,%eax
jge    1324 <main+0x1c4>
movl   $0x0,-0x7c(%rbp)
mov    -0x7c(%rbp),%eax
mov    -0x54(%rbp),%ecx
imul   -0x58(%rbp),%ecx
cmp    %ecx,%eax
jge    1311 <main+0x1b1>
mov    -0x7c(%rbp),%edi
mov    -0x78(%rbp),%esi
mov    -0x74(%rbp),%edx
mov    -0x5c(%rbp),%ecx
sub    $0x1,%ecx
mov    -0x54(%rbp),%r8d
mov    -0x58(%rbp),%r9d
call   1080 <get_num_in_zone@plt>
mov    %eax,-0x70(%rbp)
mov    -0x7c(%rbp),%edi
mov    -0x78(%rbp),%esi
mov    -0x74(%rbp),%edx
mov    -0x5c(%rbp),%ecx
mov    -0x54(%rbp),%r8d
mov    -0x58(%rbp),%r9d
call   1080 <get_num_in_zone@plt>
mov    %eax,-0x6c(%rbp)
cmpl   $0x0,-0x6c(%rbp)
jl     12fe <main+0x19e>
cmpl   $0x0,-0x70(%rbp)
jl     12fe <main+0x19e>
mov    -0x10(%rbp),%rdi
xor    %edx,%edx
sub    -0x6c(%rbp),%edx
mov    -0x5c(%rbp),%ecx
sub    $0x1,%ecx
mov    -0x70(%rbp),%r8d
lea    0xd4c(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    1303 <main+0x1a3>
mov    -0x7c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x7c(%rbp)
jmp    127c <main+0x11c>
jmp    1316 <main+0x1b6>
mov    -0x78(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x78(%rbp)
jmp    1263 <main+0x103>
mov    -0x5c(%rbp),%eax
imul   -0x58(%rbp),%eax
mov    %eax,-0x80(%rbp)
mov    -0x80(%rbp),%eax
mov    -0x5c(%rbp),%ecx
add    $0x1,%ecx
imul   -0x58(%rbp),%ecx
cmp    %ecx,%eax
jge    1418 <main+0x2b8>
movl   $0x0,-0x84(%rbp)
mov    -0x84(%rbp),%eax
mov    -0x54(%rbp),%ecx
imul   -0x58(%rbp),%ecx
cmp    %ecx,%eax
jge    1405 <main+0x2a5>
movl   $0x0,-0x88(%rbp)
mov    -0x88(%rbp),%eax
mov    -0x54(%rbp),%ecx
imul   -0x58(%rbp),%ecx
cmp    %ecx,%eax
jge    13ec <main+0x28c>
mov    -0x88(%rbp),%edi
mov    -0x84(%rbp),%esi
mov    -0x80(%rbp),%edx
mov    -0x5c(%rbp),%ecx
mov    -0x54(%rbp),%r8d
mov    -0x58(%rbp),%r9d
call   1080 <get_num_in_zone@plt>
mov    %eax,-0x6c(%rbp)
cmpl   $0x0,-0x6c(%rbp)
jl     13d3 <main+0x273>
mov    -0x10(%rbp),%rdi
mov    -0x6c(%rbp),%edx
mov    -0x88(%rbp),%ecx
mov    -0x84(%rbp),%r8d
mov    -0x80(%rbp),%r9d
lea    0xc74(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    13d8 <main+0x278>
mov    -0x88(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x88(%rbp)
jmp    136c <main+0x20c>
jmp    13f1 <main+0x291>
mov    -0x84(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x84(%rbp)
jmp    134d <main+0x1ed>
jmp    140a <main+0x2aa>
mov    -0x80(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x80(%rbp)
jmp    132e <main+0x1ce>
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
imul   -0x58(%rbp),%eax
mov    %eax,-0x74(%rbp)
movl   $0x0,-0x8c(%rbp)
mov    -0x8c(%rbp),%eax
mov    -0x54(%rbp),%ecx
imul   -0x58(%rbp),%ecx
cmp    %ecx,%eax
jge    1511 <main+0x3b1>
movl   $0x0,-0x90(%rbp)
mov    -0x90(%rbp),%eax
mov    -0x54(%rbp),%ecx
imul   -0x58(%rbp),%ecx
cmp    %ecx,%eax
jge    14f8 <main+0x398>
mov    -0x90(%rbp),%edi
mov    -0x8c(%rbp),%esi
mov    -0x74(%rbp),%edx
mov    -0x5c(%rbp),%ecx
add    $0x1,%ecx
mov    -0x54(%rbp),%r8d
mov    -0x58(%rbp),%r9d
call   1080 <get_num_in_zone@plt>
mov    %eax,-0x70(%rbp)
mov    -0x90(%rbp),%edi
mov    -0x8c(%rbp),%esi
mov    -0x74(%rbp),%edx
mov    -0x5c(%rbp),%ecx
mov    -0x54(%rbp),%r8d
mov    -0x58(%rbp),%r9d
call   1080 <get_num_in_zone@plt>
mov    %eax,-0x6c(%rbp)
cmpl   $0x0,-0x6c(%rbp)
jl     14df <main+0x37f>
cmpl   $0x0,-0x70(%rbp)
jl     14df <main+0x37f>
mov    -0x10(%rbp),%rdi
xor    %edx,%edx
sub    -0x6c(%rbp),%edx
mov    -0x5c(%rbp),%ecx
add    $0x1,%ecx
mov    -0x70(%rbp),%r8d
lea    0xb6b(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    14e4 <main+0x384>
mov    -0x90(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x90(%rbp)
jmp    144e <main+0x2ee>
jmp    14fd <main+0x39d>
mov    -0x8c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8c(%rbp)
jmp    142f <main+0x2cf>
mov    -0x10(%rbp),%rdi
mov    -0x54(%rbp),%eax
imul   -0x58(%rbp),%eax
sub    $0x1,%eax
mov    -0x54(%rbp),%ecx
imul   -0x58(%rbp),%ecx
sub    $0x1,%ecx
imul   %ecx,%eax
mov    -0x64(%rbp),%ecx
sub    $0x1,%ecx
imul   %ecx,%eax
imul   $0x6,%eax,%edx
lea    0xb0e(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x1,-0x94(%rbp)
movl   $0x0,-0x98(%rbp)
mov    -0x98(%rbp),%eax
mov    -0x64(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    1633 <main+0x4d3>
movl   $0x0,-0x9c(%rbp)
mov    -0x9c(%rbp),%eax
mov    -0x54(%rbp),%ecx
imul   -0x58(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    161a <main+0x4ba>
movl   $0x0,-0xa0(%rbp)
mov    -0xa0(%rbp),%eax
mov    -0x54(%rbp),%ecx
imul   -0x58(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    1601 <main+0x4a1>
mov    -0x10(%rbp),%rdi
mov    -0x94(%rbp),%esi
mov    -0xa0(%rbp),%edx
mov    -0x9c(%rbp),%ecx
mov    -0x98(%rbp),%r8d
mov    -0x54(%rbp),%r9d
mov    -0x58(%rbp),%eax
mov    %eax,(%rsp)
call   1070 <write_tetrs@plt>
mov    -0x94(%rbp),%eax
add    $0x6,%eax
mov    %eax,-0x94(%rbp)
mov    -0xa0(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xa0(%rbp)
jmp    159a <main+0x43a>
jmp    1606 <main+0x4a6>
mov    -0x9c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x9c(%rbp)
jmp    1578 <main+0x418>
jmp    161f <main+0x4bf>
mov    -0x98(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x98(%rbp)
jmp    155a <main+0x3fa>
mov    -0x10(%rbp),%rdi
lea    0xa27(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x5c(%rbp)
jmp    1187 <main+0x27>
xor    %eax,%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
movl   $0xa,0x18(%rsp)
xor    %r14d,%r14d
nopl   0x0(%rax)
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
lea    0xe61(%rip),%rsi
mov    %r14d,%edx
call   1060 <sprintf@plt>
mov    %rbx,%rdi
lea    0xe61(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%r12
xor    %eax,%eax
cmp    $0x3,%r14d
setne  %al
mov    %r14d,%ecx
sub    $0x1,%ecx
mov    %ecx,0xc(%rsp)
sbb    $0x0,%eax
add    $0xb,%eax
mov    %eax,0x10(%rsp)
imul   $0x640,%eax,%edx
mov    %r12,%rdi
lea    0xe2e(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
lea    (%r14,%r14,1),%eax
lea    (%rax,%rax,4),%r13d
lea    (%rax,%rax,4),%eax
add    $0xffffffff,%eax
mov    %eax,0x1c(%rsp)
movl   $0x0,0x14(%rsp)
jmp    1224 <main+0xb4>
nopl   0x0(%rax)
mov    0x14(%rsp),%eax
add    $0x1,%eax
mov    %eax,0x14(%rsp)
cmp    $0x28,%eax
je     12b0 <main+0x140>
xor    %ebx,%ebx
jmp    1238 <main+0xc8>
nopl   0x0(%rax,%rax,1)
add    $0x1,%ebx
cmp    $0x28,%ebx
je     1210 <main+0xa0>
mov    %ebx,%edi
mov    0x14(%rsp),%ebp
mov    %ebp,%esi
mov    0x1c(%rsp),%r15d
mov    %r15d,%edx
mov    0xc(%rsp),%ecx
mov    $0x4,%r8d
mov    $0xa,%r9d
call   1090 <get_num_in_zone@plt>
mov    %eax,0x8(%rsp)
mov    %ebx,%edi
mov    %ebp,%esi
mov    %r15d,%edx
mov    %r14d,%ecx
mov    $0x4,%r8d
mov    $0xa,%r9d
call   1090 <get_num_in_zone@plt>
mov    0x8(%rsp),%r8d
test   %eax,%eax
js     1230 <main+0xc0>
test   %r8d,%r8d
js     1230 <main+0xc0>
neg    %eax
mov    %r12,%rdi
lea    0xdad(%rip),%rsi
mov    %eax,%edx
mov    0xc(%rsp),%ecx
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    1230 <main+0xc0>
cs nopw 0x0(%rax,%rax,1)
nop
lea    0x1(%r14),%eax
mov    %eax,0x8(%rsp)
lea    (%r14,%r14,1),%eax
add    $0x2,%eax
lea    (%rax,%rax,4),%eax
mov    %eax,0xc(%rsp)
lea    0xd73(%rip),%r15
jmp    12db <main+0x16b>
nop
add    $0x1,%r13d
cmp    0x18(%rsp),%r13d
je     1330 <main+0x1c0>
xor    %ebx,%ebx
jmp    12e8 <main+0x178>
nop
add    $0x1,%ebx
cmp    $0x28,%ebx
je     12d0 <main+0x160>
xor    %ebp,%ebp
jmp    12f8 <main+0x188>
nopl   0x0(%rax)
add    $0x1,%ebp
cmp    $0x28,%ebp
je     12e0 <main+0x170>
mov    %ebp,%edi
mov    %ebx,%esi
mov    %r13d,%edx
mov    %r14d,%ecx
mov    $0x4,%r8d
mov    $0xa,%r9d
call   1090 <get_num_in_zone@plt>
test   %eax,%eax
js     12f0 <main+0x180>
mov    %r12,%rdi
mov    %r15,%rsi
mov    %eax,%edx
mov    %ebp,%ecx
mov    %ebx,%r8d
mov    %r13d,%r9d
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    12f0 <main+0x180>
xor    %r15d,%r15d
jmp    134a <main+0x1da>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%r15d
cmp    $0x28,%r15d
je     13c0 <main+0x250>
xor    %ebp,%ebp
jmp    1358 <main+0x1e8>
xchg   %ax,%ax
add    $0x1,%ebp
cmp    $0x28,%ebp
je     1340 <main+0x1d0>
mov    %ebp,%edi
mov    %r15d,%esi
mov    0xc(%rsp),%r13d
mov    %r13d,%edx
mov    0x8(%rsp),%ecx
mov    $0x4,%r8d
mov    $0xa,%r9d
call   1090 <get_num_in_zone@plt>
mov    %eax,%ebx
mov    %ebp,%edi
mov    %r15d,%esi
mov    %r13d,%edx
mov    %r14d,%ecx
mov    $0x4,%r8d
mov    $0xa,%r9d
call   1090 <get_num_in_zone@plt>
test   %eax,%eax
js     1350 <main+0x1e0>
test   %ebx,%ebx
js     1350 <main+0x1e0>
neg    %eax
mov    %r12,%rdi
lea    0xc97(%rip),%rsi
mov    %eax,%edx
mov    0x8(%rsp),%ecx
mov    %ebx,%r8d
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    1350 <main+0x1e0>
xchg   %ax,%ax
mov    0x10(%rsp),%eax
add    $0xffffffff,%eax
mov    %eax,0x10(%rsp)
imul   $0x23a6,%eax,%edx
xor    %r14d,%r14d
mov    %r12,%rdi
lea    0xc6f(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x1,%ebp
nopw   0x0(%rax,%rax,1)
xor    %r13d,%r13d
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movl   $0xa,(%rsp)
mov    %r12,%rdi
mov    %ebp,%esi
mov    %ebx,%edx
mov    %r13d,%ecx
mov    %r14d,%r8d
mov    $0x4,%r9d
call   1080 <write_tetrs@plt>
add    $0x6,%ebp
add    $0x1,%ebx
cmp    $0x27,%ebx
jne    1410 <main+0x2a0>
add    $0x1,%r13d
cmp    $0x27,%r13d
jne    1400 <main+0x290>
add    $0x1,%r14d
cmp    0x10(%rsp),%r14d
jne    13f0 <main+0x280>
mov    $0xd,%esi
mov    $0x1,%edx
lea    0xc05(%rip),%rdi
mov    %r12,%rcx
call   1070 <fwrite@plt>
mov    %r12,%rdi
call   1030 <fclose@plt>
addl   $0xa,0x18(%rsp)
mov    0x8(%rsp),%eax
mov    %eax,%r14d
cmp    $0x4,%eax
jne    1190 <main+0x20>
xor    %eax,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [18 x i8] c"cube-zone-%d.zmsh\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [44 x i8] c"$MeshFormat\0A2 0 8\0A$EndMeshFormat\0A$Nodes\0A%d\0A\00"
@.str.3 = [10 x i8] c"%d %d %d\0A\00"
@.str.4 = [13 x i8] c"%d %d %d %d\0A\00"
@.str.5 = [24 x i8] c"$EndNodes\0A$Elements\0A%d\0A\00"
@.str.6 = [14 x i8] c"$EndElements\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [50 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
%21 = alloca i32
%22 = alloca i32
%23 = alloca i32
store i32 0, i32* %1
store i32 4, i32* %4
store i32 10, i32* %5
store i32 0, i32* %6
br label %24
24: ; preds = %300, %0
%25 = load i32, i32* %6
%26 = load i32, i32* %4
%27 = icmp slt i32 %25, %26
br i1 %27, label %28, label %303
28: ; preds = %24
%29 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
%30 = load i32, i32* %6
%31 = call i32 @sprintf(i8* %29, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %30)
%32 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
%33 = call i32* @fopen(i8* %32, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %33, i32** %2
store i32 -1, i32* %7
%34 = load i32, i32* %6
%35 = icmp eq i32 %34, 0
br i1 %35, label %41, label %36
36: ; preds = %28
%37 = load i32, i32* %6
%38 = load i32, i32* %4
%39 = sub nsw i32 %38, 1
%40 = icmp eq i32 %37, %39
br i1 %40, label %41, label %44
41: ; preds = %36, %28
%42 = load i32, i32* %5
%43 = sub nsw i32 %42, 1
store i32 %43, i32* %7
br label %46
44: ; preds = %36
%45 = load i32, i32* %5
store i32 %45, i32* %7
br label %46
46: ; preds = %44, %41
%47 = load i32, i32* %5
store i32 %47, i32* %8
%48 = load i32, i32* %6
%49 = icmp ne i32 %48, 0
br i1 %49, label %50, label %53
50: ; preds = %46
%51 = load i32, i32* %8
%52 = add nsw i32 %51, 1
store i32 %52, i32* %8
br label %53
53: ; preds = %50, %46
%54 = load i32, i32* %6
%55 = load i32, i32* %4
%56 = sub nsw i32 %55, 1
%57 = icmp ne i32 %54, %56
br i1 %57, label %58, label %61
58: ; preds = %53
%59 = load i32, i32* %8
%60 = add nsw i32 %59, 1
store i32 %60, i32* %8
br label %61
61: ; preds = %58, %53
%62 = load i32*, i32** %2
%63 = load i32, i32* %4
%64 = load i32, i32* %5
%65 = mul nsw i32 %63, %64
%66 = load i32, i32* %4
%67 = mul nsw i32 %65, %66
%68 = load i32, i32* %5
%69 = mul nsw i32 %67, %68
%70 = load i32, i32* %8
%71 = mul nsw i32 %69, %70
%72 = call i32 (i32*, i8*, ...) @fprintf(i32* %62, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), i32 %71)
store i32 0, i32* %9
%73 = load i32, i32* %6
%74 = load i32, i32* %5
%75 = mul nsw i32 %73, %74
%76 = sub nsw i32 %75, 1
store i32 %76, i32* %12
store i32 0, i32* %13
br label %77
77: ; preds = %124, %61
%78 = load i32, i32* %13
%79 = load i32, i32* %4
%80 = load i32, i32* %5
%81 = mul nsw i32 %79, %80
%82 = icmp slt i32 %78, %81
br i1 %82, label %83, label %127
83: ; preds = %77
store i32 0, i32* %14
br label %84
84: ; preds = %120, %83
%85 = load i32, i32* %14
%86 = load i32, i32* %4
%87 = load i32, i32* %5
%88 = mul nsw i32 %86, %87
%89 = icmp slt i32 %85, %88
br i1 %89, label %90, label %123
90: ; preds = %84
%91 = load i32, i32* %14
%92 = load i32, i32* %13
%93 = load i32, i32* %12
%94 = load i32, i32* %6
%95 = sub nsw i32 %94, 1
%96 = load i32, i32* %4
%97 = load i32, i32* %5
%98 = call i32 @get_num_in_zone(i32 %91, i32 %92, i32 %93, i32 %95, i32 %96, i32 %97)
store i32 %98, i32* %11
%99 = load i32, i32* %14
%100 = load i32, i32* %13
%101 = load i32, i32* %12
%102 = load i32, i32* %6
%103 = load i32, i32* %4
%104 = load i32, i32* %5
%105 = call i32 @get_num_in_zone(i32 %99, i32 %100, i32 %101, i32 %102, i32 %103, i32 %104)
store i32 %105, i32* %10
%106 = load i32, i32* %10
%107 = icmp sge i32 %106, 0
br i1 %107, label %108, label %119
108: ; preds = %90
%109 = load i32, i32* %11
%110 = icmp sge i32 %109, 0
br i1 %110, label %111, label %119
111: ; preds = %108
%112 = load i32*, i32** %2
%113 = load i32, i32* %10
%114 = sub nsw i32 0, %113
%115 = load i32, i32* %6
%116 = sub nsw i32 %115, 1
%117 = load i32, i32* %11
%118 = call i32 (i32*, i8*, ...) @fprintf(i32* %112, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 %114, i32 %116, i32 %117)
br label %119
119: ; preds = %111, %108, %90
br label %120
120: ; preds = %119
%121 = load i32, i32* %14
%122 = add nsw i32 %121, 1
store i32 %122, i32* %14
br label %84
123: ; preds = %84
br label %124
124: ; preds = %123
%125 = load i32, i32* %13
%126 = add nsw i32 %125, 1
store i32 %126, i32* %13
br label %77
127: ; preds = %77
%128 = load i32, i32* %6
%129 = load i32, i32* %5
%130 = mul nsw i32 %128, %129
store i32 %130, i32* %15
br label %131
131: ; preds = %178, %127
%132 = load i32, i32* %15
%133 = load i32, i32* %6
%134 = add nsw i32 %133, 1
%135 = load i32, i32* %5
%136 = mul nsw i32 %134, %135
%137 = icmp slt i32 %132, %136
br i1 %137, label %138, label %181
138: ; preds = %131
store i32 0, i32* %16
br label %139
139: ; preds = %174, %138
%140 = load i32, i32* %16
%141 = load i32, i32* %4
%142 = load i32, i32* %5
%143 = mul nsw i32 %141, %142
%144 = icmp slt i32 %140, %143
br i1 %144, label %145, label %177
145: ; preds = %139
store i32 0, i32* %17
br label %146
146: ; preds = %170, %145
%147 = load i32, i32* %17
%148 = load i32, i32* %4
%149 = load i32, i32* %5
%150 = mul nsw i32 %148, %149
%151 = icmp slt i32 %147, %150
br i1 %151, label %152, label %173
152: ; preds = %146
%153 = load i32, i32* %17
%154 = load i32, i32* %16
%155 = load i32, i32* %15
%156 = load i32, i32* %6
%157 = load i32, i32* %4
%158 = load i32, i32* %5
%159 = call i32 @get_num_in_zone(i32 %153, i32 %154, i32 %155, i32 %156, i32 %157, i32 %158)
store i32 %159, i32* %10
%160 = load i32, i32* %10
%161 = icmp sge i32 %160, 0
br i1 %161, label %162, label %169
162: ; preds = %152
%163 = load i32*, i32** %2
%164 = load i32, i32* %10
%165 = load i32, i32* %17
%166 = load i32, i32* %16
%167 = load i32, i32* %15
%168 = call i32 (i32*, i8*, ...) @fprintf(i32* %163, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i32 %164, i32 %165, i32 %166, i32 %167)
br label %169
169: ; preds = %162, %152
br label %170
170: ; preds = %169
%171 = load i32, i32* %17
%172 = add nsw i32 %171, 1
store i32 %172, i32* %17
br label %146
173: ; preds = %146
br label %174
174: ; preds = %173
%175 = load i32, i32* %16
%176 = add nsw i32 %175, 1
store i32 %176, i32* %16
br label %139
177: ; preds = %139
br label %178
178: ; preds = %177
%179 = load i32, i32* %15
%180 = add nsw i32 %179, 1
store i32 %180, i32* %15
br label %131
181: ; preds = %131
%182 = load i32, i32* %6
%183 = add nsw i32 %182, 1
%184 = load i32, i32* %5
%185 = mul nsw i32 %183, %184
store i32 %185, i32* %12
store i32 0, i32* %18
br label %186
186: ; preds = %233, %181
%187 = load i32, i32* %18
%188 = load i32, i32* %4
%189 = load i32, i32* %5
%190 = mul nsw i32 %188, %189
%191 = icmp slt i32 %187, %190
br i1 %191, label %192, label %236
192: ; preds = %186
store i32 0, i32* %19
br label %193
193: ; preds = %229, %192
%194 = load i32, i32* %19
%195 = load i32, i32* %4
%196 = load i32, i32* %5
%197 = mul nsw i32 %195, %196
%198 = icmp slt i32 %194, %197
br i1 %198, label %199, label %232
199: ; preds = %193
%200 = load i32, i32* %19
%201 = load i32, i32* %18
%202 = load i32, i32* %12
%203 = load i32, i32* %6
%204 = add nsw i32 %203, 1
%205 = load i32, i32* %4
%206 = load i32, i32* %5
%207 = call i32 @get_num_in_zone(i32 %200, i32 %201, i32 %202, i32 %204, i32 %205, i32 %206)
store i32 %207, i32* %11
%208 = load i32, i32* %19
%209 = load i32, i32* %18
%210 = load i32, i32* %12
%211 = load i32, i32* %6
%212 = load i32, i32* %4
%213 = load i32, i32* %5
%214 = call i32 @get_num_in_zone(i32 %208, i32 %209, i32 %210, i32 %211, i32 %212, i32 %213)
store i32 %214, i32* %10
%215 = load i32, i32* %10
%216 = icmp sge i32 %215, 0
br i1 %216, label %217, label %228
217: ; preds = %199
%218 = load i32, i32* %11
%219 = icmp sge i32 %218, 0
br i1 %219, label %220, label %228
220: ; preds = %217
%221 = load i32*, i32** %2
%222 = load i32, i32* %10
%223 = sub nsw i32 0, %222
%224 = load i32, i32* %6
%225 = add nsw i32 %224, 1
%226 = load i32, i32* %11
%227 = call i32 (i32*, i8*, ...) @fprintf(i32* %221, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 %223, i32 %225, i32 %226)
br label %228
228: ; preds = %220, %217, %199
br label %229
229: ; preds = %228
%230 = load i32, i32* %19
%231 = add nsw i32 %230, 1
store i32 %231, i32* %19
br label %193
232: ; preds = %193
br label %233
233: ; preds = %232
%234 = load i32, i32* %18
%235 = add nsw i32 %234, 1
store i32 %235, i32* %18
br label %186
236: ; preds = %186
%237 = load i32*, i32** %2
%238 = load i32, i32* %4
%239 = load i32, i32* %5
%240 = mul nsw i32 %238, %239
%241 = sub nsw i32 %240, 1
%242 = load i32, i32* %4
%243 = load i32, i32* %5
%244 = mul nsw i32 %242, %243
%245 = sub nsw i32 %244, 1
%246 = mul nsw i32 %241, %245
%247 = load i32, i32* %8
%248 = sub nsw i32 %247, 1
%249 = mul nsw i32 %246, %248
%250 = mul nsw i32 %249, 6
%251 = call i32 (i32*, i8*, ...) @fprintf(i32* %237, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), i32 %250)
store i32 1, i32* %20
store i32 0, i32* %21
br label %252
252: ; preds = %292, %236
%253 = load i32, i32* %21
%254 = load i32, i32* %8
%255 = sub nsw i32 %254, 1
%256 = icmp slt i32 %253, %255
br i1 %256, label %257, label %295
257: ; preds = %252
store i32 0, i32* %22
br label %258
258: ; preds = %288, %257
%259 = load i32, i32* %22
%260 = load i32, i32* %4
%261 = load i32, i32* %5
%262 = mul nsw i32 %260, %261
%263 = sub nsw i32 %262, 1
%264 = icmp slt i32 %259, %263
br i1 %264, label %265, label %291
265: ; preds = %258
store i32 0, i32* %23
br label %266
266: ; preds = %284, %265
%267 = load i32, i32* %23
%268 = load i32, i32* %4
%269 = load i32, i32* %5
%270 = mul nsw i32 %268, %269
%271 = sub nsw i32 %270, 1
%272 = icmp slt i32 %267, %271
br i1 %272, label %273, label %287
273: ; preds = %266
%274 = load i32*, i32** %2
%275 = load i32, i32* %20
%276 = load i32, i32* %23
%277 = load i32, i32* %22
%278 = load i32, i32* %21
%279 = load i32, i32* %4
%280 = load i32, i32* %5
%281 = call i32 @write_tetrs(i32* %274, i32 %275, i32 %276, i32 %277, i32 %278, i32 %279, i32 %280)
%282 = load i32, i32* %20
%283 = add nsw i32 %282, 6
store i32 %283, i32* %20
br label %284
284: ; preds = %273
%285 = load i32, i32* %23
%286 = add nsw i32 %285, 1
store i32 %286, i32* %23
br label %266
287: ; preds = %266
br label %288
288: ; preds = %287
%289 = load i32, i32* %22
%290 = add nsw i32 %289, 1
store i32 %290, i32* %22
br label %258
291: ; preds = %258
br label %292
292: ; preds = %291
%293 = load i32, i32* %21
%294 = add nsw i32 %293, 1
store i32 %294, i32* %21
br label %252
295: ; preds = %252
%296 = load i32*, i32** %2
%297 = call i32 (i32*, i8*, ...) @fprintf(i32* %296, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0))
%298 = load i32*, i32** %2
%299 = call i32 @fclose(i32* %298)
br label %300
300: ; preds = %295
%301 = load i32, i32* %6
%302 = add nsw i32 %301, 1
store i32 %302, i32* %6
br label %24
303: ; preds = %24
ret i32 0
}

LLVM IR (-O2):
@.str = [18 x i8] c"cube-zone-%d.zmsh\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [44 x i8] c"$MeshFormat\0A2 0 8\0A$EndMeshFormat\0A$Nodes\0A%d\0A\00"
@.str.3 = [10 x i8] c"%d %d %d\0A\00"
@.str.4 = [13 x i8] c"%d %d %d %d\0A\00"
@.str.5 = [24 x i8] c"$EndNodes\0A$Elements\0A%d\0A\00"
@.str.6 = [14 x i8] c"$EndElements\0A\00"
define i32 @main() {
%1 = alloca [50 x i8]
%2 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 0
br label %4
3: ; preds = %84
ret i32 0
4: ; preds = %0, %84
%5 = phi i32 [ 10, %0 ], [ %87, %84 ]
%6 = phi i32 [ 0, %0 ], [ %20, %84 ]
%7 = call i32 @sprintf(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = call i32* @fopen(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%9 = icmp eq i32 %6, 0
%10 = select i1 %9, i32 10, i32 11
%11 = icmp ne i32 %6, 3
%12 = zext i1 %11 to i32
%13 = add nuw nsw i32 %10, %12
%14 = mul nuw nsw i32 %13, 1600
%15 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %8, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), i32 %14)
%16 = mul nuw nsw i32 %6, 10
%17 = add nsw i32 %16, -1
%18 = add nsw i32 %6, -1
br label %22
19: ; preds = %24
%20 = add nuw nsw i32 %6, 1
%21 = mul nuw nsw i32 %20, 10
br label %40
22: ; preds = %4, %24
%23 = phi i32 [ 0, %4 ], [ %25, %24 ]
br label %27
24: ; preds = %37
%25 = add nuw nsw i32 %23, 1
%26 = icmp eq i32 %25, 40
br i1 %26, label %19, label %22
27: ; preds = %22, %37
%28 = phi i32 [ 0, %22 ], [ %38, %37 ]
%29 = tail call i32 @get_num_in_zone(i32 %28, i32 %23, i32 %17, i32 %18, i32 4, i32 10)
%30 = tail call i32 @get_num_in_zone(i32 %28, i32 %23, i32 %17, i32 %6, i32 4, i32 10)
%31 = icmp sgt i32 %30, -1
%32 = icmp sgt i32 %29, -1
%33 = select i1 %31, i1 %32, i1 false
br i1 %33, label %34, label %37
34: ; preds = %27
%35 = sub nsw i32 0, %30
%36 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %8, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 %35, i32 %18, i32 %29)
br label %37
37: ; preds = %27, %34
%38 = add nuw nsw i32 %28, 1
%39 = icmp eq i32 %38, 40
br i1 %39, label %24, label %27
40: ; preds = %19, %44
%41 = phi i32 [ %45, %44 ], [ %16, %19 ]
br label %42
42: ; preds = %40, %47
%43 = phi i32 [ 0, %40 ], [ %48, %47 ]
br label %50
44: ; preds = %47
%45 = add nuw nsw i32 %41, 1
%46 = icmp eq i32 %45, %5
br i1 %46, label %59, label %40
47: ; preds = %56
%48 = add nuw nsw i32 %43, 1
%49 = icmp eq i32 %48, 40
br i1 %49, label %44, label %42
50: ; preds = %42, %56
%51 = phi i32 [ 0, %42 ], [ %57, %56 ]
%52 = tail call i32 @get_num_in_zone(i32 %51, i32 %43, i32 %41, i32 %6, i32 4, i32 10)
%53 = icmp sgt i32 %52, -1
br i1 %53, label %54, label %56
54: ; preds = %50
%55 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %8, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i32 %52, i32 %51, i32 %43, i32 %41)
br label %56
56: ; preds = %50, %54
%57 = add nuw nsw i32 %51, 1
%58 = icmp eq i32 %57, 40
br i1 %58, label %47, label %50
59: ; preds = %44, %65
%60 = phi i32 [ %66, %65 ], [ 0, %44 ]
br label %68
61: ; preds = %65
%62 = add nsw i32 %13, -1
%63 = mul nuw nsw i32 %62, 9126
%64 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %8, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), i32 %63)
br label %81
65: ; preds = %78
%66 = add nuw nsw i32 %60, 1
%67 = icmp eq i32 %66, 40
br i1 %67, label %61, label %59
68: ; preds = %59, %78
%69 = phi i32 [ 0, %59 ], [ %79, %78 ]
%70 = tail call i32 @get_num_in_zone(i32 %69, i32 %60, i32 %21, i32 %20, i32 4, i32 10)
%71 = tail call i32 @get_num_in_zone(i32 %69, i32 %60, i32 %21, i32 %6, i32 4, i32 10)
%72 = icmp sgt i32 %71, -1
%73 = icmp sgt i32 %70, -1
%74 = select i1 %72, i1 %73, i1 false
br i1 %74, label %75, label %78
75: ; preds = %68
%76 = sub nsw i32 0, %71
%77 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %8, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 %76, i32 %20, i32 %70)
br label %78
78: ; preds = %68, %75
%79 = add nuw nsw i32 %69, 1
%80 = icmp eq i32 %79, 40
br i1 %80, label %65, label %68
81: ; preds = %61, %92
%82 = phi i32 [ %93, %92 ], [ 0, %61 ]
%83 = phi i32 [ %102, %92 ], [ 1, %61 ]
br label %89
84: ; preds = %92
%85 = tail call i64 @fwrite(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0), i64 13, i64 1, i32* %8)
%86 = tail call i32 @fclose(i32* %8)
%87 = add nuw nsw i32 %5, 10
%88 = icmp eq i32 %20, 4
br i1 %88, label %3, label %4
89: ; preds = %81, %95
%90 = phi i32 [ 0, %81 ], [ %96, %95 ]
%91 = phi i32 [ %83, %81 ], [ %102, %95 ]
br label %98
92: ; preds = %95
%93 = add nuw nsw i32 %82, 1
%94 = icmp eq i32 %93, %62
br i1 %94, label %84, label %81
95: ; preds = %98
%96 = add nuw nsw i32 %90, 1
%97 = icmp eq i32 %96, 39
br i1 %97, label %92, label %89
98: ; preds = %89, %98
%99 = phi i32 [ 0, %89 ], [ %103, %98 ]
%100 = phi i32 [ %91, %89 ], [ %102, %98 ]
%101 = tail call i32 @write_tetrs(i32* %8, i32 %100, i32 %99, i32 %90, i32 %82, i32 4, i32 10)
%102 = add nsw i32 %100, 6
%103 = add nuw nsw i32 %99, 1
%104 = icmp eq i32 %103, 39
br i1 %104, label %95, label %98
}