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

/* Variables and functions */
int Calculate_Error(int **, int *, int);
int /*<<< orphan*/ Generate_Pattern(int **);
int Set_Initial_State(int **, int *, int);
int /*<<< orphan*/ Set_Weight_Value(int **, int **);
int /*<<< orphan*/ Update_State(int **, int *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int, double);
int /*<<< orphan*/ srand(unsigned int);
scalar_t__ time(int /*<<< orphan*/ *);
int main() {
  int pattern[5][100];
  int state[100];
  int w[100][100];
  int set_pattern;
  int error;
  int rec_times;
  int iteration, exp, noise;
  FILE *fp;
  fp = fopen("noise_error.dat", "w");
  srand((unsigned int)time((time_t *)0));
  for (noise = 1; noise < 90; noise++) {
    rec_times = 0;
    for (exp = 0; exp < 100; exp++) {
      Generate_Pattern(pattern);
      Set_Weight_Value(pattern, w);
      set_pattern = Set_Initial_State(pattern, state, noise);
      iteration = 1;
      do {
        Update_State(w, state);
        error = Calculate_Error(pattern, state, set_pattern);
        iteration++;
      } while (iteration < 1e4 && error != 0);
      if (error == 0) {
        rec_times++;
      }
    }
    fprintf(fp, "%d %f\n", noise, 100.0 * rec_times / (double)100);
  }
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa5e0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe57(%rip),%rdi
lea    0xe60(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0xa5d0(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1090 <time@plt>
mov    %eax,%edi
call   1070 <srand@plt>
movl   $0x1,-0xa5c8(%rbp)
cmpl   $0x5a,-0xa5c8(%rbp)
jge    135f <main+0x1bf>
movl   $0x0,-0xa5bc(%rbp)
movl   $0x0,-0xa5c4(%rbp)
cmpl   $0x64,-0xa5c4(%rbp)
jge    1312 <main+0x172>
lea    -0x7e0(%rbp),%rdi
call   10c0 <Generate_Pattern@plt>
lea    -0x7e0(%rbp),%rdi
lea    -0xa5b0(%rbp),%rsi
call   10a0 <Set_Weight_Value@plt>
lea    -0x7e0(%rbp),%rdi
lea    -0x970(%rbp),%rsi
mov    -0xa5c8(%rbp),%edx
call   1060 <Set_Initial_State@plt>
mov    %eax,-0xa5b4(%rbp)
movl   $0x1,-0xa5c0(%rbp)
lea    -0xa5b0(%rbp),%rdi
lea    -0x970(%rbp),%rsi
call   1040 <Update_State@plt>
lea    -0x7e0(%rbp),%rdi
lea    -0x970(%rbp),%rsi
mov    -0xa5b4(%rbp),%edx
call   1030 <Calculate_Error@plt>
mov    %eax,-0xa5b8(%rbp)
mov    -0xa5c0(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xa5c0(%rbp)
cvtsi2sdl -0xa5c0(%rbp),%xmm1
ff
xor    %eax,%eax
movsd  0xd59(%rip),%xmm0
ucomisd %xmm1,%xmm0
mov    %al,-0xa5d1(%rbp)
jbe    12cf <main+0x12f>
cmpl   $0x0,-0xa5b8(%rbp)
setne  %al
mov    %al,-0xa5d1(%rbp)
mov    -0xa5d1(%rbp),%al
test   $0x1,%al
jne    125c <main+0xbc>
cmpl   $0x0,-0xa5b8(%rbp)
jne    12f9 <main+0x159>
mov    -0xa5bc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xa5bc(%rbp)
jmp    12fe <main+0x15e>
mov    -0xa5c4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xa5c4(%rbp)
jmp    1207 <main+0x67>
mov    -0xa5d0(%rbp),%rdi
mov    -0xa5c8(%rbp),%edx
cvtsi2sdl -0xa5bc(%rbp),%xmm1
ff
movsd  0xcd1(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  0xcc5(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0xcdc(%rip),%rsi
call   1080 <fprintf@plt>
mov    -0xa5c8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xa5c8(%rbp)
jmp    11e6 <main+0x46>
mov    -0xa5d0(%rbp),%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
add    $0xa5e0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xa5b8,%rsp
lea    0xe50(%rip),%rdi
lea    0xe59(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,0x8(%rsp)
xor    %edi,%edi
call   1090 <time@plt>
mov    %eax,%edi
call   1070 <srand@plt>
movl   $0x1,(%rsp)
lea    0x1a0(%rsp),%rbx
lea    0x970(%rsp),%r12
lea    0x10(%rsp),%rbp
jmp    1241 <main+0xa1>
cs nopw 0x0(%rax,%rax,1)
nop
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  0xdf1(%rip),%xmm1
mulsd  %xmm1,%xmm0
divsd  %xmm1,%xmm0
mov    0x8(%rsp),%rdi
lea    0xdf7(%rip),%rsi
mov    (%rsp),%r14d
mov    %r14d,%edx
call   1080 <fprintf@plt>
add    $0x1,%r14d
mov    %r14d,(%rsp)
cmp    $0x5a,%r14d
je     12cc <main+0x12c>
xor    %eax,%eax
xor    %r15d,%r15d
jmp    1264 <main+0xc4>
nopl   0x0(%rax,%rax,1)
cmp    $0x1,%eax
mov    0x4(%rsp),%eax
adc    $0x0,%eax
add    $0x1,%r15d
cmp    $0x64,%r15d
je     1200 <main+0x60>
mov    %eax,0x4(%rsp)
mov    %rbx,%rdi
call   10c0 <Generate_Pattern@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   10a0 <Set_Weight_Value@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    (%rsp),%edx
call   1060 <Set_Initial_State@plt>
mov    %eax,%r13d
mov    $0x1,%r14d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r12,%rdi
mov    %rbp,%rsi
call   1040 <Update_State@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %r13d,%edx
call   1030 <Calculate_Error@plt>
cmp    $0x270e,%r14d
ja     1250 <main+0xb0>
add    $0x1,%r14d
test   %eax,%eax
jne    12a0 <main+0x100>
jmp    1250 <main+0xb0>
mov    0x8(%rsp),%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
add    $0xa5b8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [16 x i8] c"noise_error.dat\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [7 x i8] c"%d %f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [5 x [100 x i32]]
%3 = alloca [100 x i32]
%4 = alloca [100 x [100 x i32]]
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32*
store i32 0, i32* %1
%12 = call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %12, i32** %11
%13 = call i64 @time(i32* null)
%14 = trunc i64 %13 to i32
%15 = call i32 @srand(i32 %14)
store i32 1, i32* %10
br label %16
16: ; preds = %76, %0
%17 = load i32, i32* %10
%18 = icmp slt i32 %17, 90
br i1 %18, label %19, label %79
19: ; preds = %16
store i32 0, i32* %7
store i32 0, i32* %9
br label %20
20: ; preds = %65, %19
%21 = load i32, i32* %9
%22 = icmp slt i32 %21, 100
br i1 %22, label %23, label %68
23: ; preds = %20
%24 = getelementptr inbounds [5 x [100 x i32]], [5 x [100 x i32]]* %2, i64 0, i64 0
%25 = bitcast [100 x i32]* %24 to i32**
%26 = call i32 @Generate_Pattern(i32** %25)
%27 = getelementptr inbounds [5 x [100 x i32]], [5 x [100 x i32]]* %2, i64 0, i64 0
%28 = bitcast [100 x i32]* %27 to i32**
%29 = getelementptr inbounds [100 x [100 x i32]], [100 x [100 x i32]]* %4, i64 0, i64 0
%30 = bitcast [100 x i32]* %29 to i32**
%31 = call i32 @Set_Weight_Value(i32** %28, i32** %30)
%32 = getelementptr inbounds [5 x [100 x i32]], [5 x [100 x i32]]* %2, i64 0, i64 0
%33 = bitcast [100 x i32]* %32 to i32**
%34 = getelementptr inbounds [100 x i32], [100 x i32]* %3, i64 0, i64 0
%35 = load i32, i32* %10
%36 = call i32 @Set_Initial_State(i32** %33, i32* %34, i32 %35)
store i32 %36, i32* %5
store i32 1, i32* %8
br label %37
37: ; preds = %56, %23
%38 = getelementptr inbounds [100 x [100 x i32]], [100 x [100 x i32]]* %4, i64 0, i64 0
%39 = bitcast [100 x i32]* %38 to i32**
%40 = getelementptr inbounds [100 x i32], [100 x i32]* %3, i64 0, i64 0
%41 = call i32 @Update_State(i32** %39, i32* %40)
%42 = getelementptr inbounds [5 x [100 x i32]], [5 x [100 x i32]]* %2, i64 0, i64 0
%43 = bitcast [100 x i32]* %42 to i32**
%44 = getelementptr inbounds [100 x i32], [100 x i32]* %3, i64 0, i64 0
%45 = load i32, i32* %5
%46 = call i32 @Calculate_Error(i32** %43, i32* %44, i32 %45)
store i32 %46, i32* %6
%47 = load i32, i32* %8
%48 = add nsw i32 %47, 1
store i32 %48, i32* %8
br label %49
49: ; preds = %37
%50 = load i32, i32* %8
%51 = sitofp i32 %50 to double
%52 = fcmp olt double %51, 1.000000e+04
br i1 %52, label %53, label %56
53: ; preds = %49
%54 = load i32, i32* %6
%55 = icmp ne i32 %54, 0
br label %56
56: ; preds = %53, %49
%57 = phi i1 [ false, %49 ], [ %55, %53 ]
br i1 %57, label %37, label %58
58: ; preds = %56
%59 = load i32, i32* %6
%60 = icmp eq i32 %59, 0
br i1 %60, label %61, label %64
61: ; preds = %58
%62 = load i32, i32* %7
%63 = add nsw i32 %62, 1
store i32 %63, i32* %7
br label %64
64: ; preds = %61, %58
br label %65
65: ; preds = %64
%66 = load i32, i32* %9
%67 = add nsw i32 %66, 1
store i32 %67, i32* %9
br label %20
68: ; preds = %20
%69 = load i32*, i32** %11
%70 = load i32, i32* %10
%71 = load i32, i32* %7
%72 = sitofp i32 %71 to double
%73 = fmul double 1.000000e+02, %72
%74 = fdiv double %73, 1.000000e+02
%75 = call i32 @fprintf(i32* %69, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %70, double %74)
br label %76
76: ; preds = %68
%77 = load i32, i32* %10
%78 = add nsw i32 %77, 1
store i32 %78, i32* %10
br label %16
79: ; preds = %16
%80 = load i32*, i32** %11
%81 = call i32 @fclose(i32* %80)
ret i32 0
}

LLVM IR (-O2):
@.str = [16 x i8] c"noise_error.dat\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [7 x i8] c"%d %f\0A\00"
define i32 @main() {
%1 = alloca [5 x [100 x i32]]
%2 = alloca [100 x i32]
%3 = alloca [100 x [100 x i32]]
%4 = bitcast [5 x [100 x i32]]* %1 to i8*
%5 = bitcast [100 x i32]* %2 to i8*
%6 = bitcast [100 x [100 x i32]]* %3 to i8*
%7 = tail call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%8 = tail call i64 @time(i32* null)
%9 = trunc i64 %8 to i32
%10 = tail call i32 @srand(i32 %9)
%11 = bitcast [5 x [100 x i32]]* %1 to i32**
%12 = bitcast [100 x [100 x i32]]* %3 to i32**
%13 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 0
br label %14
14: ; preds = %0, %36
%15 = phi i32 [ 1, %0 ], [ %41, %36 ]
br label %16
16: ; preds = %14, %30
%17 = phi i32 [ 0, %14 ], [ %33, %30 ]
%18 = phi i32 [ 0, %14 ], [ %34, %30 ]
%19 = call i32 @Generate_Pattern(i32** %11)
%20 = call i32 @Set_Weight_Value(i32** %11, i32** %12)
%21 = call i32 @Set_Initial_State(i32** %11, i32* %13, i32 %15)
br label %22
22: ; preds = %22, %16
%23 = phi i32 [ 1, %16 ], [ %26, %22 ]
%24 = call i32 @Update_State(i32** %12, i32* %13)
%25 = call i32 @Calculate_Error(i32** %11, i32* %13, i32 %21)
%26 = add nuw nsw i32 %23, 1
%27 = icmp ult i32 %23, 9999
%28 = icmp ne i32 %25, 0
%29 = select i1 %27, i1 %28, i1 false
br i1 %29, label %22, label %30
30: ; preds = %22
%31 = icmp eq i32 %25, 0
%32 = zext i1 %31 to i32
%33 = add nuw nsw i32 %17, %32
%34 = add nuw nsw i32 %18, 1
%35 = icmp eq i32 %34, 100
br i1 %35, label %36, label %16
36: ; preds = %30
%37 = sitofp i32 %33 to double
%38 = fmul double %37, 1.000000e+02
%39 = fdiv double %38, 1.000000e+02
%40 = call i32 @fprintf(i32* %7, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %15, double %39)
%41 = add nuw nsw i32 %15, 1
%42 = icmp eq i32 %41, 90
br i1 %42, label %43, label %14
43: ; preds = %36
%44 = call i32 @fclose(i32* %7)
ret i32 0
}