#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*/ fprintf(int /*<<< orphan*/ *, char *, char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sprintf(char *, char *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int main(int argc, char *argv[]) {
  if (argc != 4) {
    printf(
        "Error!\nUsage: ./stim_generator.x network_X network_Y duration_ms.\n");
    return 0;
  }
  int dim_1 = atoi(argv[1]);
  int dim_2 = atoi(argv[2]);
  int experiment_msecs = atoi(argv[3]);
  int total_steps = experiment_msecs * 20;
  char currFileName[100];
  sprintf(currFileName, "currentInput.txt");
  FILE *fd = fopen(currFileName, "w+");
  int i, j, t = 0;
  int line_message_size = 6 * dim_1 * dim_2 + 2;
  char *line_message_buffer = (char *)malloc(line_message_size * sizeof(char));
  while (t < total_steps) {
    strcpy(line_message_buffer, "");
    for (i = 0; i < dim_1; i++)
      for (j = 0; j < dim_2; j++)
        if ((t > 20000) && (t < 20500))
          strcat(line_message_buffer, "6.000 ");
        else
          strcat(line_message_buffer, "0.000 ");
    strcat(line_message_buffer, "\n");
    fprintf(fd, "%s", line_message_buffer);
    t++;
  }
  fclose(fd);
  return 1;
}


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     11cb <main+0x3b>
lea    0xe46(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1388 <main+0x1f8>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x1c(%rbp)
imul   $0x14,-0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
lea    -0x90(%rbp),%rdi
lea    0xe33(%rip),%rsi
call   10b0 <sprintf@plt>
lea    -0x90(%rbp),%rdi
lea    0xe31(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x98(%rbp)
movl   $0x0,-0xa4(%rbp)
imul   $0x6,-0x14(%rbp),%eax
imul   -0x18(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0xa8(%rbp)
movslq -0xa8(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0xb0(%rbp)
mov    -0xa4(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    1375 <main+0x1e5>
mov    -0xb0(%rbp),%rdi
lea    0xdc2(%rip),%rsi
call   1030 <strcpy@plt>
movl   $0x0,-0x9c(%rbp)
mov    -0x9c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1334 <main+0x1a4>
movl   $0x0,-0xa0(%rbp)
mov    -0xa0(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    131b <main+0x18b>
cmpl   $0x4e20,-0xa4(%rbp)
jle    12ef <main+0x15f>
cmpl   $0x5014,-0xa4(%rbp)
jge    12ef <main+0x15f>
mov    -0xb0(%rbp),%rdi
lea    0xd72(%rip),%rsi
call   10a0 <strcat@plt>
jmp    1302 <main+0x172>
mov    -0xb0(%rbp),%rdi
lea    0xd61(%rip),%rsi
call   10a0 <strcat@plt>
jmp    1307 <main+0x177>
mov    -0xa0(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xa0(%rbp)
jmp    12a8 <main+0x118>
jmp    1320 <main+0x190>
mov    -0x9c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x9c(%rbp)
jmp    128f <main+0xff>
mov    -0xb0(%rbp),%rdi
lea    0xcff(%rip),%rsi
call   10a0 <strcat@plt>
mov    -0x98(%rbp),%rdi
mov    -0xb0(%rbp),%rdx
lea    0xd09(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0xa4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xa4(%rbp)
jmp    1263 <main+0xd3>
mov    -0x98(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%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    $0x88,%rsp
cmp    $0x4,%edi
jne    12d2 <main+0x152>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
call   1090 <atoi@plt>
mov    %eax,%r15d
mov    0x10(%rbx),%rdi
call   1090 <atoi@plt>
mov    %eax,%r14d
mov    0x18(%rbx),%rdi
call   1090 <atoi@plt>
mov    %eax,%r12d
movups 0xe38(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movb   $0x0,0x30(%rsp)
lea    0xe38(%rip),%rsi
lea    0x20(%rsp),%rdi
call   1080 <fopen@plt>
mov    %rax,0x18(%rsp)
mov    %r15d,%eax
imul   %r14d,%eax
lea    (%rax,%rax,2),%eax
lea    (%rax,%rax,1),%edi
add    $0x2,%edi
call   1070 <malloc@plt>
test   %r12d,%r12d
jle    12e2 <main+0x162>
mov    %rax,%rbx
shl    $0x2,%r12d
lea    (%r12,%r12,4),%eax
cmp    $0x2,%eax
mov    $0x1,%ecx
cmovge %eax,%ecx
mov    %ecx,0x14(%rsp)
xor    %eax,%eax
mov    %rax,0x8(%rsp)
jmp    1263 <main+0xe3>
nopl   0x0(%rax)
mov    %rbx,%rdi
lea    0xde8(%rip),%rsi
call   10a0 <strcat@plt>
mov    %rbx,%rdi
mov    0x18(%rsp),%rsi
call   1060 <fputs@plt>
mov    0x8(%rsp),%rax
add    $0x1,%eax
mov    %rax,0x8(%rsp)
cmp    0x14(%rsp),%eax
je     12e2 <main+0x162>
mov    %rbx,%rdi
lea    0xdb6(%rip),%rsi
call   1030 <strcpy@plt>
test   %r15d,%r15d
jle    1230 <main+0xb0>
mov    0x8(%rsp),%rax
add    $0xffffb1df,%eax
cmp    $0x1f3,%eax
lea    0xd8e(%rip),%r12
lea    0xd80(%rip),%rax
cmovb  %rax,%r12
xor    %r13d,%r13d
jmp    12a9 <main+0x129>
nopl   (%rax)
add    $0x1,%r13d
cmp    %r15d,%r13d
je     1230 <main+0xb0>
test   %r14d,%r14d
jle    12a0 <main+0x120>
mov    %r14d,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r12,%rsi
call   10a0 <strcat@plt>
add    $0xffffffff,%ebp
jne    12c0 <main+0x140>
jmp    12a0 <main+0x120>
lea    0xd4b(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
jmp    12f1 <main+0x171>
mov    0x18(%rsp),%rdi
call   1050 <fclose@plt>
mov    $0x1,%eax
add    $0x88,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [67 x i8] c"Error!\0AUsage: ./stim_generator.x network_X network_Y duration_ms.\0A\00"
@.str.1 = [17 x i8] c"currentInput.txt\00"
@.str.2 = [3 x i8] c"w+\00"
@.str.3 = [1 x i8] zeroinitializer
@.str.4 = [7 x i8] c"6.000 \00"
@.str.5 = [7 x i8] c"0.000 \00"
@.str.6 = [2 x i8] c"\0A\00"
@.str.7 = [3 x i8] c"%s\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 [100 x i8]
%11 = alloca i32*
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%17 = load i32, i32* %4
%18 = icmp ne i32 %17, 4
br i1 %18, label %19, label %21
19: ; preds = %2
%20 = call i32 @printf(i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %98
21: ; preds = %2
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i32 @atoi(i8* %24)
store i32 %25, i32* %6
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 2
%28 = load i8*, i8** %27
%29 = call i32 @atoi(i8* %28)
store i32 %29, i32* %7
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 3
%32 = load i8*, i8** %31
%33 = call i32 @atoi(i8* %32)
store i32 %33, i32* %8
%34 = load i32, i32* %8
%35 = mul nsw i32 %34, 20
store i32 %35, i32* %9
%36 = getelementptr inbounds [100 x i8], [100 x i8]* %10, i64 0, i64 0
%37 = call i32 @sprintf(i8* %36, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%38 = getelementptr inbounds [100 x i8], [100 x i8]* %10, i64 0, i64 0
%39 = call i32* @fopen(i8* %38, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %39, i32** %11
store i32 0, i32* %14
%40 = load i32, i32* %6
%41 = mul nsw i32 6, %40
%42 = load i32, i32* %7
%43 = mul nsw i32 %41, %42
%44 = add nsw i32 %43, 2
store i32 %44, i32* %15
%45 = load i32, i32* %15
%46 = sext i32 %45 to i64
%47 = mul i64 %46, 1
%48 = trunc i64 %47 to i32
%49 = call i64 @malloc(i32 %48)
%50 = inttoptr i64 %49 to i8*
store i8* %50, i8** %16
br label %51
51: ; preds = %87, %21
%52 = load i32, i32* %14
%53 = load i32, i32* %9
%54 = icmp slt i32 %52, %53
br i1 %54, label %55, label %95
55: ; preds = %51
%56 = load i8*, i8** %16
%57 = call i32 @strcpy(i8* %56, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %12
br label %58
58: ; preds = %84, %55
%59 = load i32, i32* %12
%60 = load i32, i32* %6
%61 = icmp slt i32 %59, %60
br i1 %61, label %62, label %87
62: ; preds = %58
store i32 0, i32* %13
br label %63
63: ; preds = %80, %62
%64 = load i32, i32* %13
%65 = load i32, i32* %7
%66 = icmp slt i32 %64, %65
br i1 %66, label %67, label %83
67: ; preds = %63
%68 = load i32, i32* %14
%69 = icmp sgt i32 %68, 20000
br i1 %69, label %70, label %76
70: ; preds = %67
%71 = load i32, i32* %14
%72 = icmp slt i32 %71, 20500
br i1 %72, label %73, label %76
73: ; preds = %70
%74 = load i8*, i8** %16
%75 = call i32 @strcat(i8* %74, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
br label %79
76: ; preds = %70, %67
%77 = load i8*, i8** %16
%78 = call i32 @strcat(i8* %77, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
br label %79
79: ; preds = %76, %73
br label %80
80: ; preds = %79
%81 = load i32, i32* %13
%82 = add nsw i32 %81, 1
store i32 %82, i32* %13
br label %63
83: ; preds = %63
br label %84
84: ; preds = %83
%85 = load i32, i32* %12
%86 = add nsw i32 %85, 1
store i32 %86, i32* %12
br label %58
87: ; preds = %58
%88 = load i8*, i8** %16
%89 = call i32 @strcat(i8* %88, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%90 = load i32*, i32** %11
%91 = load i8*, i8** %16
%92 = call i32 @fprintf(i32* %90, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i8* %91)
%93 = load i32, i32* %14
%94 = add nsw i32 %93, 1
store i32 %94, i32* %14
br label %51
95: ; preds = %51
%96 = load i32*, i32** %11
%97 = call i32 @fclose(i32* %96)
store i32 1, i32* %3
br label %98
98: ; preds = %95, %19
%99 = load i32, i32* %3
ret i32 %99
}

LLVM IR (-O2):
@.str.1 = [17 x i8] c"currentInput.txt\00"
@.str.2 = [3 x i8] c"w+\00"
@.str.3 = [1 x i8] zeroinitializer
@.str.4 = [7 x i8] c"6.000 \00"
@.str.5 = [7 x i8] c"0.000 \00"
@.str.6 = [2 x i8] c"\0A\00"
@str = [66 x i8] c"Error!\0AUsage: ./stim_generator.x network_X network_Y duration_ms.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [100 x i8]
%4 = icmp eq i32 %0, 4
br i1 %4, label %7, label %5
5: ; preds = %2
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([66 x i8], [66 x i8]* @str, i64 0, i64 0))
br label %54
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32 @atoi(i8* %9)
%11 = getelementptr inbounds i8*, i8** %1, i64 2
%12 = load i8*, i8** %11
%13 = tail call i32 @atoi(i8* %12)
%14 = getelementptr inbounds i8*, i8** %1, i64 3
%15 = load i8*, i8** %14
%16 = tail call i32 @atoi(i8* %15)
%17 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%19 = mul nsw i32 %10, 6
%20 = mul nsw i32 %19, %13
%21 = add nsw i32 %20, 2
%22 = tail call i64 @malloc(i32 %21)
%23 = inttoptr i64 %22 to i8*
%24 = icmp sgt i32 %16, 0
br i1 %24, label %25, label %52
25: ; preds = %7
%26 = mul i32 %16, 20
%27 = icmp sgt i32 %10, 0
%28 = icmp sgt i32 %13, 0
%29 = call i32 @llvm.smax.i32(i32 %26, i32 1)
br label %30
30: ; preds = %25, %47
%31 = phi i32 [ 0, %25 ], [ %50, %47 ]
%32 = tail call i32 @strcpy(i8* %23, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0))
br i1 %27, label %33, label %47
33: ; preds = %30
%34 = add nsw i32 %31, -20001
%35 = icmp ult i32 %34, 499
%36 = select i1 %35, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0)
br label %37
37: ; preds = %33, %44
%38 = phi i32 [ 0, %33 ], [ %45, %44 ]
br i1 %28, label %39, label %44
39: ; preds = %37, %39
%40 = phi i32 [ %42, %39 ], [ 0, %37 ]
%41 = tail call i32 @strcat(i8* %23, i8* %36)
%42 = add nuw nsw i32 %40, 1
%43 = icmp eq i32 %42, %13
br i1 %43, label %44, label %39
44: ; preds = %39, %37
%45 = add nuw nsw i32 %38, 1
%46 = icmp eq i32 %45, %10
br i1 %46, label %47, label %37
47: ; preds = %44, %30
%48 = tail call i32 @strcat(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%49 = tail call i32 @fputs(i8* %23, i32* %18)
%50 = add nuw nsw i32 %31, 1
%51 = icmp eq i32 %50, %29
br i1 %51, label %52, label %30
52: ; preds = %47, %7
%53 = tail call i32 @fclose(i32* %18)
br label %54
54: ; preds = %52, %5
%55 = phi i32 [ 0, %5 ], [ 1, %52 ]
ret i32 %55
}