#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*/ EXIT_FAILURE;
long RAND_MAX;
float atof(char *);
int atoi(char *);
int chanceit(int, int *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/ *);
float log(float);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ random();
int /*<<< orphan*/ srand(int);
int main(int argc, char *argv[]) {
  if (argc != 4) {
    printf("Error. Pls supply 3 arguments 1) Length unknown seq 2) length "
           "training data 3) avg numb of state change per training length.\n");
    printf("This program generates state and symbols sequences based on a six "
           "sided die for testing purposes.\n");
    printf("A training sequence is also given as many hmm detectors require "
           "one.\n");
    printf("Example usage: %s 200 20 2 will give you an average of two state "
           "changes in training data of length 20;\n",
           argv[0]);
    printf("This same rate si the used for the true unknown sequence of length "
           "200\n");
    printf("Four files will be output: \"unkhmm.symb\", unkhmm.states\", "
           "\"trnhmm.symb\" and finally \"trnhmm.states\"\n");
    exit(EXIT_FAILURE);
  }
  int tsqlen = atoi(argv[1]);
  int sqlen = atoi(argv[2]);
  int rem = tsqlen % sqlen;
  if (rem) {
    printf("Sorry: one of the rules is that total unknown sequence length "
           "needs to be perfectly\n");
    printf("divisible by the training sequence length\n");
    exit(EXIT_FAILURE);
  }
  srand(5);
  float evplen = atof(argv[3]);
  float lam = evplen / sqlen;
  int i = 0;
  float ura;
  float wt;
  float twt = .0;
  char cc[2] = {'A', 'B'};
  int die[2][6] = {{1, 1, 1, 1, 1, 1}, {1, 1, 1, 1, 1, 20}};
  unsigned char c = 0;
  FILE *ftsy = fopen("./trnhmm.symb", "w");
  FILE *ftsta = fopen("./trnhmm.states", "w");
  int tstacha = 0;
  while (1) {
    ura = 1. - (float)random() / (RAND_MAX + 1L);
    wt = -log(ura) / lam;
    twt += wt;
    while ((i <= (int)twt) & (i < sqlen)) {
      fputc(cc[0x01 & c], ftsy);
      fputc(48 + chanceit(6, die[0x01 & c]), ftsta);
      i++;
    }
    if (twt >= sqlen)
      break;
    c++;
    tstacha++;
  }
  fputc('\n', ftsy);
  fputc('\n', ftsta);
  fclose(ftsy);
  fclose(ftsta);
  FILE *fusy = fopen("./unkhmm.symb", "w");
  FILE *fusta = fopen("./unkhmm.states", "w");
  c = 0;
  i = 0;
  twt = .0;
  int ustacha = 0;
  while (1) {
    ura = 1. - (float)random() / (RAND_MAX + 1L);
    wt = -log(ura) / lam;
    twt += wt;
    while ((i <= (int)twt) & (i < tsqlen)) {
      fputc(cc[0x01 & c], fusy);
      fputc(48 + chanceit(6, die[0x01 & c]), fusta);
      i++;
    }
    if (twt >= tsqlen)
      break;
    ustacha++;
    c++;
  }
  fputc('\n', fusy);
  fputc('\n', fusta);
  fclose(fusy);
  fclose(fusta);
  printf("Program run report: %i states changes reg in training set; %i state "
         "changes in unknown set.\n",
         tstacha, ustacha);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x8(%rbp)
je     124c <main+0x8c>
lea    0xe1e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe8e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xee3(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xf14(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xf6f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xfa9(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2d93(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10d0 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10d0 <atoi@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
cltd
idivl  -0x18(%rbp)
mov    %edx,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     12aa <main+0xea>
lea    0xfbe(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0x1005(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2d35(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
mov    $0x5,%edi
call   1080 <srand@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1030 <atof@plt>
movss  %xmm0,-0x20(%rbp)
movss  -0x20(%rbp),%xmm0
cvtsi2ssl -0x18(%rbp),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x34(%rbp)
mov    0x1071(%rip),%ax
mov    %ax,-0x36(%rbp)
lea    -0x70(%rbp),%rdi
lea    0x1072(%rip),%rsi
mov    $0x30,%edx
call   1090 <memcpy@plt>
movb   $0x0,-0x71(%rbp)
lea    0xfb2(%rip),%rdi
lea    0xfb9(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x80(%rbp)
lea    0xfab(%rip),%rdi
lea    0xfa2(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x88(%rbp)
movl   $0x0,-0x8c(%rbp)
mov    $0x0,%al
call   10a0 <random@plt>
cvtsi2ss %rax,%xmm0
mov    0x2c8e(%rip),%rax
mov    (%rax),%rax
add    $0x1,%rax
cvtsi2ss %rax,%xmm1
divss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xc8a(%rip),%xmm0
subsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x2c(%rbp)
movss  -0x2c(%rbp),%xmm0
call   10b0 <log@plt>
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
divss  -0x24(%rbp),%xmm0
movss  %xmm0,-0x30(%rbp)
movss  -0x30(%rbp),%xmm0
addss  -0x34(%rbp),%xmm0
movss  %xmm0,-0x34(%rbp)
mov    -0x28(%rbp),%eax
cvttss2si -0x34(%rbp),%ecx
cmp    %ecx,%eax
setle  %al
and    $0x1,%al
movzbl %al,%eax
mov    -0x28(%rbp),%ecx
cmp    -0x18(%rbp),%ecx
setl   %cl
and    $0x1,%cl
movzbl %cl,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     1436 <main+0x276>
movzbl -0x71(%rbp),%eax
and    $0x1,%eax
cltq
mov    -0x36(%rbp,%rax,1),%al
mov    -0x80(%rbp),%rsi
movsbl %al,%edi
call   1070 <fputc@plt>
movzbl -0x71(%rbp),%eax
and    $0x1,%eax
cltq
lea    -0x70(%rbp),%rsi
imul   $0x18,%rax,%rax
add    %rax,%rsi
mov    $0x6,%edi
call   1060 <chanceit@plt>
add    $0x30,%eax
mov    -0x88(%rbp),%rsi
movsbl %al,%edi
call   1070 <fputc@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    13b3 <main+0x1f3>
movss  -0x34(%rbp),%xmm0
cvtsi2ssl -0x18(%rbp),%xmm1
ucomiss %xmm1,%xmm0
jb     144e <main+0x28e>
jmp    146a <main+0x2aa>
mov    -0x71(%rbp),%al
add    $0x1,%al
mov    %al,-0x71(%rbp)
mov    -0x8c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8c(%rbp)
jmp    1347 <main+0x187>
mov    -0x80(%rbp),%rsi
mov    $0xa,%edi
call   1070 <fputc@plt>
mov    -0x88(%rbp),%rsi
mov    $0xa,%edi
call   1070 <fputc@plt>
mov    -0x80(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x88(%rbp),%rdi
call   1040 <fclose@plt>
lea    0xe40(%rip),%rdi
lea    0xe27(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x98(%rbp)
lea    0xe34(%rip),%rdi
lea    0xe0d(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0xa0(%rbp)
movb   $0x0,-0x71(%rbp)
movl   $0x0,-0x28(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x34(%rbp)
movl   $0x0,-0xa4(%rbp)
mov    $0x0,%al
call   10a0 <random@plt>
cvtsi2ss %rax,%xmm0
mov    0x2ae6(%rip),%rax
mov    (%rax),%rax
add    $0x1,%rax
cvtsi2ss %rax,%xmm1
divss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xae2(%rip),%xmm0
subsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x2c(%rbp)
movss  -0x2c(%rbp),%xmm0
call   10b0 <log@plt>
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
divss  -0x24(%rbp),%xmm0
movss  %xmm0,-0x30(%rbp)
movss  -0x30(%rbp),%xmm0
addss  -0x34(%rbp),%xmm0
movss  %xmm0,-0x34(%rbp)
mov    -0x28(%rbp),%eax
cvttss2si -0x34(%rbp),%ecx
cmp    %ecx,%eax
setle  %al
and    $0x1,%al
movzbl %al,%eax
mov    -0x28(%rbp),%ecx
cmp    -0x14(%rbp),%ecx
setl   %cl
and    $0x1,%cl
movzbl %cl,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     15e1 <main+0x421>
movzbl -0x71(%rbp),%eax
and    $0x1,%eax
cltq
mov    -0x36(%rbp,%rax,1),%al
mov    -0x98(%rbp),%rsi
movsbl %al,%edi
call   1070 <fputc@plt>
movzbl -0x71(%rbp),%eax
and    $0x1,%eax
cltq
lea    -0x70(%rbp),%rsi
imul   $0x18,%rax,%rax
add    %rax,%rsi
mov    $0x6,%edi
call   1060 <chanceit@plt>
add    $0x30,%eax
mov    -0xa0(%rbp),%rsi
movsbl %al,%edi
call   1070 <fputc@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    155b <main+0x39b>
movss  -0x34(%rbp),%xmm0
cvtsi2ssl -0x14(%rbp),%xmm1
ucomiss %xmm1,%xmm0
jb     15f9 <main+0x439>
jmp    1615 <main+0x455>
mov    -0xa4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xa4(%rbp)
mov    -0x71(%rbp),%al
add    $0x1,%al
mov    %al,-0x71(%rbp)
jmp    14ef <main+0x32f>
mov    -0x98(%rbp),%rsi
mov    $0xa,%edi
call   1070 <fputc@plt>
mov    -0xa0(%rbp),%rsi
mov    $0xa,%edi
call   1070 <fputc@plt>
mov    -0x98(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0xa0(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x8c(%rbp),%esi
mov    -0xa4(%rbp),%edx
lea    0xca1(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
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    $0x68,%rsp
mov    %rsi,%r14
cmp    $0x4,%edi
jne    1549 <main+0x389>
mov    0x8(%r14),%rdi
call   10d0 <atoi@plt>
mov    %eax,%ebp
mov    0x10(%r14),%rdi
call   10d0 <atoi@plt>
mov    %eax,%ebx
mov    %ebp,0xc(%rsp)
mov    %ebp,%eax
cltd
idiv   %ebx
test   %edx,%edx
jne    1593 <main+0x3d3>
mov    $0x5,%edi
call   1090 <srand@plt>
mov    0x18(%r14),%rdi
call   1040 <atof@plt>
cvtsi2ss %ebx,%xmm1
movss  %xmm1,0x8(%rsp)
divss  %xmm1,%xmm0
movss  %xmm0,0x24(%rsp)
movaps 0x1161(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
movaps 0x1145(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0x1129(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
lea    0xe1a(%rip),%rdi
lea    0xe21(%rip),%rbp
mov    %rbp,%rsi
call   10c0 <fopen@plt>
mov    %rax,0x18(%rsp)
lea    0xe0f(%rip),%rdi
mov    %rbp,%rsi
call   10c0 <fopen@plt>
mov    %rax,(%rsp)
xorps  %xmm0,%xmm0
xor    %eax,%eax
xor    %ebp,%ebp
jmp    12a9 <main+0xe9>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    0x28(%rsp),%rax
add    $0x1,%eax
movss  0x10(%rsp),%xmm0
ucomiss 0x8(%rsp),%xmm0
jae    1382 <main+0x1c2>
movss  %xmm0,0x10(%rsp)
mov    %eax,%r14d
xor    %eax,%eax
call   10a0 <random@plt>
xorps  %xmm1,%xmm1
cvtsi2ss %rax,%xmm1
mov    0x2d20(%rip),%rax
mov    (%rax),%rax
add    $0x1,%rax
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
divss  %xmm0,%xmm1
movss  0xd1d(%rip),%xmm0
subss  %xmm1,%xmm0
call   10b0 <log@plt>
divss  0x24(%rsp),%xmm0
movss  0x10(%rsp),%xmm1
subss  %xmm0,%xmm1
movss  %xmm1,0x10(%rsp)
cvttss2si 0x10(%rsp),%r15d
cmp    %r15d,%ebp
mov    %r14,0x28(%rsp)
jg     1290 <main+0xd0>
cmp    %ebx,%ebp
jge    1290 <main+0xd0>
mov    %r14d,%eax
and    $0x1,%eax
lea    0x1034(%rip),%rcx
mov    (%rax,%rcx,1),%r12b
lea    (%rax,%rax,2),%rax
lea    (%rsp,%rax,8),%r14
add    $0x30,%r14
nopl   0x0(%rax)
mov    %ebp,%r13d
movsbl %r12b,%edi
mov    0x18(%rsp),%rsi
call   1080 <fputc@plt>
mov    $0x6,%edi
mov    %r14,%rsi
call   1070 <chanceit@plt>
add    $0x30,%al
movsbl %al,%edi
mov    (%rsp),%rsi
call   1080 <fputc@plt>
lea    0x1(%r13),%ebp
cmp    %r15d,%r13d
jge    1290 <main+0xd0>
cmp    %ebx,%ebp
jl     1340 <main+0x180>
jmp    1290 <main+0xd0>
mov    $0xa,%edi
mov    0x18(%rsp),%rbx
mov    %rbx,%rsi
call   1080 <fputc@plt>
mov    $0xa,%edi
mov    (%rsp),%rbp
mov    %rbp,%rsi
call   1080 <fputc@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    %rbp,%rdi
call   1050 <fclose@plt>
lea    0xcd1(%rip),%rdi
lea    0xcb8(%rip),%rbx
mov    %rbx,%rsi
call   10c0 <fopen@plt>
mov    %rax,0x18(%rsp)
lea    0xcc4(%rip),%rdi
mov    %rbx,%rsi
call   10c0 <fopen@plt>
xorps  %xmm0,%xmm0
cvtsi2ssl 0xc(%rsp),%xmm0
movss  %xmm0,0x8(%rsp)
mov    %rax,%r15
xorps  %xmm0,%xmm0
xor    %r14d,%r14d
xor    %eax,%eax
jmp    1418 <main+0x258>
nopl   0x0(%rax,%rax,1)
mov    0x10(%rsp),%rbx
lea    0x1(%rbx),%eax
movss  (%rsp),%xmm0
ucomiss 0x8(%rsp),%xmm0
jae    14f4 <main+0x334>
movss  %xmm0,(%rsp)
mov    %eax,%ebx
xor    %eax,%eax
call   10a0 <random@plt>
xorps  %xmm1,%xmm1
cvtsi2ss %rax,%xmm1
mov    0x2bb3(%rip),%rax
mov    (%rax),%rax
add    $0x1,%rax
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
divss  %xmm0,%xmm1
movss  0xbb0(%rip),%xmm0
subss  %xmm1,%xmm0
call   10b0 <log@plt>
divss  0x24(%rsp),%xmm0
movss  (%rsp),%xmm1
subss  %xmm0,%xmm1
movss  %xmm1,(%rsp)
cvttss2si (%rsp),%ebp
cmp    %ebp,%r14d
mov    %rbx,0x10(%rsp)
jg     1400 <main+0x240>
cmp    0xc(%rsp),%r14d
jge    1400 <main+0x240>
mov    %ebx,%eax
and    $0x1,%eax
lea    0xecd(%rip),%rcx
mov    (%rax,%rcx,1),%r12b
lea    (%rax,%rax,2),%rax
lea    (%rsp,%rax,8),%rbx
add    $0x30,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r14d,%r13d
movsbl %r12b,%edi
mov    0x18(%rsp),%rsi
call   1080 <fputc@plt>
mov    $0x6,%edi
mov    %rbx,%rsi
call   1070 <chanceit@plt>
add    $0x30,%al
movsbl %al,%edi
mov    %r15,%rsi
call   1080 <fputc@plt>
lea    0x1(%r13),%r14d
cmp    %ebp,%r13d
jge    1400 <main+0x240>
cmp    0xc(%rsp),%r14d
jl     14b0 <main+0x2f0>
jmp    1400 <main+0x240>
mov    $0xa,%edi
mov    0x18(%rsp),%rbp
mov    %rbp,%rsi
call   1080 <fputc@plt>
mov    $0xa,%edi
mov    %r15,%rsi
call   1080 <fputc@plt>
mov    %rbp,%rdi
call   1050 <fclose@plt>
mov    %r15,%rdi
call   1050 <fclose@plt>
lea    0xb81(%rip),%rdi
mov    0x28(%rsp),%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xc36(%rip),%rdi
call   1030 <puts@plt>
lea    0xca7(%rip),%rdi
call   1030 <puts@plt>
lea    0xcfd(%rip),%rdi
call   1030 <puts@plt>
mov    (%r14),%rsi
lea    0xa8d(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xd25(%rip),%rdi
call   1030 <puts@plt>
lea    0xd60(%rip),%rdi
jmp    15a6 <main+0x3e6>
lea    0xb6e(%rip),%rdi
call   1030 <puts@plt>
lea    0xbb6(%rip),%rdi
call   1030 <puts@plt>
mov    0x2a26(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
@.str = [126 x i8] c"Error. Pls supply 3 arguments 1) Length unknown seq 2) length training data 3) avg numb of state change per training length.\0A\00"
@.str.1 = [99 x i8] c"This program generates state and symbols sequences based on a six sided die for testing purposes.\0A\00"
@.str.2 = [70 x i8] c"A training sequence is also given as many hmm detectors require one.\0A\00"
@.str.3 = [105 x i8] c"Example usage: %s 200 20 2 will give you an average of two state changes in training data of length 20;\0A\00"
@.str.4 = [72 x i8] c"This same rate si the used for the true unknown sequence of length 200\0A\00"
@.str.5 = [101 x i8] c"Four files will be output: \22unkhmm.symb\22, unkhmm.states\22, \22trnhmm.symb\22 and finally \22trnhmm.states\22\0A\00"
@EXIT_FAILURE = global i32 0
@.str.6 = [85 x i8] c"Sorry: one of the rules is that total unknown sequence length needs to be perfectly\0A\00"
@.str.7 = [43 x i8] c"divisible by the training sequence length\0A\00"
@__const.main.cc = [2 x i8] c"AB"
@__const.main.die = [2 x [6 x i32]] [[6 x i32] [i32 1, i32 1, i32 1, i32 1, i32 1, i32 1], [6 x i32] [i32 1, i32 1, i32 1, i32 1, i32 1, i32 20]]
@.str.8 = [14 x i8] c"./trnhmm.symb\00"
@.str.9 = [2 x i8] c"w\00"
@.str.10 = [16 x i8] c"./trnhmm.states\00"
@RAND_MAX = global i64 0
@.str.11 = [14 x i8] c"./unkhmm.symb\00"
@.str.12 = [16 x i8] c"./unkhmm.states\00"
@.str.13 = [93 x i8] c"Program run report: %i states changes reg in training set; %i state changes in unknown set.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca float
%10 = alloca float
%11 = alloca i32
%12 = alloca float
%13 = alloca float
%14 = alloca float
%15 = alloca [2 x i8]
%16 = alloca [2 x [6 x i32]]
%17 = alloca i8
%18 = alloca i32*
%19 = alloca i32*
%20 = alloca i32
%21 = alloca i32*
%22 = alloca i32*
%23 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%24 = load i32, i32* %4
%25 = icmp ne i32 %24, 4
br i1 %25, label %26, label %38
26: ; preds = %2
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([126 x i8], [126 x i8]* @.str, i64 0, i64 0))
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([99 x i8], [99 x i8]* @.str.1, i64 0, i64 0))
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str.2, i64 0, i64 0))
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 0
%32 = load i8*, i8** %31
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([105 x i8], [105 x i8]* @.str.3, i64 0, i64 0), i8* %32)
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.4, i64 0, i64 0))
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([101 x i8], [101 x i8]* @.str.5, i64 0, i64 0))
%36 = load i32, i32* @EXIT_FAILURE
%37 = call i32 @exit(i32 %36)
unreachable
38: ; preds = %2
%39 = load i8**, i8*** %5
%40 = getelementptr inbounds i8*, i8** %39, i64 1
%41 = load i8*, i8** %40
%42 = call i32 @atoi(i8* %41)
store i32 %42, i32* %6
%43 = load i8**, i8*** %5
%44 = getelementptr inbounds i8*, i8** %43, i64 2
%45 = load i8*, i8** %44
%46 = call i32 @atoi(i8* %45)
store i32 %46, i32* %7
%47 = load i32, i32* %6
%48 = load i32, i32* %7
%49 = srem i32 %47, %48
store i32 %49, i32* %8
%50 = load i32, i32* %8
%51 = icmp ne i32 %50, 0
br i1 %51, label %52, label %57
52: ; preds = %38
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([85 x i8], [85 x i8]* @.str.6, i64 0, i64 0))
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.7, i64 0, i64 0))
%55 = load i32, i32* @EXIT_FAILURE
%56 = call i32 @exit(i32 %55)
unreachable
57: ; preds = %38
%58 = call i32 @srand(i32 5)
%59 = load i8**, i8*** %5
%60 = getelementptr inbounds i8*, i8** %59, i64 3
%61 = load i8*, i8** %60
%62 = call float @atof(i8* %61)
store float %62, float* %9
%63 = load float, float* %9
%64 = load i32, i32* %7
%65 = sitofp i32 %64 to float
%66 = fdiv float %63, %65
store float %66, float* %10
store i32 0, i32* %11
store float 0.000000e+00, float* %14
%67 = bitcast [2 x i8]* %15 to i8*
%68 = bitcast [2 x [6 x i32]]* %16 to i8*
store i8 0, i8* %17
%69 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
store i32* %69, i32** %18
%70 = call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
store i32* %70, i32** %19
store i32 0, i32* %20
br label %71
71: ; preds = %57, %129
%72 = call i64 (...) @random()
%73 = sitofp i64 %72 to float
%74 = load i64, i64* @RAND_MAX
%75 = add nsw i64 %74, 1
%76 = sitofp i64 %75 to float
%77 = fdiv float %73, %76
%78 = fpext float %77 to double
%79 = fsub double 1.000000e+00, %78
%80 = fptrunc double %79 to float
store float %80, float* %12
%81 = load float, float* %12
%82 = call float @log(float %81)
%83 = fneg float %82
%84 = load float, float* %10
%85 = fdiv float %83, %84
store float %85, float* %13
%86 = load float, float* %13
%87 = load float, float* %14
%88 = fadd float %87, %86
store float %88, float* %14
br label %89
89: ; preds = %101, %71
%90 = load i32, i32* %11
%91 = load float, float* %14
%92 = fptosi float %91 to i32
%93 = icmp sle i32 %90, %92
%94 = zext i1 %93 to i32
%95 = load i32, i32* %11
%96 = load i32, i32* %7
%97 = icmp slt i32 %95, %96
%98 = zext i1 %97 to i32
%99 = and i32 %94, %98
%100 = icmp ne i32 %99, 0
br i1 %100, label %101, label %123
101: ; preds = %89
%102 = load i8, i8* %17
%103 = zext i8 %102 to i32
%104 = and i32 1, %103
%105 = sext i32 %104 to i64
%106 = getelementptr inbounds [2 x i8], [2 x i8]* %15, i64 0, i64 %105
%107 = load i8, i8* %106
%108 = load i32*, i32** %18
%109 = call i32 @fputc(i8 signext %107, i32* %108)
%110 = load i8, i8* %17
%111 = zext i8 %110 to i32
%112 = and i32 1, %111
%113 = sext i32 %112 to i64
%114 = getelementptr inbounds [2 x [6 x i32]], [2 x [6 x i32]]* %16, i64 0, i64 %113
%115 = getelementptr inbounds [6 x i32], [6 x i32]* %114, i64 0, i64 0
%116 = call i32 @chanceit(i32 6, i32* %115)
%117 = add nsw i32 48, %116
%118 = trunc i32 %117 to i8
%119 = load i32*, i32** %19
%120 = call i32 @fputc(i8 signext %118, i32* %119)
%121 = load i32, i32* %11
%122 = add nsw i32 %121, 1
store i32 %122, i32* %11
br label %89
123: ; preds = %89
%124 = load float, float* %14
%125 = load i32, i32* %7
%126 = sitofp i32 %125 to float
%127 = fcmp oge float %124, %126
br i1 %127, label %128, label %129
128: ; preds = %123
br label %134
129: ; preds = %123
%130 = load i8, i8* %17
%131 = add i8 %130, 1
store i8 %131, i8* %17
%132 = load i32, i32* %20
%133 = add nsw i32 %132, 1
store i32 %133, i32* %20
br label %71
134: ; preds = %128
%135 = load i32*, i32** %18
%136 = call i32 @fputc(i8 signext 10, i32* %135)
%137 = load i32*, i32** %19
%138 = call i32 @fputc(i8 signext 10, i32* %137)
%139 = load i32*, i32** %18
%140 = call i32 @fclose(i32* %139)
%141 = load i32*, i32** %19
%142 = call i32 @fclose(i32* %141)
%143 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
store i32* %143, i32** %21
%144 = call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.12, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
store i32* %144, i32** %22
store i8 0, i8* %17
store i32 0, i32* %11
store float 0.000000e+00, float* %14
store i32 0, i32* %23
br label %145
145: ; preds = %134, %203
%146 = call i64 (...) @random()
%147 = sitofp i64 %146 to float
%148 = load i64, i64* @RAND_MAX
%149 = add nsw i64 %148, 1
%150 = sitofp i64 %149 to float
%151 = fdiv float %147, %150
%152 = fpext float %151 to double
%153 = fsub double 1.000000e+00, %152
%154 = fptrunc double %153 to float
store float %154, float* %12
%155 = load float, float* %12
%156 = call float @log(float %155)
%157 = fneg float %156
%158 = load float, float* %10
%159 = fdiv float %157, %158
store float %159, float* %13
%160 = load float, float* %13
%161 = load float, float* %14
%162 = fadd float %161, %160
store float %162, float* %14
br label %163
163: ; preds = %175, %145
%164 = load i32, i32* %11
%165 = load float, float* %14
%166 = fptosi float %165 to i32
%167 = icmp sle i32 %164, %166
%168 = zext i1 %167 to i32
%169 = load i32, i32* %11
%170 = load i32, i32* %6
%171 = icmp slt i32 %169, %170
%172 = zext i1 %171 to i32
%173 = and i32 %168, %172
%174 = icmp ne i32 %173, 0
br i1 %174, label %175, label %197
175: ; preds = %163
%176 = load i8, i8* %17
%177 = zext i8 %176 to i32
%178 = and i32 1, %177
%179 = sext i32 %178 to i64
%180 = getelementptr inbounds [2 x i8], [2 x i8]* %15, i64 0, i64 %179
%181 = load i8, i8* %180
%182 = load i32*, i32** %21
%183 = call i32 @fputc(i8 signext %181, i32* %182)
%184 = load i8, i8* %17
%185 = zext i8 %184 to i32
%186 = and i32 1, %185
%187 = sext i32 %186 to i64
%188 = getelementptr inbounds [2 x [6 x i32]], [2 x [6 x i32]]* %16, i64 0, i64 %187
%189 = getelementptr inbounds [6 x i32], [6 x i32]* %188, i64 0, i64 0
%190 = call i32 @chanceit(i32 6, i32* %189)
%191 = add nsw i32 48, %190
%192 = trunc i32 %191 to i8
%193 = load i32*, i32** %22
%194 = call i32 @fputc(i8 signext %192, i32* %193)
%195 = load i32, i32* %11
%196 = add nsw i32 %195, 1
store i32 %196, i32* %11
br label %163
197: ; preds = %163
%198 = load float, float* %14
%199 = load i32, i32* %6
%200 = sitofp i32 %199 to float
%201 = fcmp oge float %198, %200
br i1 %201, label %202, label %203
202: ; preds = %197
br label %208
203: ; preds = %197
%204 = load i32, i32* %23
%205 = add nsw i32 %204, 1
store i32 %205, i32* %23
%206 = load i8, i8* %17
%207 = add i8 %206, 1
store i8 %207, i8* %17
br label %145
208: ; preds = %202
%209 = load i32*, i32** %21
%210 = call i32 @fputc(i8 signext 10, i32* %209)
%211 = load i32*, i32** %22
%212 = call i32 @fputc(i8 signext 10, i32* %211)
%213 = load i32*, i32** %21
%214 = call i32 @fclose(i32* %213)
%215 = load i32*, i32** %22
%216 = call i32 @fclose(i32* %215)
%217 = load i32, i32* %20
%218 = load i32, i32* %23
%219 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([93 x i8], [93 x i8]* @.str.13, i64 0, i64 0), i32 %217, i32 %218)
ret i32 0
}

LLVM IR (-O2):
@.str.3 = [105 x i8] c"Example usage: %s 200 20 2 will give you an average of two state changes in training data of length 20;\0A\00"
@EXIT_FAILURE = global i32 0
@__const.main.cc = [2 x i8] c"AB"
@__const.main.die = [2 x [6 x i32]] [[6 x i32] [i32 1, i32 1, i32 1, i32 1, i32 1, i32 1], [6 x i32] [i32 1, i32 1, i32 1, i32 1, i32 1, i32 20]]
@.str.8 = [14 x i8] c"./trnhmm.symb\00"
@.str.9 = [2 x i8] c"w\00"
@.str.10 = [16 x i8] c"./trnhmm.states\00"
@RAND_MAX = global i64 0
@.str.11 = [14 x i8] c"./unkhmm.symb\00"
@.str.12 = [16 x i8] c"./unkhmm.states\00"
@.str.13 = [93 x i8] c"Program run report: %i states changes reg in training set; %i state changes in unknown set.\0A\00"
@str = [84 x i8] c"Sorry: one of the rules is that total unknown sequence length needs to be perfectly\00"
@str.14 = [42 x i8] c"divisible by the training sequence length\00"
@str.15 = [125 x i8] c"Error. Pls supply 3 arguments 1) Length unknown seq 2) length training data 3) avg numb of state change per training length.\00"
@str.16 = [98 x i8] c"This program generates state and symbols sequences based on a six sided die for testing purposes.\00"
@str.17 = [69 x i8] c"A training sequence is also given as many hmm detectors require one.\00"
@str.18 = [71 x i8] c"This same rate si the used for the true unknown sequence of length 200\00"
@str.19 = [100 x i8] c"Four files will be output: \22unkhmm.symb\22, unkhmm.states\22, \22trnhmm.symb\22 and finally \22trnhmm.states\22\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [2 x [6 x i32]]
%4 = icmp eq i32 %0, 4
br i1 %4, label %15, label %5
5: ; preds = %2
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([125 x i8], [125 x i8]* @str.15, i64 0, i64 0))
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([98 x i8], [98 x i8]* @str.16, i64 0, i64 0))
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([69 x i8], [69 x i8]* @str.17, i64 0, i64 0))
%9 = load i8*, i8** %1
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([105 x i8], [105 x i8]* @.str.3, i64 0, i64 0), i8* %9)
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([71 x i8], [71 x i8]* @str.18, i64 0, i64 0))
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([100 x i8], [100 x i8]* @str.19, i64 0, i64 0))
%13 = load i32, i32* @EXIT_FAILURE
%14 = tail call i32 @exit(i32 %13)
unreachable
15: ; preds = %2
%16 = getelementptr inbounds i8*, i8** %1, i64 1
%17 = load i8*, i8** %16
%18 = tail call i32 @atoi(i8* %17)
%19 = getelementptr inbounds i8*, i8** %1, i64 2
%20 = load i8*, i8** %19
%21 = tail call i32 @atoi(i8* %20)
%22 = srem i32 %18, %21
%23 = icmp eq i32 %22, 0
br i1 %23, label %29, label %24
24: ; preds = %15
%25 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([84 x i8], [84 x i8]* @str, i64 0, i64 0))
%26 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str.14, i64 0, i64 0))
%27 = load i32, i32* @EXIT_FAILURE
%28 = tail call i32 @exit(i32 %27)
unreachable
29: ; preds = %15
%30 = tail call i32 @srand(i32 5)
%31 = getelementptr inbounds i8*, i8** %1, i64 3
%32 = load i8*, i8** %31
%33 = tail call float @atof(i8* %32)
%34 = sitofp i32 %21 to float
%35 = fdiv float %33, %34
%36 = bitcast [2 x [6 x i32]]* %3 to i8*
%37 = tail call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
%38 = tail call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
br label %39
39: ; preds = %74, %29
%40 = phi float [ 0.000000e+00, %29 ], [ %52, %74 ]
%41 = phi i32 [ 0, %29 ], [ %77, %74 ]
%42 = phi i32 [ 0, %29 ], [ %75, %74 ]
%43 = call i64 (...) @random()
%44 = sitofp i64 %43 to float
%45 = load i64, i64* @RAND_MAX
%46 = add nsw i64 %45, 1
%47 = sitofp i64 %46 to float
%48 = fdiv float %44, %47
%49 = fsub float 1.000000e+00, %48
%50 = call float @log(float %49)
%51 = fdiv float %50, %35
%52 = fsub float %40, %51
%53 = fptosi float %52 to i32
%54 = icmp sle i32 %42, %53
%55 = icmp slt i32 %42, %21
%56 = and i1 %54, %55
br i1 %56, label %57, label %74
57: ; preds = %39
%58 = and i32 %41, 1
%59 = zext i32 %58 to i64
%60 = getelementptr inbounds [2 x i8], [2 x i8]* @__const.main.cc, i64 0, i64 %59
%61 = load i8, i8* %60
%62 = getelementptr inbounds [2 x [6 x i32]], [2 x [6 x i32]]* %3, i64 0, i64 %59, i64 0
br label %63
63: ; preds = %57, %63
%64 = phi i32 [ %42, %57 ], [ %70, %63 ]
%65 = call i32 @fputc(i8 signext %61, i32* %37)
%66 = call i32 @chanceit(i32 6, i32* %62)
%67 = trunc i32 %66 to i8
%68 = add i8 %67, 48
%69 = call i32 @fputc(i8 signext %68, i32* %38)
%70 = add nsw i32 %64, 1
%71 = icmp slt i32 %64, %53
%72 = icmp slt i32 %70, %21
%73 = and i1 %71, %72
br i1 %73, label %63, label %74
74: ; preds = %63, %39
%75 = phi i32 [ %42, %39 ], [ %70, %63 ]
%76 = fcmp ult float %52, %34
%77 = add nuw nsw i32 %41, 1
br i1 %76, label %39, label %78
78: ; preds = %74
%79 = call i32 @fputc(i8 signext 10, i32* %37)
%80 = call i32 @fputc(i8 signext 10, i32* %38)
%81 = call i32 @fclose(i32* %37)
%82 = call i32 @fclose(i32* %38)
%83 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
%84 = call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.12, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
%85 = sitofp i32 %18 to float
br label %86
86: ; preds = %121, %78
%87 = phi float [ 0.000000e+00, %78 ], [ %99, %121 ]
%88 = phi i32 [ 0, %78 ], [ %122, %121 ]
%89 = phi i32 [ 0, %78 ], [ %124, %121 ]
%90 = call i64 (...) @random()
%91 = sitofp i64 %90 to float
%92 = load i64, i64* @RAND_MAX
%93 = add nsw i64 %92, 1
%94 = sitofp i64 %93 to float
%95 = fdiv float %91, %94
%96 = fsub float 1.000000e+00, %95
%97 = call float @log(float %96)
%98 = fdiv float %97, %35
%99 = fsub float %87, %98
%100 = fptosi float %99 to i32
%101 = icmp sle i32 %88, %100
%102 = icmp slt i32 %88, %18
%103 = and i1 %101, %102
br i1 %103, label %104, label %121
104: ; preds = %86
%105 = and i32 %89, 1
%106 = zext i32 %105 to i64
%107 = getelementptr inbounds [2 x i8], [2 x i8]* @__const.main.cc, i64 0, i64 %106
%108 = load i8, i8* %107
%109 = getelementptr inbounds [2 x [6 x i32]], [2 x [6 x i32]]* %3, i64 0, i64 %106, i64 0
br label %110
110: ; preds = %104, %110
%111 = phi i32 [ %88, %104 ], [ %117, %110 ]
%112 = call i32 @fputc(i8 signext %108, i32* %83)
%113 = call i32 @chanceit(i32 6, i32* %109)
%114 = trunc i32 %113 to i8
%115 = add i8 %114, 48
%116 = call i32 @fputc(i8 signext %115, i32* %84)
%117 = add nsw i32 %111, 1
%118 = icmp slt i32 %111, %100
%119 = icmp slt i32 %117, %18
%120 = and i1 %118, %119
br i1 %120, label %110, label %121
121: ; preds = %110, %86
%122 = phi i32 [ %88, %86 ], [ %117, %110 ]
%123 = fcmp ult float %99, %85
%124 = add nuw nsw i32 %89, 1
br i1 %123, label %86, label %125
125: ; preds = %121
%126 = call i32 @fputc(i8 signext 10, i32* %83)
%127 = call i32 @fputc(i8 signext 10, i32* %84)
%128 = call i32 @fclose(i32* %83)
%129 = call i32 @fclose(i32* %84)
%130 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([93 x i8], [93 x i8]* @.str.13, i64 0, i64 0), i32 %41, i32 %89)
ret i32 0
}