#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 atoi(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fwrite(double *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char **argv) {
  int i, j, l;
  int num_inputs, num_layers;
  double buf;
  FILE *f;
  if (argc < 3) {
    printf("\n\nThis program generates the weights for the neural network.\n");
    printf(
        "You must specify the number of inputs and the number of layers.\n\n");
    printf("%s number_of_inputs number_of_layers\n\n");
    printf("For example: %s 10 3\n\n", argv[0]);
    return 0;
  }
  num_inputs = atoi(argv[1]);
  num_layers = atoi(argv[2]);
  f = fopen("weights.dat", "wb");
  perror(NULL);
  for (l = 0; l < num_layers; l++)
    for (i = 0; i < num_inputs; i++)
      for (j = 0; j < num_inputs; j++) {
        if (i == j + 1 || i == 0 && j == num_inputs - 1)
          buf = 1;
        else
          buf = 0;
        fwrite(&buf, sizeof(double), 1, f);
      }
  fclose(f);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11cb <main+0x6b>
lea    0xe81(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xeb1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xee5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xef7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12e5 <main+0x185>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x24(%rbp)
lea    0xed4(%rip),%rdi
lea    0xed9(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x38(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1060 <perror@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    12d5 <main+0x175>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    12c2 <main+0x162>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    12af <main+0x14f>
mov    -0x14(%rbp),%eax
mov    -0x18(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
je     1270 <main+0x110>
cmpl   $0x0,-0x14(%rbp)
jne    1282 <main+0x122>
mov    -0x18(%rbp),%eax
mov    -0x20(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jne    1282 <main+0x122>
movsd  0xd88(%rip),%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    128a <main+0x12a>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x38(%rbp),%rcx
lea    -0x30(%rbp),%rdi
mov    $0x8,%esi
mov    $0x1,%edx
call   1080 <fwrite@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1238 <main+0xd8>
jmp    12b4 <main+0x154>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1225 <main+0xc5>
jmp    12c7 <main+0x167>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1212 <main+0xb2>
mov    -0x38(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbp
cmp    $0x2,%edi
jg     11cf <main+0x5f>
lea    0xec8(%rip),%rdi
call   1030 <puts@plt>
lea    0xef9(%rip),%rdi
call   1030 <puts@plt>
lea    0xe63(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x0(%rbp),%rsi
lea    0xe78(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x8(%rbp),%rdi
call   1080 <atoi@plt>
mov    %eax,%ebx
mov    0x10(%rbp),%rdi
call   1080 <atoi@plt>
mov    %eax,%ebp
lea    0xe5a(%rip),%rdi
lea    0xe5f(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%r13
xor    %r12d,%r12d
xor    %edi,%edi
call   1070 <perror@plt>
mov    %ebp,0xc(%rsp)
test   %ebp,%ebp
jle    129d <main+0x12d>
movsd  0xde7(%rip),%xmm1
lea    0x10(%rsp),%r15
jmp    122b <main+0xbb>
add    $0x1,%r12d
cmp    0xc(%rsp),%r12d
je     129d <main+0x12d>
test   %ebx,%ebx
jle    1220 <main+0xb0>
xor    %ebp,%ebp
jmp    1247 <main+0xd7>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%ebp
cmp    %ebx,%ebp
je     1220 <main+0xb0>
xor    %r14d,%r14d
jmp    127e <main+0x10e>
nopl   0x0(%rax)
movsd  %xmm1,0x10(%rsp)
mov    %r15,%rdi
mov    $0x8,%esi
mov    $0x1,%edx
mov    %r13,%rcx
call   1090 <fwrite@plt>
add    $0xffffffff,%r14d
mov    %ebx,%eax
add    %r14d,%eax
movsd  0xd84(%rip),%xmm1
je     1240 <main+0xd0>
lea    (%rbx,%r14,1),%ecx
lea    (%r14,%rbp,1),%eax
xor    $0x1,%ecx
or     %ebp,%ecx
movaps %xmm1,%xmm0
je     1293 <main+0x123>
xorps  %xmm0,%xmm0
cmp    $0x1,%eax
je     1250 <main+0xe0>
movaps %xmm0,%xmm1
jmp    1250 <main+0xe0>
mov    %r13,%rdi
call   1040 <fclose@plt>
jmp    11be <main+0x4e>

LLVM IR (-O0):
@.str = [62 x i8] c"\0A\0AThis program generates the weights for the neural network.\0A\00"
@.str.1 = [66 x i8] c"You must specify the number of inputs and the number of layers.\0A\0A\00"
@.str.2 = [39 x i8] c"%s number_of_inputs number_of_layers\0A\0A\00"
@.str.3 = [23 x i8] c"For example: %s 10 3\0A\0A\00"
@.str.4 = [12 x i8] c"weights.dat\00"
@.str.5 = [3 x i8] c"wb\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 double
%12 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* %4
%14 = icmp slt i32 %13, 3
br i1 %14, label %15, label %23
15: ; preds = %2
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str, i64 0, i64 0))
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.1, i64 0, i64 0))
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0))
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 0
%21 = load i8*, i8** %20
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i8* %21)
store i32 0, i32* %3
br label %80
23: ; preds = %2
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = call i32 @atoi(i8* %26)
store i32 %27, i32* %9
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 2
%30 = load i8*, i8** %29
%31 = call i32 @atoi(i8* %30)
store i32 %31, i32* %10
%32 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
store i32* %32, i32** %12
%33 = call i32 @perror(i32* null)
store i32 0, i32* %8
br label %34
34: ; preds = %74, %23
%35 = load i32, i32* %8
%36 = load i32, i32* %10
%37 = icmp slt i32 %35, %36
br i1 %37, label %38, label %77
38: ; preds = %34
store i32 0, i32* %6
br label %39
39: ; preds = %70, %38
%40 = load i32, i32* %6
%41 = load i32, i32* %9
%42 = icmp slt i32 %40, %41
br i1 %42, label %43, label %73
43: ; preds = %39
store i32 0, i32* %7
br label %44
44: ; preds = %66, %43
%45 = load i32, i32* %7
%46 = load i32, i32* %9
%47 = icmp slt i32 %45, %46
br i1 %47, label %48, label %69
48: ; preds = %44
%49 = load i32, i32* %6
%50 = load i32, i32* %7
%51 = add nsw i32 %50, 1
%52 = icmp eq i32 %49, %51
br i1 %52, label %61, label %53
53: ; preds = %48
%54 = load i32, i32* %6
%55 = icmp eq i32 %54, 0
br i1 %55, label %56, label %62
56: ; preds = %53
%57 = load i32, i32* %7
%58 = load i32, i32* %9
%59 = sub nsw i32 %58, 1
%60 = icmp eq i32 %57, %59
br i1 %60, label %61, label %62
61: ; preds = %56, %48
store double 1.000000e+00, double* %11
br label %63
62: ; preds = %56, %53
store double 0.000000e+00, double* %11
br label %63
63: ; preds = %62, %61
%64 = load i32*, i32** %12
%65 = call i32 @fwrite(double* %11, i32 8, i32 1, i32* %64)
br label %66
66: ; preds = %63
%67 = load i32, i32* %7
%68 = add nsw i32 %67, 1
store i32 %68, i32* %7
br label %44
69: ; preds = %44
br label %70
70: ; preds = %69
%71 = load i32, i32* %6
%72 = add nsw i32 %71, 1
store i32 %72, i32* %6
br label %39
73: ; preds = %39
br label %74
74: ; preds = %73
%75 = load i32, i32* %8
%76 = add nsw i32 %75, 1
store i32 %76, i32* %8
br label %34
77: ; preds = %34
%78 = load i32*, i32** %12
%79 = call i32 @fclose(i32* %78)
store i32 0, i32* %3
br label %80
80: ; preds = %77, %15
%81 = load i32, i32* %3
ret i32 %81
}

LLVM IR (-O2):
@.str.2 = [39 x i8] c"%s number_of_inputs number_of_layers\0A\0A\00"
@.str.3 = [23 x i8] c"For example: %s 10 3\0A\0A\00"
@.str.4 = [12 x i8] c"weights.dat\00"
@.str.5 = [3 x i8] c"wb\00"
@str = [61 x i8] c"\0A\0AThis program generates the weights for the neural network.\00"
@str.6 = [65 x i8] c"You must specify the number of inputs and the number of layers.\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca double
%4 = bitcast double* %3 to i8*
%5 = icmp slt i32 %0, 3
br i1 %5, label %6, label %12
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([61 x i8], [61 x i8]* @str, i64 0, i64 0))
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([65 x i8], [65 x i8]* @str.6, i64 0, i64 0))
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0))
%10 = load i8*, i8** %1
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i8* %10)
br label %48
12: ; preds = %2
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = tail call i32 @atoi(i8* %14)
%16 = getelementptr inbounds i8*, i8** %1, i64 2
%17 = load i8*, i8** %16
%18 = tail call i32 @atoi(i8* %17)
%19 = tail call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%20 = tail call i32 @perror(i32* null)
%21 = icmp sgt i32 %18, 0
br i1 %21, label %22, label %46
22: ; preds = %12
%23 = icmp sgt i32 %15, 0
%24 = add nsw i32 %15, -1
br label %25
25: ; preds = %22, %43
%26 = phi i32 [ 0, %22 ], [ %44, %43 ]
br i1 %23, label %27, label %43
27: ; preds = %25, %40
%28 = phi i32 [ %41, %40 ], [ 0, %25 ]
%29 = icmp eq i32 %28, 0
br label %30
30: ; preds = %27, %30
%31 = phi i32 [ 0, %27 ], [ %32, %30 ]
%32 = add nuw nsw i32 %31, 1
%33 = icmp eq i32 %28, %32
%34 = icmp eq i32 %31, %24
%35 = select i1 %29, i1 %34, i1 false
%36 = select i1 %33, i1 true, i1 %35
%37 = select i1 %36, double 1.000000e+00, double 0.000000e+00
store double %37, double* %3
%38 = call i32 @fwrite(double* %3, i32 8, i32 1, i32* %19)
%39 = icmp eq i32 %32, %15
br i1 %39, label %40, label %30
40: ; preds = %30
%41 = add nuw nsw i32 %28, 1
%42 = icmp eq i32 %41, %15
br i1 %42, label %43, label %27
43: ; preds = %40, %25
%44 = add nuw nsw i32 %26, 1
%45 = icmp eq i32 %44, %18
br i1 %45, label %46, label %25
46: ; preds = %43, %12
%47 = tail call i32 @fclose(i32* %19)
br label %48
48: ; preds = %46, %6
ret i32 0
}