#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 char FILE;

/* Variables and functions */
int /*<<< orphan*/ PerformSOM(char *, int, int, int, double const, char, char *,
                              int, int, int, double const, char);
int /*<<< orphan*/ Save(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ fclose(char *);
char *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, ...);
char *strchr(char *, char);
int strlen(char *);
void SOM(char genemetric, char arraymetric, int x, int y, int Rows, int Columns,
         char *jobname) {
  char *filename;
  char *extension;
  FILE *GeneFile = NULL;
  FILE *ArrayFile = NULL;
  FILE *DataFile = NULL;
  int GeneIters;
  int ArrayIters;
  const double tau = 0.02;
  int n = 1 + strlen(jobname) + strlen("-SOM") + strlen(".ext");
  if (genemetric) {
    int dummy = x;
    do
      n++;
    while (dummy /= 10);
    dummy = y;
    do
      n++;
    while (dummy /= 10);
    n += strlen("-G");
    n++;
  }
  if (arraymetric) {
    int dummy = x;
    do
      n++;
    while (dummy /= 10);
    dummy = y;
    do
      n++;
    while (dummy /= 10);
    n += strlen("-A");
    n++;
  }
  filename = malloc(n * sizeof(char));
  sprintf(filename, "%s-SOM", jobname);
  if (genemetric)
    sprintf(strchr(filename, '\0'), "-G%d-%d", x, y);
  if (arraymetric)
    sprintf(strchr(filename, '\0'), "-A%d-%d", x, y);
  extension = strchr(filename, '\0');
  sprintf(extension, ".txt");
  DataFile = fopen(filename, "wt");
  if (!DataFile) {
    printf("Failed to open output file %s", filename);
    free(filename);
    return;
  }
  if (genemetric) {
    sprintf(extension, ".gnf");
    GeneFile = fopen(filename, "wt");
    if (!GeneFile) {
      printf("Failed to open output file %s", filename);
      free(filename);
      return;
    }
    GeneIters = 100000;
  } else
    GeneIters = 0;
  if (arraymetric) {
    sprintf(extension, ".anf");
    ArrayFile = fopen(filename, "wt");
    if (!ArrayFile) {
      printf("Failed to open output file %s", filename);
      free(filename);
      if (GeneFile)
        free(GeneFile);
      return;
    }
    ArrayIters = 20000;
  } else
    ArrayIters = 0;
  free(filename);
  PerformSOM(GeneFile, x, y, GeneIters, tau, genemetric, ArrayFile, x, y,
             ArrayIters, tau, arraymetric);
  if (GeneFile)
    fclose(GeneFile);
  if (ArrayFile)
    fclose(ArrayFile);
  Save(DataFile, 0, 0);
  fclose(DataFile);
  return;
}


x86 assembly (clang, -O0):
<SOM>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %sil,%al
mov    %dil,%sil
mov    0x10(%rbp),%rdi
mov    %sil,-0x1(%rbp)
mov    %al,-0x2(%rbp)
mov    %edx,-0x8(%rbp)
mov    %ecx,-0xc(%rbp)
mov    %r8d,-0x10(%rbp)
mov    %r9d,-0x14(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
movsd  0xe16(%rip),%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    0x10(%rbp),%rdi
call   1050 <strlen@plt>
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
lea    0xe10(%rip),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x64(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x60(%rbp)
lea    0xded(%rip),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x60(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x54(%rbp)
cmpb   $0x0,-0x1(%rbp)
je     129b <SOM+0xfb>
mov    -0x8(%rbp),%eax
mov    %eax,-0x58(%rbp)
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
mov    -0x58(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x58(%rbp)
cmp    $0x0,%eax
jne    123a <SOM+0x9a>
mov    -0xc(%rbp),%eax
mov    %eax,-0x58(%rbp)
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
mov    -0x58(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x58(%rbp)
cmp    $0x0,%eax
jne    1260 <SOM+0xc0>
lea    0xd86(%rip),%rdi
call   1050 <strlen@plt>
add    -0x54(%rbp),%eax
mov    %eax,-0x54(%rbp)
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
cmpb   $0x0,-0x2(%rbp)
je     130c <SOM+0x16c>
mov    -0x8(%rbp),%eax
mov    %eax,-0x5c(%rbp)
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
mov    -0x5c(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x5c(%rbp)
cmp    $0x0,%eax
jne    12ab <SOM+0x10b>
mov    -0xc(%rbp),%eax
mov    %eax,-0x5c(%rbp)
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
mov    -0x5c(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x5c(%rbp)
cmp    $0x0,%eax
jne    12d1 <SOM+0x131>
lea    0xd18(%rip),%rdi
call   1050 <strlen@plt>
add    -0x54(%rbp),%eax
mov    %eax,-0x54(%rbp)
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
movslq -0x54(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    0x10(%rbp),%rdx
lea    0xce5(%rip),%rsi
mov    $0x0,%al
call   10b0 <sprintf@plt>
cmpb   $0x0,-0x1(%rbp)
je     1361 <SOM+0x1c1>
mov    -0x20(%rbp),%rdi
xor    %esi,%esi
call   1060 <strchr@plt>
mov    %rax,%rdi
mov    -0x8(%rbp),%edx
mov    -0xc(%rbp),%ecx
lea    0xcc0(%rip),%rsi
mov    $0x0,%al
call   10b0 <sprintf@plt>
cmpb   $0x0,-0x2(%rbp)
je     138d <SOM+0x1ed>
mov    -0x20(%rbp),%rdi
xor    %esi,%esi
call   1060 <strchr@plt>
mov    %rax,%rdi
mov    -0x8(%rbp),%edx
mov    -0xc(%rbp),%ecx
lea    0xc9c(%rip),%rsi
mov    $0x0,%al
call   10b0 <sprintf@plt>
mov    -0x20(%rbp),%rdi
xor    %esi,%esi
call   1060 <strchr@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xc83(%rip),%rsi
mov    $0x0,%al
call   10b0 <sprintf@plt>
mov    -0x20(%rbp),%rdi
lea    0xc76(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    13eb <SOM+0x24b>
mov    -0x20(%rbp),%rsi
lea    0xc5a(%rip),%rdi
call   1070 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
jmp    1567 <SOM+0x3c7>
cmpb   $0x0,-0x1(%rbp)
je     1450 <SOM+0x2b0>
mov    -0x28(%rbp),%rdi
lea    0xc50(%rip),%rsi
mov    $0x0,%al
call   10b0 <sprintf@plt>
mov    -0x20(%rbp),%rdi
lea    0xc1d(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1444 <SOM+0x2a4>
mov    -0x20(%rbp),%rsi
lea    0xc01(%rip),%rdi
call   1070 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
jmp    1567 <SOM+0x3c7>
movl   $0x186a0,-0x44(%rbp)
jmp    1457 <SOM+0x2b7>
movl   $0x0,-0x44(%rbp)
cmpb   $0x0,-0x2(%rbp)
je     14d0 <SOM+0x330>
mov    -0x28(%rbp),%rdi
lea    0xbe9(%rip),%rsi
mov    $0x0,%al
call   10b0 <sprintf@plt>
mov    -0x20(%rbp),%rdi
lea    0xbb1(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    14c4 <SOM+0x324>
mov    -0x20(%rbp),%rsi
lea    0xb95(%rip),%rdi
call   1070 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x30(%rbp)
je     14bf <SOM+0x31f>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
jmp    1567 <SOM+0x3c7>
movl   $0x4e20,-0x48(%rbp)
jmp    14d7 <SOM+0x337>
movl   $0x0,-0x48(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x44(%rbp),%ecx
mov    -0x1(%rbp),%r8b
mov    -0x38(%rbp),%r9
mov    -0x8(%rbp),%r11d
mov    -0xc(%rbp),%r10d
mov    -0x48(%rbp),%eax
movsd  0xaf8(%rip),%xmm1
movaps %xmm1,%xmm0
movsbl %r8b,%r8d
mov    %r11d,(%rsp)
mov    %r10d,0x8(%rsp)
mov    %eax,0x10(%rsp)
movsbl -0x2(%rbp),%eax
mov    %eax,0x18(%rsp)
call   1090 <PerformSOM@plt>
cmpq   $0x0,-0x30(%rbp)
je     153d <SOM+0x39d>
mov    -0x30(%rbp),%rdi
call   1040 <fclose@plt>
cmpq   $0x0,-0x38(%rbp)
je     1551 <SOM+0x3b1>
mov    -0x38(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x40(%rbp),%rdi
xor    %edx,%edx
mov    %edx,%esi
call   10c0 <Save@plt>
mov    -0x40(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SOM>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %ecx,%r12d
mov    %edx,%r15d
mov    %esi,(%rsp)
mov    %edi,%r13d
mov    0x50(%rsp),%r14
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %eax,%ebx
lea    0xe55(%rip),%rdi
call   1050 <strlen@plt>
mov    %eax,%ebp
add    %ebx,%ebp
lea    0xe38(%rip),%rdi
call   1050 <strlen@plt>
test   %r13b,%r13b
je     125a <SOM+0xca>
lea    (%rax,%rbp,1),%ebx
add    $0x2,%ebx
mov    %r15d,%eax
nopw   0x0(%rax,%rax,1)
movslq %eax,%rcx
imul   $0x66666667,%rcx,%rax
mov    %rax,%rdx
shr    $0x3f,%rdx
sar    $0x22,%rax
add    %edx,%eax
add    $0x9,%ecx
add    $0x1,%ebx
cmp    $0x12,%ecx
ja     11f0 <SOM+0x60>
mov    %r12d,%eax
cs nopw 0x0(%rax,%rax,1)
nop
movslq %eax,%rcx
imul   $0x66666667,%rcx,%rax
mov    %rax,%rdx
shr    $0x3f,%rdx
sar    $0x22,%rax
add    %edx,%eax
add    $0x9,%ecx
add    $0x1,%ebx
cmp    $0x12,%ecx
ja     1220 <SOM+0x90>
lea    0xdc4(%rip),%rdi
call   1050 <strlen@plt>
mov    %eax,%ebp
add    %ebx,%ebp
cmpb   $0x0,(%rsp)
jne    1265 <SOM+0xd5>
jmp    12d0 <SOM+0x140>
add    %eax,%ebp
add    $0x1,%ebp
cmpb   $0x0,(%rsp)
je     12d0 <SOM+0x140>
add    $0x1,%ebp
mov    %r15d,%eax
nopl   0x0(%rax,%rax,1)
movslq %eax,%rcx
imul   $0x66666667,%rcx,%rax
mov    %rax,%rdx
shr    $0x3f,%rdx
sar    $0x22,%rax
add    %edx,%eax
add    $0x9,%ecx
add    $0x1,%ebp
cmp    $0x12,%ecx
ja     1270 <SOM+0xe0>
mov    %r12d,%eax
cs nopw 0x0(%rax,%rax,1)
nop
movslq %eax,%rcx
imul   $0x66666667,%rcx,%rax
mov    %rax,%rdx
shr    $0x3f,%rdx
sar    $0x22,%rax
add    %edx,%eax
add    $0x9,%ecx
add    $0x1,%ebp
cmp    $0x12,%ecx
ja     12a0 <SOM+0x110>
lea    0xd47(%rip),%rdi
call   1050 <strlen@plt>
add    %eax,%ebp
mov    %ebp,%edi
call   1070 <malloc@plt>
mov    %rax,%rbp
lea    0xd32(%rip),%rsi
mov    %rax,%rdi
mov    %r14,%rdx
xor    %eax,%eax
call   10a0 <sprintf@plt>
test   %r13b,%r13b
je     1313 <SOM+0x183>
mov    %rbp,%rdi
call   1050 <strlen@plt>
lea    (%rax,%rbp,1),%rdi
lea    0xd14(%rip),%rsi
mov    %r15d,%edx
mov    %r12d,%ecx
xor    %eax,%eax
call   10a0 <sprintf@plt>
cmpb   $0x0,(%rsp)
je     1339 <SOM+0x1a9>
mov    %rbp,%rdi
call   1050 <strlen@plt>
lea    (%rax,%rbp,1),%rdi
lea    0xcf6(%rip),%rsi
mov    %r15d,%edx
mov    %r12d,%ecx
xor    %eax,%eax
call   10a0 <sprintf@plt>
mov    %r12,0x10(%rsp)
mov    %rbp,%rdi
call   1050 <strlen@plt>
mov    %rax,%rbx
movl   $0x7478742e,0x0(%rbp,%rax,1)
74
movb   $0x0,0x4(%rbp,%rax,1)
lea    0xcd2(%rip),%rsi
mov    %rbp,%rdi
call   1090 <fopen@plt>
test   %rax,%rax
je     13b5 <SOM+0x225>
mov    %rax,%r12
mov    %r15,0x8(%rsp)
mov    %rbp,%r14
add    %rbx,%r14
xor    %ebx,%ebx
test   %r13b,%r13b
je     13da <SOM+0x24a>
movb   $0x0,0x4(%r14)
movl   $0x666e672e,(%r14)
lea    0xc9d(%rip),%rsi
mov    %rbp,%rdi
call   1090 <fopen@plt>
test   %rax,%rax
je     13b5 <SOM+0x225>
mov    %rax,%r15
movl   $0x186a0,0x4(%rsp)
cmpb   $0x0,(%rsp)
jne    13eb <SOM+0x25b>
xor    %r14d,%r14d
jmp    1417 <SOM+0x287>
lea    0xc76(%rip),%rdi
mov    %rbp,%rsi
call   1060 <printf@plt>
mov    %rbp,%rdi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>
movl   $0x0,0x4(%rsp)
xor    %r15d,%r15d
cmpb   $0x0,(%rsp)
je     13b0 <SOM+0x220>
movb   $0x0,0x4(%r14)
movl   $0x666e612e,(%r14)
lea    0xc31(%rip),%rsi
mov    %rbp,%rdi
call   1090 <fopen@plt>
test   %rax,%rax
je     148f <SOM+0x2ff>
mov    %rax,%r14
mov    $0x4e20,%ebx
mov    %rbp,%rdi
call   1030 <free@plt>
movsbl (%rsp),%eax
movsbl %r13b,%r8d
movsd  0xbd1(%rip),%xmm0
mov    %r15,%rdi
mov    0x8(%rsp),%rsi
mov    0x10(%rsp),%rdx
mov    0x4(%rsp),%ecx
mov    %r14,%r9
movaps %xmm0,%xmm1
push   %rax
push   %rbx
push   %rdx
push   %rsi
call   1080 <PerformSOM@plt>
add    $0x20,%rsp
test   %r15,%r15
je     1460 <SOM+0x2d0>
mov    %r15,%rdi
call   1040 <fclose@plt>
test   %r14,%r14
je     146d <SOM+0x2dd>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %r12,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   10b0 <Save@plt>
mov    %r12,%rdi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <fclose@plt>
lea    0xb9c(%rip),%rdi
mov    %rbp,%rsi
call   1060 <printf@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
test   %r15,%r15
je     14b3 <SOM+0x323>
mov    %r15,%rdi
jmp    13c7 <SOM+0x237>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"-SOM\00"
@.str.1 = [5 x i8] c".ext\00"
@.str.2 = [3 x i8] c"-G\00"
@.str.3 = [3 x i8] c"-A\00"
@.str.4 = [7 x i8] c"%s-SOM\00"
@.str.5 = [8 x i8] c"-G%d-%d\00"
@.str.6 = [8 x i8] c"-A%d-%d\00"
@.str.7 = [5 x i8] c".txt\00"
@.str.8 = [3 x i8] c"wt\00"
@.str.9 = [30 x i8] c"Failed to open output file %s\00"
@.str.10 = [5 x i8] c".gnf\00"
@.str.11 = [5 x i8] c".anf\00"
define void @SOM(i8 signext %0, i8 signext %1, i32 %2, i32 %3, i32 %4, i32 %5, i8* %6) {
%8 = alloca i8
%9 = alloca i8
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i8*
%15 = alloca i8*
%16 = alloca i8*
%17 = alloca i8*
%18 = alloca i8*
%19 = alloca i8*
%20 = alloca i32
%21 = alloca i32
%22 = alloca double
%23 = alloca i32
%24 = alloca i32
%25 = alloca i32
store i8 %0, i8* %8
store i8 %1, i8* %9
store i32 %2, i32* %10
store i32 %3, i32* %11
store i32 %4, i32* %12
store i32 %5, i32* %13
store i8* %6, i8** %14
store i8* null, i8** %17
store i8* null, i8** %18
store i8* null, i8** %19
store double 2.000000e-02, double* %22
%26 = load i8*, i8** %14
%27 = call i32 @strlen(i8* %26)
%28 = add nsw i32 1, %27
%29 = call i32 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%30 = add nsw i32 %28, %29
%31 = call i32 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%32 = add nsw i32 %30, %31
store i32 %32, i32* %23
%33 = load i8, i8* %8
%34 = icmp ne i8 %33, 0
br i1 %34, label %35, label %59
35: ; preds = %7
%36 = load i32, i32* %10
store i32 %36, i32* %24
br label %37
37: ; preds = %40, %35
%38 = load i32, i32* %23
%39 = add nsw i32 %38, 1
store i32 %39, i32* %23
br label %40
40: ; preds = %37
%41 = load i32, i32* %24
%42 = sdiv i32 %41, 10
store i32 %42, i32* %24
%43 = icmp ne i32 %42, 0
br i1 %43, label %37, label %44
44: ; preds = %40
%45 = load i32, i32* %11
store i32 %45, i32* %24
br label %46
46: ; preds = %49, %44
%47 = load i32, i32* %23
%48 = add nsw i32 %47, 1
store i32 %48, i32* %23
br label %49
49: ; preds = %46
%50 = load i32, i32* %24
%51 = sdiv i32 %50, 10
store i32 %51, i32* %24
%52 = icmp ne i32 %51, 0
br i1 %52, label %46, label %53
53: ; preds = %49
%54 = call i32 @strlen(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%55 = load i32, i32* %23
%56 = add nsw i32 %55, %54
store i32 %56, i32* %23
%57 = load i32, i32* %23
%58 = add nsw i32 %57, 1
store i32 %58, i32* %23
br label %59
59: ; preds = %53, %7
%60 = load i8, i8* %9
%61 = icmp ne i8 %60, 0
br i1 %61, label %62, label %86
62: ; preds = %59
%63 = load i32, i32* %10
store i32 %63, i32* %25
br label %64
64: ; preds = %67, %62
%65 = load i32, i32* %23
%66 = add nsw i32 %65, 1
store i32 %66, i32* %23
br label %67
67: ; preds = %64
%68 = load i32, i32* %25
%69 = sdiv i32 %68, 10
store i32 %69, i32* %25
%70 = icmp ne i32 %69, 0
br i1 %70, label %64, label %71
71: ; preds = %67
%72 = load i32, i32* %11
store i32 %72, i32* %25
br label %73
73: ; preds = %76, %71
%74 = load i32, i32* %23
%75 = add nsw i32 %74, 1
store i32 %75, i32* %23
br label %76
76: ; preds = %73
%77 = load i32, i32* %25
%78 = sdiv i32 %77, 10
store i32 %78, i32* %25
%79 = icmp ne i32 %78, 0
br i1 %79, label %73, label %80
80: ; preds = %76
%81 = call i32 @strlen(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%82 = load i32, i32* %23
%83 = add nsw i32 %82, %81
store i32 %83, i32* %23
%84 = load i32, i32* %23
%85 = add nsw i32 %84, 1
store i32 %85, i32* %23
br label %86
86: ; preds = %80, %59
%87 = load i32, i32* %23
%88 = sext i32 %87 to i64
%89 = mul i64 %88, 1
%90 = trunc i64 %89 to i32
%91 = call i8* @malloc(i32 %90)
store i8* %91, i8** %15
%92 = load i8*, i8** %15
%93 = load i8*, i8** %14
%94 = call i32 (i8*, i8*, ...) @sprintf(i8* %92, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8* %93)
%95 = load i8, i8* %8
%96 = icmp ne i8 %95, 0
br i1 %96, label %97, label %103
97: ; preds = %86
%98 = load i8*, i8** %15
%99 = call i8* @strchr(i8* %98, i8 signext 0)
%100 = load i32, i32* %10
%101 = load i32, i32* %11
%102 = call i32 (i8*, i8*, ...) @sprintf(i8* %99, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i32 %100, i32 %101)
br label %103
103: ; preds = %97, %86
%104 = load i8, i8* %9
%105 = icmp ne i8 %104, 0
br i1 %105, label %106, label %112
106: ; preds = %103
%107 = load i8*, i8** %15
%108 = call i8* @strchr(i8* %107, i8 signext 0)
%109 = load i32, i32* %10
%110 = load i32, i32* %11
%111 = call i32 (i8*, i8*, ...) @sprintf(i8* %108, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i32 %109, i32 %110)
br label %112
112: ; preds = %106, %103
%113 = load i8*, i8** %15
%114 = call i8* @strchr(i8* %113, i8 signext 0)
store i8* %114, i8** %16
%115 = load i8*, i8** %16
%116 = call i32 (i8*, i8*, ...) @sprintf(i8* %115, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%117 = load i8*, i8** %15
%118 = call i8* @fopen(i8* %117, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0))
store i8* %118, i8** %19
%119 = load i8*, i8** %19
%120 = icmp ne i8* %119, null
br i1 %120, label %126, label %121
121: ; preds = %112
%122 = load i8*, i8** %15
%123 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.9, i64 0, i64 0), i8* %122)
%124 = load i8*, i8** %15
%125 = call i32 @free(i8* %124)
br label %196
126: ; preds = %112
%127 = load i8, i8* %8
%128 = icmp ne i8 %127, 0
br i1 %128, label %129, label %142
129: ; preds = %126
%130 = load i8*, i8** %16
%131 = call i32 (i8*, i8*, ...) @sprintf(i8* %130, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0))
%132 = load i8*, i8** %15
%133 = call i8* @fopen(i8* %132, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0))
store i8* %133, i8** %17
%134 = load i8*, i8** %17
%135 = icmp ne i8* %134, null
br i1 %135, label %141, label %136
136: ; preds = %129
%137 = load i8*, i8** %15
%138 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.9, i64 0, i64 0), i8* %137)
%139 = load i8*, i8** %15
%140 = call i32 @free(i8* %139)
br label %196
141: ; preds = %129
store i32 100000, i32* %20
br label %143
142: ; preds = %126
store i32 0, i32* %20
br label %143
143: ; preds = %142, %141
%144 = load i8, i8* %9
%145 = icmp ne i8 %144, 0
br i1 %145, label %146, label %165
146: ; preds = %143
%147 = load i8*, i8** %16
%148 = call i32 (i8*, i8*, ...) @sprintf(i8* %147, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.11, i64 0, i64 0))
%149 = load i8*, i8** %15
%150 = call i8* @fopen(i8* %149, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0))
store i8* %150, i8** %18
%151 = load i8*, i8** %18
%152 = icmp ne i8* %151, null
br i1 %152, label %164, label %153
153: ; preds = %146
%154 = load i8*, i8** %15
%155 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.9, i64 0, i64 0), i8* %154)
%156 = load i8*, i8** %15
%157 = call i32 @free(i8* %156)
%158 = load i8*, i8** %17
%159 = icmp ne i8* %158, null
br i1 %159, label %160, label %163
160: ; preds = %153
%161 = load i8*, i8** %17
%162 = call i32 @free(i8* %161)
br label %163
163: ; preds = %160, %153
br label %196
164: ; preds = %146
store i32 20000, i32* %21
br label %166
165: ; preds = %143
store i32 0, i32* %21
br label %166
166: ; preds = %165, %164
%167 = load i8*, i8** %15
%168 = call i32 @free(i8* %167)
%169 = load i8*, i8** %17
%170 = load i32, i32* %10
%171 = load i32, i32* %11
%172 = load i32, i32* %20
%173 = load i8, i8* %8
%174 = load i8*, i8** %18
%175 = load i32, i32* %10
%176 = load i32, i32* %11
%177 = load i32, i32* %21
%178 = load i8, i8* %9
%179 = call i32 @PerformSOM(i8* %169, i32 %170, i32 %171, i32 %172, double 2.000000e-02, i8 signext %173, i8* %174, i32 %175, i32 %176, i32 %177, double 2.000000e-02, i8 signext %178)
%180 = load i8*, i8** %17
%181 = icmp ne i8* %180, null
br i1 %181, label %182, label %185
182: ; preds = %166
%183 = load i8*, i8** %17
%184 = call i32 @fclose(i8* %183)
br label %185
185: ; preds = %182, %166
%186 = load i8*, i8** %18
%187 = icmp ne i8* %186, null
br i1 %187, label %188, label %191
188: ; preds = %185
%189 = load i8*, i8** %18
%190 = call i32 @fclose(i8* %189)
br label %191
191: ; preds = %188, %185
%192 = load i8*, i8** %19
%193 = call i32 @Save(i8* %192, i32 0, i32 0)
%194 = load i8*, i8** %19
%195 = call i32 @fclose(i8* %194)
br label %196
196: ; preds = %191, %163, %136, %121
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"-SOM\00"
@.str.1 = [5 x i8] c".ext\00"
@.str.2 = [3 x i8] c"-G\00"
@.str.3 = [3 x i8] c"-A\00"
@.str.4 = [7 x i8] c"%s-SOM\00"
@.str.5 = [8 x i8] c"-G%d-%d\00"
@.str.6 = [8 x i8] c"-A%d-%d\00"
@.str.7 = [5 x i8] c".txt\00"
@.str.8 = [3 x i8] c"wt\00"
@.str.9 = [30 x i8] c"Failed to open output file %s\00"
@.str.10 = [5 x i8] c".gnf\00"
@.str.11 = [5 x i8] c".anf\00"
define void @SOM(i8 signext %0, i8 signext %1, i32 %2, i32 %3, i32 %4, i32 %5, i8* %6) {
%8 = tail call i32 @strlen(i8* %6)
%9 = add nsw i32 %8, 1
%10 = tail call i32 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%11 = add nsw i32 %9, %10
%12 = tail call i32 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%13 = add nsw i32 %11, %12
%14 = icmp eq i8 %0, 0
br i1 %14, label %33, label %15
15: ; preds = %7, %15
%16 = phi i32 [ %18, %15 ], [ %13, %7 ]
%17 = phi i32 [ %19, %15 ], [ %2, %7 ]
%18 = add nsw i32 %16, 1
%19 = sdiv i32 %17, 10
%20 = add i32 %17, 9
%21 = icmp ult i32 %20, 19
br i1 %21, label %22, label %15
22: ; preds = %15, %22
%23 = phi i32 [ %25, %22 ], [ %18, %15 ]
%24 = phi i32 [ %26, %22 ], [ %3, %15 ]
%25 = add nsw i32 %23, 1
%26 = sdiv i32 %24, 10
%27 = add i32 %24, 9
%28 = icmp ult i32 %27, 19
br i1 %28, label %29, label %22
29: ; preds = %22
%30 = tail call i32 @strlen(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%31 = add i32 %23, 2
%32 = add i32 %31, %30
br label %33
33: ; preds = %29, %7
%34 = phi i32 [ %32, %29 ], [ %13, %7 ]
%35 = icmp eq i8 %1, 0
br i1 %35, label %54, label %36
36: ; preds = %33, %36
%37 = phi i32 [ %39, %36 ], [ %34, %33 ]
%38 = phi i32 [ %40, %36 ], [ %2, %33 ]
%39 = add nsw i32 %37, 1
%40 = sdiv i32 %38, 10
%41 = add i32 %38, 9
%42 = icmp ult i32 %41, 19
br i1 %42, label %43, label %36
43: ; preds = %36, %43
%44 = phi i32 [ %46, %43 ], [ %39, %36 ]
%45 = phi i32 [ %47, %43 ], [ %3, %36 ]
%46 = add nsw i32 %44, 1
%47 = sdiv i32 %45, 10
%48 = add i32 %45, 9
%49 = icmp ult i32 %48, 19
br i1 %49, label %50, label %43
50: ; preds = %43
%51 = tail call i32 @strlen(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%52 = add i32 %44, 2
%53 = add i32 %52, %51
br label %54
54: ; preds = %50, %33
%55 = phi i32 [ %53, %50 ], [ %34, %33 ]
%56 = tail call i8* @malloc(i32 %55)
%57 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %56, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8* %6)
br i1 %14, label %62, label %58
58: ; preds = %54
%59 = tail call i64 bitcast (i32 (i8*)* @strlen to i64 (i8*)*)(i8* %56)
%60 = getelementptr i8, i8* %56, i64 %59
%61 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %60, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i32 %2, i32 %3)
br label %62
62: ; preds = %58, %54
br i1 %35, label %67, label %63
63: ; preds = %62
%64 = tail call i64 bitcast (i32 (i8*)* @strlen to i64 (i8*)*)(i8* %56)
%65 = getelementptr i8, i8* %56, i64 %64
%66 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %65, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i32 %2, i32 %3)
br label %67
67: ; preds = %63, %62
%68 = tail call i64 bitcast (i32 (i8*)* @strlen to i64 (i8*)*)(i8* %56)
%69 = getelementptr i8, i8* %56, i64 %68
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(5) %69, i8* align 1 dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i64 5, i1 false)
%70 = tail call i8* @fopen(i8* %56, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0))
%71 = icmp eq i8* %70, null
br i1 %71, label %72, label %75
72: ; preds = %67
%73 = tail call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.9, i64 0, i64 0), i8* %56)
%74 = tail call i32 @free(i8* %56)
br label %109
75: ; preds = %67
br i1 %14, label %82, label %76
76: ; preds = %75
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(5) %69, i8* align 1 dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0), i64 5, i1 false)
%77 = tail call i8* @fopen(i8* %56, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0))
%78 = icmp eq i8* %77, null
br i1 %78, label %79, label %82
79: ; preds = %76
%80 = tail call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.9, i64 0, i64 0), i8* %56)
%81 = tail call i32 @free(i8* %56)
br label %109
82: ; preds = %75, %76
%83 = phi i32 [ 100000, %76 ], [ 0, %75 ]
%84 = phi i8* [ %77, %76 ], [ null, %75 ]
br i1 %35, label %94, label %85
85: ; preds = %82
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(5) %69, i8* align 1 dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.11, i64 0, i64 0), i64 5, i1 false)
%86 = tail call i8* @fopen(i8* %56, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0))
%87 = icmp eq i8* %86, null
br i1 %87, label %88, label %94
88: ; preds = %85
%89 = tail call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.9, i64 0, i64 0), i8* %56)
%90 = tail call i32 @free(i8* %56)
%91 = icmp eq i8* %84, null
br i1 %91, label %109, label %92
92: ; preds = %88
%93 = tail call i32 @free(i8* %84)
br label %109
94: ; preds = %82, %85
%95 = phi i8* [ %86, %85 ], [ null, %82 ]
%96 = phi i32 [ 20000, %85 ], [ 0, %82 ]
%97 = tail call i32 @free(i8* %56)
%98 = tail call i32 @PerformSOM(i8* %84, i32 %2, i32 %3, i32 %83, double 2.000000e-02, i8 signext %0, i8* %95, i32 %2, i32 %3, i32 %96, double 2.000000e-02, i8 signext %1)
%99 = icmp eq i8* %84, null
br i1 %99, label %102, label %100
100: ; preds = %94
%101 = tail call i32 @fclose(i8* %84)
br label %102
102: ; preds = %100, %94
%103 = icmp eq i8* %95, null
br i1 %103, label %106, label %104
104: ; preds = %102
%105 = tail call i32 @fclose(i8* %95)
br label %106
106: ; preds = %104, %102
%107 = tail call i32 @Save(i8* %70, i32 0, i32 0)
%108 = tail call i32 @fclose(i8* %70)
br label %109
109: ; preds = %88, %92, %106, %79, %72
ret void
}