#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 */
scalar_t__ cbimat(int /*<<< orphan*/, int, int /*<<< orphan*/, int);
scalar_t__ cmat(int /*<<< orphan*/, int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free_bimat(unsigned char **, int /*<<< orphan*/, int,
                              int /*<<< orphan*/, int);
int /*<<< orphan*/ free_mat(unsigned char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ fwrite(unsigned char *, int, int, int /*<<< orphan*/ *);
scalar_t__ memcmp(unsigned char *, unsigned char *, int);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char *, int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ sprintf(char *, char *, char *, ...);
void unique_models(char *root, int files, int nlitho) {
  int n, m, uniquemodels, x, y, same;
  char rootname[250], *model;
  FILE *in, *out;
  unsigned char **am, **uam, *cam, *dam;
  am = (unsigned char **)cbimat(0, files, 0, nlitho * nlitho);
  uam = (unsigned char **)cbimat(0, files, 0, nlitho * nlitho);
  cam = (unsigned char *)cmat(0, nlitho * nlitho);
  dam = (unsigned char *)cmat(0, nlitho * nlitho);
  for (n = 1; n < files + 1; n++) {
    sprintf(rootname, "%s_%04d.g24", root, n);
    in = fopen(rootname, "rb");
    fread(&(am[n - 1][0]), sizeof(char), nlitho * nlitho, in);
    fclose(in);
  }
  for (n = 0, uniquemodels = 0; n < files; n++) {
    same = 0;
    for (m = 0; m < uniquemodels; m++)
      if (memcmp(&(am[n][0]), &(uam[m][0]), nlitho * nlitho) == 0) {
        same = 1;
        break;
      }
    if (same == 0) {
      memcpy(&(uam[uniquemodels][0]), &(am[n][0]), nlitho * nlitho);
      uniquemodels++;
    }
  }
  printf("unique models %d\n", uniquemodels);
  sprintf(rootname, "%s_uam.bin", root);
  out = fopen(rootname, "wb");
  for (m = 0; m < uniquemodels; m++)
    fwrite(&(uam[m][0]), sizeof(char), nlitho * nlitho, out);
  fclose(out);
  memcpy(&(cam[0]), &(uam[0][0]), nlitho * nlitho);
  for (x = 0; x < nlitho * nlitho; x++) {
    for (m = 1, same = 1; m < uniquemodels; m++) {
      if (uam[m][x] != cam[x]) {
        same = 0;
        break;
      }
    }
    if (same == 1) {
      dam[x] = '\0';
    } else {
      cam[x] = '\0';
      dam[x] = '\1';
    }
  }
  sprintf(rootname, "%s_cam.bin", root);
  out = fopen(rootname, "wb");
  fwrite(&(cam[0]), sizeof(char), nlitho * nlitho, out);
  fclose(out);
  sprintf(rootname, "%s_dam.bin", root);
  out = fopen(rootname, "wb");
  fwrite(&(dam[0]), sizeof(char), nlitho * nlitho, out);
  fclose(out);
  free_bimat(am, 0, files, 0, nlitho * nlitho);
  free_bimat(uam, 0, files, 0, nlitho * nlitho);
  free_mat(cam, 0, nlitho * nlitho);
  free_mat(dam, 0, nlitho * nlitho);
}


x86 assembly (clang, -O0):
<unique_models>:
push   %rbp
mov    %rsp,%rbp
sub    $0x170,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%ecx
imul   -0x10(%rbp),%ecx
xor    %edx,%edx
mov    %edx,%edi
call   1090 <cbimat@plt>
mov    %rax,-0x150(%rbp)
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%ecx
imul   -0x10(%rbp),%ecx
xor    %edx,%edx
mov    %edx,%edi
call   1090 <cbimat@plt>
mov    %rax,-0x158(%rbp)
mov    -0x10(%rbp),%esi
imul   -0x10(%rbp),%esi
xor    %edi,%edi
call   10a0 <cmat@plt>
mov    %rax,-0x160(%rbp)
mov    -0x10(%rbp),%esi
imul   -0x10(%rbp),%esi
xor    %edi,%edi
call   10a0 <cmat@plt>
mov    %rax,-0x168(%rbp)
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    -0xc(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jge    12c7 <unique_models+0x107>
lea    -0x130(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0x14(%rbp),%ecx
lea    0xda0(%rip),%rsi
mov    $0x0,%al
call   10d0 <sprintf@plt>
lea    -0x130(%rbp),%rdi
lea    0xd97(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x140(%rbp)
mov    -0x150(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x10(%rbp),%edx
imul   -0x10(%rbp),%edx
mov    -0x140(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    -0x140(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    123a <unique_models+0x7a>
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    139e <unique_models+0x1de>
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    134e <unique_models+0x18e>
mov    -0x150(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x158(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
mov    -0x10(%rbp),%edx
imul   -0x10(%rbp),%edx
call   1060 <memcmp@plt>
cmp    $0x0,%rax
jne    133b <unique_models+0x17b>
movl   $0x1,-0x28(%rbp)
jmp    134e <unique_models+0x18e>
jmp    1340 <unique_models+0x180>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    12ef <unique_models+0x12f>
cmpl   $0x0,-0x28(%rbp)
jne    138b <unique_models+0x1cb>
mov    -0x158(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x150(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
mov    -0x10(%rbp),%edx
imul   -0x10(%rbp),%edx
call   1080 <memcpy@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1390 <unique_models+0x1d0>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    12d5 <unique_models+0x115>
mov    -0x1c(%rbp),%esi
lea    0xc67(%rip),%rdi
call   1050 <printf@plt>
lea    -0x130(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xc62(%rip),%rsi
mov    $0x0,%al
call   10d0 <sprintf@plt>
lea    -0x130(%rbp),%rdi
lea    0xc58(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x148(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1428 <unique_models+0x268>
mov    -0x158(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x10(%rbp),%edx
imul   -0x10(%rbp),%edx
mov    -0x148(%rbp),%rcx
mov    $0x1,%esi
call   10e0 <fwrite@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    13e7 <unique_models+0x227>
mov    -0x148(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x160(%rbp),%rdi
mov    -0x158(%rbp),%rax
mov    (%rax),%rsi
mov    -0x10(%rbp),%edx
imul   -0x10(%rbp),%edx
call   1080 <memcpy@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    -0x10(%rbp),%ecx
imul   -0x10(%rbp),%ecx
cmp    %ecx,%eax
jge    1520 <unique_models+0x360>
movl   $0x1,-0x18(%rbp)
movl   $0x1,-0x28(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    14d1 <unique_models+0x311>
mov    -0x158(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x20(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
mov    -0x160(%rbp),%rcx
movslq -0x20(%rbp),%rdx
movzbl (%rcx,%rdx,1),%ecx
cmp    %ecx,%eax
je     14be <unique_models+0x2fe>
movl   $0x0,-0x28(%rbp)
jmp    14d1 <unique_models+0x311>
jmp    14c3 <unique_models+0x303>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1478 <unique_models+0x2b8>
cmpl   $0x1,-0x28(%rbp)
jne    14ef <unique_models+0x32f>
mov    -0x168(%rbp),%rax
movslq -0x20(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    150d <unique_models+0x34d>
mov    -0x160(%rbp),%rax
movslq -0x20(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x168(%rbp),%rax
movslq -0x20(%rbp),%rcx
movb   $0x1,(%rax,%rcx,1)
jmp    1512 <unique_models+0x352>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1458 <unique_models+0x298>
lea    -0x130(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xafd(%rip),%rsi
mov    $0x0,%al
call   10d0 <sprintf@plt>
lea    -0x130(%rbp),%rdi
lea    0xae5(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x148(%rbp)
mov    -0x160(%rbp),%rdi
mov    -0x10(%rbp),%edx
imul   -0x10(%rbp),%edx
mov    -0x148(%rbp),%rcx
mov    $0x1,%esi
call   10e0 <fwrite@plt>
mov    -0x148(%rbp),%rdi
call   1040 <fclose@plt>
lea    -0x130(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xaaa(%rip),%rsi
mov    $0x0,%al
call   10d0 <sprintf@plt>
lea    -0x130(%rbp),%rdi
lea    0xa87(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x148(%rbp)
mov    -0x168(%rbp),%rdi
mov    -0x10(%rbp),%edx
imul   -0x10(%rbp),%edx
mov    -0x148(%rbp),%rcx
mov    $0x1,%esi
call   10e0 <fwrite@plt>
mov    -0x148(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x150(%rbp),%rdi
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%r8d
imul   -0x10(%rbp),%r8d
xor    %ecx,%ecx
mov    %ecx,%esi
call   1070 <free_bimat@plt>
mov    -0x158(%rbp),%rdi
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%r8d
imul   -0x10(%rbp),%r8d
xor    %ecx,%ecx
mov    %ecx,%esi
call   1070 <free_bimat@plt>
mov    -0x160(%rbp),%rdi
mov    -0x10(%rbp),%edx
imul   -0x10(%rbp),%edx
xor    %esi,%esi
call   10c0 <free_mat@plt>
mov    -0x168(%rbp),%rdi
mov    -0x10(%rbp),%edx
imul   -0x10(%rbp),%edx
xor    %esi,%esi
call   10c0 <free_mat@plt>
add    $0x170,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<unique_models>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x148,%rsp
mov    %edx,%r13d
mov    %esi,%ebp
mov    %rdi,0x20(%rsp)
imul   %edx,%r13d
movl   $0x0,0x8(%rsp)
xor    %edi,%edi
xor    %edx,%edx
mov    %r13d,%ecx
call   1090 <cbimat@plt>
mov    %rax,%rbx
xor    %edi,%edi
mov    %ebp,%esi
xor    %edx,%edx
mov    %r13d,%ecx
call   1090 <cbimat@plt>
mov    %rax,%r15
xor    %edi,%edi
mov    %r13d,%esi
call   10a0 <cmat@plt>
mov    %rax,0x30(%rsp)
xor    %edi,%edi
mov    %r13d,%esi
call   10a0 <cmat@plt>
mov    %rax,0x28(%rsp)
mov    %rbp,0x18(%rsp)
test   %ebp,%ebp
mov    %rbx,0x10(%rsp)
jle    133d <unique_models+0x17d>
mov    0x18(%rsp),%rax
add    $0x1,%eax
mov    %rax,0x8(%rsp)
mov    $0x1,%ebp
mov    0x20(%rsp),%r14
xchg   %ax,%ax
lea    0x40(%rsp),%r12
mov    %r12,%rdi
lea    0xda1(%rip),%rsi
mov    %r14,%rdx
mov    %ebp,%ecx
xor    %eax,%eax
call   10d0 <sprintf@plt>
mov    %r12,%rdi
lea    0xd97(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,%r12
mov    -0x8(%rbx,%rbp,8),%rdi
mov    $0x1,%esi
mov    %r13d,%edx
mov    %rax,%rcx
call   1030 <fread@plt>
mov    %r12,%rdi
call   1040 <fclose@plt>
add    $0x1,%rbp
cmp    %rbp,0x8(%rsp)
jne    1250 <unique_models+0x90>
mov    0x18(%rsp),%rax
test   %eax,%eax
jle    1335 <unique_models+0x175>
mov    %eax,%eax
mov    %rax,0x38(%rsp)
xor    %ebp,%ebp
movl   $0x0,0x8(%rsp)
mov    0x10(%rsp),%rcx
jmp    12fa <unique_models+0x13a>
nopw   0x0(%rax,%rax,1)
movslq %ebx,%rax
mov    (%r15,%rax,8),%rdi
mov    (%rcx,%rbp,8),%rsi
mov    %r13d,%edx
call   1080 <memcpy@plt>
add    $0x1,%ebx
mov    %ebx,0x8(%rsp)
add    $0x1,%rbp
cmp    0x38(%rsp),%rbp
mov    0x10(%rsp),%rcx
je     133d <unique_models+0x17d>
mov    0x8(%rsp),%ebx
test   %ebx,%ebx
jle    12d0 <unique_models+0x110>
mov    %ebx,%r14d
xor    %r12d,%r12d
nopl   0x0(%rax,%rax,1)
mov    (%rcx,%rbp,8),%rdi
mov    (%r15,%r12,8),%rsi
mov    %r13d,%edx
call   1060 <memcmp@plt>
test   %rax,%rax
je     12ea <unique_models+0x12a>
add    $0x1,%r12
cmp    %r12,%r14
mov    0x10(%rsp),%rcx
jne    1310 <unique_models+0x150>
jmp    12d0 <unique_models+0x110>
movl   $0x0,0x8(%rsp)
lea    0xccb(%rip),%rdi
mov    0x8(%rsp),%ebx
mov    %ebx,%esi
call   1050 <printf@plt>
lea    0xccb(%rip),%rsi
lea    0x40(%rsp),%rbp
mov    %rbp,%rdi
mov    0x20(%rsp),%rdx
xor    %eax,%eax
call   10d0 <sprintf@plt>
lea    0xcbb(%rip),%rsi
mov    %rbp,%rdi
call   10b0 <fopen@plt>
mov    %rax,%r14
mov    %ebx,%ebp
test   %ebx,%ebx
jle    13ad <unique_models+0x1ed>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    (%r15,%rbx,8),%rdi
mov    $0x1,%esi
mov    %r13d,%edx
mov    %r14,%rcx
call   10e0 <fwrite@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1390 <unique_models+0x1d0>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    (%r15),%rsi
mov    0x30(%rsp),%r12
mov    %r12,%rdi
mov    %r13d,%edx
call   1080 <memcpy@plt>
test   %r13d,%r13d
mov    0x28(%rsp),%r14
mov    0x20(%rsp),%rdx
mov    0x8(%rsp),%edi
je     143e <unique_models+0x27e>
mov    %r13d,%eax
xor    %ecx,%ecx
jmp    13ff <unique_models+0x23f>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %esi,%esi
mov    %sil,(%r14,%rcx,1)
add    $0x1,%rcx
cmp    %rax,%rcx
je     143e <unique_models+0x27e>
cmp    $0x2,%edi
jl     13f0 <unique_models+0x230>
mov    (%r12,%rcx,1),%bl
mov    $0x1,%esi
nopl   (%rax)
mov    (%r15,%rsi,8),%rdi
cmp    %bl,(%rdi,%rcx,1)
jne    1430 <unique_models+0x270>
add    $0x1,%rsi
cmp    %rsi,%rbp
jne    1410 <unique_models+0x250>
xor    %esi,%esi
jmp    1438 <unique_models+0x278>
cs nopw 0x0(%rax,%rax,1)
movb   $0x0,(%r12,%rcx,1)
mov    $0x1,%sil
mov    0x8(%rsp),%edi
jmp    13f2 <unique_models+0x232>
lea    0xbea(%rip),%rsi
lea    0x40(%rsp),%rbx
mov    %rbx,%rdi
xor    %eax,%eax
mov    %rdx,%r14
call   10d0 <sprintf@plt>
lea    0xbce(%rip),%rsi
mov    %rbx,%rdi
call   10b0 <fopen@plt>
mov    %rax,%rbp
mov    %r12,%rdi
mov    $0x1,%esi
mov    %r13d,%edx
mov    %rax,%rcx
call   10e0 <fwrite@plt>
mov    %rbp,%rdi
call   1040 <fclose@plt>
lea    0xbaf(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
xor    %eax,%eax
call   10d0 <sprintf@plt>
mov    %rbx,%rdi
lea    0xb8a(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,%rbp
mov    0x28(%rsp),%r14
mov    %r14,%rdi
mov    $0x1,%esi
mov    %r13d,%edx
mov    %rax,%rcx
call   10e0 <fwrite@plt>
mov    %rbp,%rdi
call   1040 <fclose@plt>
mov    0x10(%rsp),%rdi
xor    %esi,%esi
mov    0x18(%rsp),%rbx
mov    %ebx,%edx
xor    %ecx,%ecx
mov    %r13d,%r8d
call   1070 <free_bimat@plt>
mov    %r15,%rdi
xor    %esi,%esi
mov    %ebx,%edx
xor    %ecx,%ecx
mov    %r13d,%r8d
call   1070 <free_bimat@plt>
mov    %r12,%rdi
xor    %esi,%esi
mov    %r13d,%edx
call   10c0 <free_mat@plt>
mov    %r14,%rdi
xor    %esi,%esi
mov    %r13d,%edx
add    $0x148,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    10c0 <free_mat@plt>

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

LLVM IR (-O2):
@.str = [12 x i8] c"%s_%04d.g24\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [18 x i8] c"unique models %d\0A\00"
@.str.3 = [11 x i8] c"%s_uam.bin\00"
@.str.4 = [3 x i8] c"wb\00"
@.str.5 = [11 x i8] c"%s_cam.bin\00"
@.str.6 = [11 x i8] c"%s_dam.bin\00"
define void @unique_models(i8* %0, i32 %1, i32 %2) {
%4 = alloca [250 x i8]
%5 = getelementptr inbounds [250 x i8], [250 x i8]* %4, i64 0, i64 0
%6 = mul nsw i32 %2, %2
%7 = tail call i64 @cbimat(i32 0, i32 %1, i32 0, i32 %6)
%8 = inttoptr i64 %7 to i8**
%9 = tail call i64 @cbimat(i32 0, i32 %1, i32 0, i32 %6)
%10 = inttoptr i64 %9 to i8**
%11 = tail call i64 @cmat(i32 0, i32 %6)
%12 = inttoptr i64 %11 to i8*
%13 = tail call i64 @cmat(i32 0, i32 %6)
%14 = inttoptr i64 %13 to i8*
%15 = icmp slt i32 %1, 1
br i1 %15, label %64, label %16
16: ; preds = %3
%17 = add nuw i32 %1, 1
%18 = zext i32 %17 to i64
br label %23
19: ; preds = %23
%20 = icmp sgt i32 %1, 0
br i1 %20, label %21, label %64
21: ; preds = %19
%22 = zext i32 %1 to i64
br label %35
23: ; preds = %16, %23
%24 = phi i64 [ 1, %16 ], [ %33, %23 ]
%25 = trunc i64 %24 to i32
%26 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %25)
%27 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%28 = add nsw i64 %24, -1
%29 = getelementptr inbounds i8*, i8** %8, i64 %28
%30 = load i8*, i8** %29
%31 = tail call i32 @fread(i8* %30, i32 1, i32 %6, i32* %27)
%32 = tail call i32 @fclose(i32* %27)
%33 = add nuw nsw i64 %24, 1
%34 = icmp eq i64 %33, %18
br i1 %34, label %19, label %23
35: ; preds = %21, %60
%36 = phi i64 [ 0, %21 ], [ %62, %60 ]
%37 = phi i32 [ 0, %21 ], [ %61, %60 ]
%38 = icmp sgt i32 %37, 0
br i1 %38, label %39, label %52
39: ; preds = %35
%40 = getelementptr inbounds i8*, i8** %8, i64 %36
%41 = zext i32 %37 to i64
br label %44
42: ; preds = %44
%43 = icmp eq i64 %51, %41
br i1 %43, label %52, label %44
44: ; preds = %39, %42
%45 = phi i64 [ 0, %39 ], [ %51, %42 ]
%46 = load i8*, i8** %40
%47 = getelementptr inbounds i8*, i8** %10, i64 %45
%48 = load i8*, i8** %47
%49 = tail call i64 @memcmp(i8* %46, i8* %48, i32 %6)
%50 = icmp eq i64 %49, 0
%51 = add nuw nsw i64 %45, 1
br i1 %50, label %60, label %42
52: ; preds = %42, %35
%53 = sext i32 %37 to i64
%54 = getelementptr inbounds i8*, i8** %10, i64 %53
%55 = load i8*, i8** %54
%56 = getelementptr inbounds i8*, i8** %8, i64 %36
%57 = load i8*, i8** %56
%58 = tail call i32 @memcpy(i8* %55, i8* %57, i32 %6)
%59 = add nsw i32 %37, 1
br label %60
60: ; preds = %44, %52
%61 = phi i32 [ %59, %52 ], [ %37, %44 ]
%62 = add nuw nsw i64 %36, 1
%63 = icmp eq i64 %62, %22
br i1 %63, label %64, label %35
64: ; preds = %60, %3, %19
%65 = phi i32 [ 0, %19 ], [ 0, %3 ], [ %61, %60 ]
%66 = tail call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %65)
%67 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i8* %0)
%68 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%69 = icmp sgt i32 %65, 0
br i1 %69, label %70, label %79
70: ; preds = %64
%71 = zext i32 %65 to i64
br label %72
72: ; preds = %70, %72
%73 = phi i64 [ 0, %70 ], [ %77, %72 ]
%74 = getelementptr inbounds i8*, i8** %10, i64 %73
%75 = load i8*, i8** %74
%76 = tail call i32 @fwrite(i8* %75, i32 1, i32 %6, i32* %68)
%77 = add nuw nsw i64 %73, 1
%78 = icmp eq i64 %77, %71
br i1 %78, label %79, label %72
79: ; preds = %72, %64
%80 = tail call i32 @fclose(i32* %68)
%81 = load i8*, i8** %10
%82 = tail call i32 @memcpy(i8* %12, i8* %81, i32 %6)
%83 = icmp eq i32 %6, 0
br i1 %83, label %109, label %84
84: ; preds = %79
%85 = icmp sgt i32 %65, 1
%86 = zext i32 %6 to i64
%87 = zext i32 %65 to i64
br label %88
88: ; preds = %84, %104
%89 = phi i64 [ 0, %84 ], [ %107, %104 ]
br i1 %85, label %90, label %104
90: ; preds = %88
%91 = getelementptr inbounds i8, i8* %12, i64 %89
%92 = load i8, i8* %91
br label %95
93: ; preds = %95
%94 = icmp eq i64 %102, %87
br i1 %94, label %104, label %95
95: ; preds = %90, %93
%96 = phi i64 [ 1, %90 ], [ %102, %93 ]
%97 = getelementptr inbounds i8*, i8** %10, i64 %96
%98 = load i8*, i8** %97
%99 = getelementptr inbounds i8, i8* %98, i64 %89
%100 = load i8, i8* %99
%101 = icmp eq i8 %100, %92
%102 = add nuw nsw i64 %96, 1
br i1 %101, label %93, label %103
103: ; preds = %95
store i8 0, i8* %91
br label %104
104: ; preds = %93, %88, %103
%105 = phi i8 [ 1, %103 ], [ 0, %88 ], [ 0, %93 ]
%106 = getelementptr inbounds i8, i8* %14, i64 %89
store i8 %105, i8* %106
%107 = add nuw nsw i64 %89, 1
%108 = icmp eq i64 %107, %86
br i1 %108, label %109, label %88
109: ; preds = %104, %79
%110 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i8* %0)
%111 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%112 = tail call i32 @fwrite(i8* %12, i32 1, i32 %6, i32* %111)
%113 = tail call i32 @fclose(i32* %111)
%114 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i8* %0)
%115 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%116 = tail call i32 @fwrite(i8* %14, i32 1, i32 %6, i32* %115)
%117 = tail call i32 @fclose(i32* %115)
%118 = tail call i32 @free_bimat(i8** %8, i32 0, i32 %1, i32 0, i32 %6)
%119 = tail call i32 @free_bimat(i8** %10, i32 0, i32 %1, i32 0, i32 %6)
%120 = tail call i32 @free_mat(i8* %12, i32 0, i32 %6)
%121 = tail call i32 @free_mat(i8* %14, i32 0, i32 %6)
ret void
}