#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 /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputc(int /*<<< orphan*/ *, char);
float log(float);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ random();
int /*<<< orphan*/ srand(int);
int main(int argc, char *argv[]) {
  if (argc != 3) {
    printf("Error. Pls supply 3 arguments 1: Length untrained seq 2) length "
           "training data 3) avg numb of state change per training length.\n");
    printf("Four file will be output: \"unkhmm.symb\", unkhmm.states\", "
           "\"trnhmm.symb\" and finally \"trnhmm.states\"");
    exit(EXIT_FAILURE);
  }
  FILE *fusy = fopen("./unkhmm.symb", "w");
  FILE *fusta = fopen("./unkhmm.states", "w");
  FILE *ftsy = fopen("./trnhmm.symb", "w");
  FILE *ftsta = fopen("./trnhmm.states", "w");
  int sqlen = atoi(argv[1]);
  float evplen = atof(argv[2]);
  srand(5);
  float lam = evplen / sqlen;
  int i = 0;
  float ura;
  float wt;
  float twt = .0, oldtwt = .0;
  char cc[2] = {'A', 'B'};
  unsigned char c = 0;
  while (1) {
    ura = 1. - (float)random() / (RAND_MAX + 1L);
    wt = -log(ura) / lam;
    twt += wt;
    while ((i <= (int)twt) & (i < sqlen)) {
      fputc(ftsy, cc[0x01 & c]);
      i++;
    }
    printf("\n");
    if (twt >= sqlen)
      break;
    c++;
  }
  printf("\ni is %i\n", i);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11da <main+0x4a>
lea    0xe51(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xec3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2e05(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
lea    0xf0a(%rip),%rdi
lea    0xf11(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
lea    0xf03(%rip),%rdi
lea    0xefa(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x20(%rbp)
lea    0xefc(%rip),%rdi
lea    0xee3(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x28(%rbp)
lea    0xef3(%rip),%rdi
lea    0xecc(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1030 <atof@plt>
movss  %xmm0,-0x38(%rbp)
mov    $0x5,%edi
call   1060 <srand@plt>
movss  -0x38(%rbp),%xmm0
cvtsi2ssl -0x34(%rbp),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x3c(%rbp)
movl   $0x0,-0x40(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x4c(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x50(%rbp)
mov    0xea0(%rip),%ax
mov    %ax,-0x52(%rbp)
movb   $0x0,-0x53(%rbp)
mov    $0x0,%al
call   1070 <random@plt>
cvtsi2ss %rax,%xmm0
mov    0x2d3a(%rip),%rax
mov    (%rax),%rax
add    $0x1,%rax
cvtsi2ss %rax,%xmm1
divss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xd36(%rip),%xmm0
subsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x44(%rbp)
movss  -0x44(%rbp),%xmm0
call   1080 <log@plt>
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
divss  -0x3c(%rbp),%xmm0
movss  %xmm0,-0x48(%rbp)
movss  -0x48(%rbp),%xmm0
addss  -0x4c(%rbp),%xmm0
movss  %xmm0,-0x4c(%rbp)
mov    -0x40(%rbp),%eax
cvttss2si -0x4c(%rbp),%ecx
cmp    %ecx,%eax
setle  %al
and    $0x1,%al
movzbl %al,%eax
mov    -0x40(%rbp),%ecx
cmp    -0x34(%rbp),%ecx
setl   %cl
and    $0x1,%cl
movzbl %cl,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     1358 <main+0x1c8>
mov    -0x28(%rbp),%rdi
movzbl -0x53(%rbp),%eax
and    $0x1,%eax
cltq
movsbl -0x52(%rbp,%rax,1),%esi
call   1050 <fputc@plt>
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    1307 <main+0x177>
lea    0xd27(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movss  -0x4c(%rbp),%xmm0
cvtsi2ssl -0x34(%rbp),%xmm1
ucomiss %xmm1,%xmm0
jb     137e <main+0x1ee>
jmp    138b <main+0x1fb>
mov    -0x53(%rbp),%al
add    $0x1,%al
mov    %al,-0x53(%rbp)
jmp    129b <main+0x10b>
mov    -0x40(%rbp),%esi
lea    0xd94(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
cmp    $0x3,%edi
jne    1357 <main+0x1a7>
mov    %rsi,%rbx
lea    0xe96(%rip),%rdi
lea    0xe9d(%rip),%rbp
mov    %rbp,%rsi
call   10b0 <fopen@plt>
lea    0xe90(%rip),%rdi
mov    %rbp,%rsi
call   10b0 <fopen@plt>
lea    0xe91(%rip),%rdi
mov    %rbp,%rsi
call   10b0 <fopen@plt>
mov    %rax,0x10(%rsp)
lea    0xe8b(%rip),%rdi
mov    %rbp,%rsi
call   10b0 <fopen@plt>
mov    0x8(%rbx),%rdi
call   10c0 <atoi@plt>
mov    %eax,%r14d
mov    0x10(%rbx),%rdi
call   1050 <atof@plt>
movss  %xmm0,0x4(%rsp)
mov    $0x5,%edi
call   1080 <srand@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %r14d,%xmm0
movss  %xmm0,0x8(%rsp)
movss  0x4(%rsp),%xmm1
divss  %xmm0,%xmm1
movss  %xmm1,0x4(%rsp)
xorps  %xmm0,%xmm0
xor    %ebx,%ebx
xor    %ebp,%ebp
jmp    1282 <main+0xd2>
xchg   %ax,%ax
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0xc(%rsp),%ebp
add    $0x1,%bpl
movss  (%rsp),%xmm0
ucomiss 0x8(%rsp),%xmm0
jae    1336 <main+0x186>
movss  %xmm0,(%rsp)
xor    %eax,%eax
call   1090 <random@plt>
xorps  %xmm1,%xmm1
cvtsi2ss %rax,%xmm1
mov    0x2d4b(%rip),%rax
mov    (%rax),%rax
add    $0x1,%rax
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
divss  %xmm0,%xmm1
movss  0xd48(%rip),%xmm0
subss  %xmm1,%xmm0
call   10a0 <log@plt>
divss  0x4(%rsp),%xmm0
movss  (%rsp),%xmm1
subss  %xmm0,%xmm1
movss  %xmm1,(%rsp)
cvttss2si (%rsp),%r12d
cmp    %r12d,%ebx
mov    %ebp,0xc(%rsp)
jg     1260 <main+0xb0>
cmp    %r14d,%ebx
jge    1260 <main+0xb0>
movzbl %bpl,%eax
and    $0x1,%eax
lea    0xe2f(%rip),%rcx
mov    (%rax,%rcx,1),%r15b
mov    0x10(%rsp),%rbp
nopl   0x0(%rax,%rax,1)
mov    %ebx,%r13d
movsbl %r15b,%esi
mov    %rbp,%rdi
call   1070 <fputc@plt>
lea    0x1(%r13),%ebx
cmp    %r12d,%r13d
jge    1260 <main+0xb0>
cmp    %r14d,%ebx
jl     1310 <main+0x160>
jmp    1260 <main+0xb0>
lea    0xd68(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd51(%rip),%rdi
call   1040 <puts@plt>
lea    0xc9a(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x2c60(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
@.str = [128 x i8] c"Error. Pls supply 3 arguments 1: Length untrained seq 2) length training data 3) avg numb of state change per training length.\0A\00"
@.str.1 = [99 x i8] c"Four file will be output: \22unkhmm.symb\22, unkhmm.states\22, \22trnhmm.symb\22 and finally \22trnhmm.states\22\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [14 x i8] c"./unkhmm.symb\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [16 x i8] c"./unkhmm.states\00"
@.str.5 = [14 x i8] c"./trnhmm.symb\00"
@.str.6 = [16 x i8] c"./trnhmm.states\00"
@__const.main.cc = [2 x i8] c"AB"
@RAND_MAX = global i64 0
@.str.7 = [2 x i8] c"\0A\00"
@.str.8 = [10 x i8] c"\0Ai is %i\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 i32*
%10 = alloca i32
%11 = alloca float
%12 = alloca float
%13 = alloca i32
%14 = alloca float
%15 = alloca float
%16 = alloca float
%17 = alloca float
%18 = alloca [2 x i8]
%19 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%20 = load i32, i32* %4
%21 = icmp ne i32 %20, 3
br i1 %21, label %22, label %27
22: ; preds = %2
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @.str, i64 0, i64 0))
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([99 x i8], [99 x i8]* @.str.1, i64 0, i64 0))
%25 = load i32, i32* @EXIT_FAILURE
%26 = call i32 @exit(i32 %25)
unreachable
27: ; preds = %2
%28 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %28, i32** %6
%29 = call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %29, i32** %7
%30 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %30, i32** %8
%31 = call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %31, i32** %9
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 1
%34 = load i8*, i8** %33
%35 = call i32 @atoi(i8* %34)
store i32 %35, i32* %10
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 2
%38 = load i8*, i8** %37
%39 = call float @atof(i8* %38)
store float %39, float* %11
%40 = call i32 @srand(i32 5)
%41 = load float, float* %11
%42 = load i32, i32* %10
%43 = sitofp i32 %42 to float
%44 = fdiv float %41, %43
store float %44, float* %12
store i32 0, i32* %13
store float 0.000000e+00, float* %16
store float 0.000000e+00, float* %17
%45 = bitcast [2 x i8]* %18 to i8*
store i8 0, i8* %19
br label %46
46: ; preds = %27, %94
%47 = call i64 (...) @random()
%48 = sitofp i64 %47 to float
%49 = load i64, i64* @RAND_MAX
%50 = add nsw i64 %49, 1
%51 = sitofp i64 %50 to float
%52 = fdiv float %48, %51
%53 = fpext float %52 to double
%54 = fsub double 1.000000e+00, %53
%55 = fptrunc double %54 to float
store float %55, float* %14
%56 = load float, float* %14
%57 = call float @log(float %56)
%58 = fneg float %57
%59 = load float, float* %12
%60 = fdiv float %58, %59
store float %60, float* %15
%61 = load float, float* %15
%62 = load float, float* %16
%63 = fadd float %62, %61
store float %63, float* %16
br label %64
64: ; preds = %76, %46
%65 = load i32, i32* %13
%66 = load float, float* %16
%67 = fptosi float %66 to i32
%68 = icmp sle i32 %65, %67
%69 = zext i1 %68 to i32
%70 = load i32, i32* %13
%71 = load i32, i32* %10
%72 = icmp slt i32 %70, %71
%73 = zext i1 %72 to i32
%74 = and i32 %69, %73
%75 = icmp ne i32 %74, 0
br i1 %75, label %76, label %87
76: ; preds = %64
%77 = load i32*, i32** %8
%78 = load i8, i8* %19
%79 = zext i8 %78 to i32
%80 = and i32 1, %79
%81 = sext i32 %80 to i64
%82 = getelementptr inbounds [2 x i8], [2 x i8]* %18, i64 0, i64 %81
%83 = load i8, i8* %82
%84 = call i32 @fputc(i32* %77, i8 signext %83)
%85 = load i32, i32* %13
%86 = add nsw i32 %85, 1
store i32 %86, i32* %13
br label %64
87: ; preds = %64
%88 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%89 = load float, float* %16
%90 = load i32, i32* %10
%91 = sitofp i32 %90 to float
%92 = fcmp oge float %89, %91
br i1 %92, label %93, label %94
93: ; preds = %87
br label %97
94: ; preds = %87
%95 = load i8, i8* %19
%96 = add i8 %95, 1
store i8 %96, i8* %19
br label %46
97: ; preds = %93
%98 = load i32, i32* %13
%99 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0), i32 %98)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [99 x i8] c"Four file will be output: \22unkhmm.symb\22, unkhmm.states\22, \22trnhmm.symb\22 and finally \22trnhmm.states\22\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [14 x i8] c"./unkhmm.symb\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [16 x i8] c"./unkhmm.states\00"
@.str.5 = [14 x i8] c"./trnhmm.symb\00"
@.str.6 = [16 x i8] c"./trnhmm.states\00"
@__const.main.cc = [2 x i8] c"AB"
@RAND_MAX = global i64 0
@.str.8 = [10 x i8] c"\0Ai is %i\0A\00"
@str = [127 x i8] c"Error. Pls supply 3 arguments 1: Length untrained seq 2) length training data 3) avg numb of state change per training length.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %9, label %4
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([127 x i8], [127 x i8]* @str, i64 0, i64 0))
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([99 x i8], [99 x i8]* @.str.1, i64 0, i64 0))
%7 = load i32, i32* @EXIT_FAILURE
%8 = tail call i32 @exit(i32 %7)
unreachable
9: ; preds = %2
%10 = tail call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%11 = tail call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%12 = tail call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%13 = tail call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = tail call i32 @atoi(i8* %15)
%17 = getelementptr inbounds i8*, i8** %1, i64 2
%18 = load i8*, i8** %17
%19 = tail call float @atof(i8* %18)
%20 = tail call i32 @srand(i32 5)
%21 = sitofp i32 %16 to float
%22 = fdiv float %19, %21
br label %23
23: ; preds = %53, %9
%24 = phi float [ 0.000000e+00, %9 ], [ %36, %53 ]
%25 = phi i32 [ 0, %9 ], [ %54, %53 ]
%26 = phi i8 [ 0, %9 ], [ %57, %53 ]
%27 = tail call i64 (...) @random()
%28 = sitofp i64 %27 to float
%29 = load i64, i64* @RAND_MAX
%30 = add nsw i64 %29, 1
%31 = sitofp i64 %30 to float
%32 = fdiv float %28, %31
%33 = fsub float 1.000000e+00, %32
%34 = tail call float @log(float %33)
%35 = fdiv float %34, %22
%36 = fsub float %24, %35
%37 = fptosi float %36 to i32
%38 = icmp sle i32 %25, %37
%39 = icmp slt i32 %25, %16
%40 = and i1 %38, %39
br i1 %40, label %41, label %53
41: ; preds = %23
%42 = and i8 %26, 1
%43 = zext i8 %42 to i64
%44 = getelementptr inbounds [2 x i8], [2 x i8]* @__const.main.cc, i64 0, i64 %43
%45 = load i8, i8* %44
br label %46
46: ; preds = %41, %46
%47 = phi i32 [ %25, %41 ], [ %49, %46 ]
%48 = tail call i32 @fputc(i32* %12, i8 signext %45)
%49 = add nsw i32 %47, 1
%50 = icmp slt i32 %47, %37
%51 = icmp slt i32 %49, %16
%52 = and i1 %50, %51
br i1 %52, label %46, label %53
53: ; preds = %46, %23
%54 = phi i32 [ %25, %23 ], [ %49, %46 ]
%55 = tail call i32 @putchar(i32 10)
%56 = fcmp ult float %36, %21
%57 = add i8 %26, 1
br i1 %56, label %23, label %58
58: ; preds = %53
%59 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0), i32 %54)
ret i32 0
}