#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*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/ *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int system(char *);
int plotActual(double **data, int rows, int cols, char *dataFilename,
               char *scriptFilename, FILE *dataFile, FILE *scriptFile) {
  int i, j;
  char command[250];
  for (i = 0; i < rows; i++) {
    for (j = 0; j < cols; j++) {
      fprintf(dataFile, "%f ", data[i][j]);
    }
    fputc('\n', dataFile);
  }
  fprintf(scriptFile,
          "set pm3d\n"
          "splot \"%s\" matrix with pm3d notitle\n"
          "pause -1 \"Press Enter\"\n",
          dataFilename);
  fflush(dataFile);
  fflush(scriptFile);
  sprintf(command, "gnuplot %s </dev/tty", scriptFilename);
  return system(command);
}


x86 assembly (clang, -O0):
<plotActual>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    0x10(%rbp),%rax
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    %r9,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11ec <plotActual+0x9c>
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11d0 <plotActual+0x80>
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x30(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xe45(%rip),%rsi
mov    $0x1,%al
call   1050 <fprintf@plt>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    118f <plotActual+0x3f>
mov    -0x28(%rbp),%rsi
mov    $0xa,%edi
call   1040 <fputc@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    117c <plotActual+0x2c>
mov    0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe09(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1060 <fflush@plt>
mov    0x10(%rbp),%rdi
call   1060 <fflush@plt>
lea    -0x130(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xe23(%rip),%rsi
call   1070 <sprintf@plt>
lea    -0x130(%rbp),%rdi
call   1030 <system@plt>
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<plotActual>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x128,%rsp
mov    %r9,%rbx
mov    %r8,0x10(%rsp)
mov    %rcx,0x8(%rsp)
mov    %edx,0x4(%rsp)
test   %esi,%esi
jle    11f3 <plotActual+0xa3>
mov    %rdi,%rbp
mov    %esi,%eax
mov    %rax,0x18(%rsp)
mov    0x4(%rsp),%r12d
xor    %r13d,%r13d
lea    0xe71(%rip),%r15
jmp    11b8 <plotActual+0x68>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    $0xa,%edi
mov    %rbx,%rsi
call   1040 <fputc@plt>
add    $0x1,%r13
cmp    0x18(%rsp),%r13
je     11f3 <plotActual+0xa3>
cmpl   $0x0,0x4(%rsp)
jle    11a0 <plotActual+0x50>
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x0(%rbp,%r13,8),%rax
movsd  (%rax,%r14,8),%xmm0
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x1,%al
call   1050 <fprintf@plt>
add    $0x1,%r14
cmp    %r14,%r12
jne    11d0 <plotActual+0x80>
jmp    11a0 <plotActual+0x50>
lea    0xe0a(%rip),%rsi
mov    0x160(%rsp),%rbp
mov    %rbp,%rdi
mov    0x8(%rsp),%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %rbx,%rdi
call   1060 <fflush@plt>
mov    %rbp,%rdi
call   1060 <fflush@plt>
lea    0xe21(%rip),%rsi
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
mov    0x10(%rsp),%rdx
call   1070 <sprintf@plt>
mov    %rbx,%rdi
call   1030 <system@plt>
add    $0x128,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%f \00"
@.str.1 = [69 x i8] c"set pm3d\0Asplot \22%s\22 matrix with pm3d notitle\0Apause -1 \22Press Enter\22\0A\00"
@.str.2 = [21 x i8] c"gnuplot %s </dev/tty\00"
define i32 @plotActual(double** %0, i32 %1, i32 %2, i8* %3, i8* %4, i32* %5, i32* %6) {
%8 = alloca double**
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i32*
%14 = alloca i32*
%15 = alloca i32
%16 = alloca i32
%17 = alloca [250 x i8]
store double** %0, double*** %8
store i32 %1, i32* %9
store i32 %2, i32* %10
store i8* %3, i8** %11
store i8* %4, i8** %12
store i32* %5, i32** %13
store i32* %6, i32** %14
store i32 0, i32* %15
br label %18
18: ; preds = %45, %7
%19 = load i32, i32* %15
%20 = load i32, i32* %9
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %48
22: ; preds = %18
store i32 0, i32* %16
br label %23
23: ; preds = %39, %22
%24 = load i32, i32* %16
%25 = load i32, i32* %10
%26 = icmp slt i32 %24, %25
br i1 %26, label %27, label %42
27: ; preds = %23
%28 = load i32*, i32** %13
%29 = load double**, double*** %8
%30 = load i32, i32* %15
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds double*, double** %29, i64 %31
%33 = load double*, double** %32
%34 = load i32, i32* %16
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds double, double* %33, i64 %35
%37 = load double, double* %36
%38 = call i32 (i32*, i8*, ...) @fprintf(i32* %28, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), double %37)
br label %39
39: ; preds = %27
%40 = load i32, i32* %16
%41 = add nsw i32 %40, 1
store i32 %41, i32* %16
br label %23
42: ; preds = %23
%43 = load i32*, i32** %13
%44 = call i32 @fputc(i8 signext 10, i32* %43)
br label %45
45: ; preds = %42
%46 = load i32, i32* %15
%47 = add nsw i32 %46, 1
store i32 %47, i32* %15
br label %18
48: ; preds = %18
%49 = load i32*, i32** %14
%50 = load i8*, i8** %11
%51 = call i32 (i32*, i8*, ...) @fprintf(i32* %49, i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str.1, i64 0, i64 0), i8* %50)
%52 = load i32*, i32** %13
%53 = call i32 @fflush(i32* %52)
%54 = load i32*, i32** %14
%55 = call i32 @fflush(i32* %54)
%56 = getelementptr inbounds [250 x i8], [250 x i8]* %17, i64 0, i64 0
%57 = load i8*, i8** %12
%58 = call i32 @sprintf(i8* %56, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %57)
%59 = getelementptr inbounds [250 x i8], [250 x i8]* %17, i64 0, i64 0
%60 = call i32 @system(i8* %59)
ret i32 %60
}

LLVM IR (-O2):
@.str = [4 x i8] c"%f \00"
@.str.1 = [69 x i8] c"set pm3d\0Asplot \22%s\22 matrix with pm3d notitle\0Apause -1 \22Press Enter\22\0A\00"
@.str.2 = [21 x i8] c"gnuplot %s </dev/tty\00"
define i32 @plotActual(double** nocapture %0, i32 %1, i32 %2, i8* %3, i8* %4, i32* nocapture %5, i32* nocapture %6) {
%8 = alloca [250 x i8]
%9 = getelementptr inbounds [250 x i8], [250 x i8]* %8, i64 0, i64 0
%10 = icmp sgt i32 %1, 0
br i1 %10, label %11, label %31
11: ; preds = %7
%12 = icmp sgt i32 %2, 0
%13 = zext i32 %1 to i64
%14 = zext i32 %2 to i64
br label %15
15: ; preds = %11, %27
%16 = phi i64 [ 0, %11 ], [ %29, %27 ]
br i1 %12, label %17, label %27
17: ; preds = %15
%18 = getelementptr inbounds double*, double** %0, i64 %16
br label %19
19: ; preds = %17, %19
%20 = phi i64 [ 0, %17 ], [ %25, %19 ]
%21 = load double*, double** %18
%22 = getelementptr inbounds double, double* %21, i64 %20
%23 = load double, double* %22
%24 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), double %23)
%25 = add nuw nsw i64 %20, 1
%26 = icmp eq i64 %25, %14
br i1 %26, label %27, label %19
27: ; preds = %19, %15
%28 = tail call i32 @fputc(i8 signext 10, i32* %5)
%29 = add nuw nsw i64 %16, 1
%30 = icmp eq i64 %29, %13
br i1 %30, label %31, label %15
31: ; preds = %27, %7
%32 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %6, i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%33 = tail call i32 @fflush(i32* %5)
%34 = tail call i32 @fflush(i32* %6)
%35 = call i32 @sprintf(i8* %9, i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %4)
%36 = call i32 @system(i8* %9)
ret i32 %36
}