#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*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ *popen(char *, char *);
void plot(double x[], double y1[], double y2[], double y3[], int points) {
  char *commandsForGnuplot[] = {
      "set title \"Energy vs. Distance using Three Techniques\"",
      "set logscale x 2\n"
      "set logscale y 10\n"
      "set xlabel 'Distance'\n"
      "set ylabel '|Energy|'\n"
      "set grid\n"
      "plot 'res' u 1:2 title 'VEGAS' w 1, 'res' u 1:3 title 'Custom' w 1, "
      "'res; u 1:4 title 'Dipole Approximation.' w 1"};
  FILE *temp = fopen("res", "w");
  FILE *gnuplotPipe = popen("gnuplot -persistent", "w");
  int i;
  for (int q = 0; q < points; q++) {
    fprintf(temp, "%1f  %1f  %1f  %1f  \n", x[q], y1[q], y2[q], y3[q]);
  }
  for (i = 0; 1 < 2; i++) {
    fprintf(gnuplotPipe, "%s \n", commandsForGnuplot[i]);
  }
}


x86 assembly (clang, -O0):
<plot>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    0x2cbd(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0x2cba(%rip),%rax
mov    %rax,-0x38(%rbp)
lea    0xf98(%rip),%rdi
lea    0xf95(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x48(%rbp)
lea    0xf87(%rip),%rdi
lea    0xf7e(%rip),%rsi
call   1040 <popen@plt>
mov    %rax,-0x50(%rbp)
movl   $0x0,-0x58(%rbp)
mov    -0x58(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    11f7 <plot+0xc7>
mov    -0x48(%rbp),%rdi
mov    -0x8(%rbp),%rax
movslq -0x58(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x58(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x18(%rbp),%rax
movslq -0x58(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
mov    -0x20(%rbp),%rax
movslq -0x58(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm3
lea    0xf39(%rip),%rsi
mov    $0x4,%al
call   1030 <fprintf@plt>
mov    -0x58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x58(%rbp)
jmp    1197 <plot+0x67>
movl   $0x0,-0x54(%rbp)
mov    $0x1,%al
test   $0x1,%al
jne    120d <plot+0xdd>
jmp    1236 <plot+0x106>
mov    -0x50(%rbp),%rdi
movslq -0x54(%rbp),%rax
mov    -0x40(%rbp,%rax,8),%rdx
lea    0xf10(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    11fe <plot+0xce>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<plot>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8d,%r14d
mov    %rcx,0x10(%rsp)
mov    %rdx,0x8(%rsp)
mov    %rsi,%r12
mov    %rdi,%r13
lea    0xfa9(%rip),%rdi
lea    0xfa6(%rip),%rbx
mov    %rbx,%rsi
call   1050 <fopen@plt>
mov    %rax,%rbp
lea    0xf96(%rip),%rdi
mov    %rbx,%rsi
call   1040 <popen@plt>
mov    %rax,%rbx
test   %r14d,%r14d
jle    11cd <plot+0x9d>
mov    %r14d,%r14d
xor    %r15d,%r15d
nopw   0x0(%rax,%rax,1)
movsd  0x0(%r13,%r15,8),%xmm0
movsd  (%r12,%r15,8),%xmm1
mov    0x8(%rsp),%rax
movsd  (%rax,%r15,8),%xmm2
mov    0x10(%rsp),%rax
movsd  (%rax,%r15,8),%xmm3
mov    %rbp,%rdi
lea    0xf5e(%rip),%rsi
mov    $0x4,%al
call   1030 <fprintf@plt>
add    $0x1,%r15
cmp    %r15,%r14
jne    1190 <plot+0x60>
lea    0xf64(%rip),%r14
lea    0xf56(%rip),%r15
mov    %r14,%rbp
xchg   %ax,%ax
movslq 0x0(%rbp),%rdx
add    %r14,%rdx
mov    %rbx,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
add    $0x4,%rbp
jmp    11e0 <plot+0xb0>

LLVM IR (-O0):
@.str = [55 x i8] c"set title \22Energy vs. Distance using Three Techniques\22\00"
@.str.1 = [202 x i8] c"set logscale x 2\0Aset logscale y 10\0Aset xlabel 'Distance'\0Aset ylabel '|Energy|'\0Aset grid\0Aplot 'res' u 1:2 title 'VEGAS' w 1, 'res' u 1:3 title 'Custom' w 1, 'res; u 1:4 title 'Dipole Approximation.' w 1\00"
@__const.plot.commandsForGnuplot = [2 x i8*] [i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([202 x i8], [202 x i8]* @.str.1, i32 0, i32 0)]
@.str.2 = [4 x i8] c"res\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [20 x i8] c"gnuplot -persistent\00"
@.str.5 = [22 x i8] c"%1f %1f %1f %1f \0A\00"
@.str.6 = [5 x i8] c"%s \0A\00"
define void @plot(double* %0, double* %1, double* %2, double* %3, i32 %4) {
%6 = alloca double*
%7 = alloca double*
%8 = alloca double*
%9 = alloca double*
%10 = alloca i32
%11 = alloca [2 x i8*]
%12 = alloca i32*
%13 = alloca i32*
%14 = alloca i32
%15 = alloca i32
store double* %0, double** %6
store double* %1, double** %7
store double* %2, double** %8
store double* %3, double** %9
store i32 %4, i32* %10
%16 = bitcast [2 x i8*]* %11 to i8*
%17 = call i32* @fopen(i8* getelementptr inbounds ([4 x i8], [4 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* %17, i32** %12
%18 = call i32* @popen(i8* getelementptr inbounds ([20 x i8], [20 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* %18, i32** %13
store i32 0, i32* %15
br label %19
19: ; preds = %46, %5
%20 = load i32, i32* %15
%21 = load i32, i32* %10
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %49
23: ; preds = %19
%24 = load i32*, i32** %12
%25 = load double*, double** %6
%26 = load i32, i32* %15
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds double, double* %25, i64 %27
%29 = load double, double* %28
%30 = load double*, double** %7
%31 = load i32, i32* %15
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds double, double* %30, i64 %32
%34 = load double, double* %33
%35 = load double*, double** %8
%36 = load i32, i32* %15
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds double, double* %35, i64 %37
%39 = load double, double* %38
%40 = load double*, double** %9
%41 = load i32, i32* %15
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds double, double* %40, i64 %42
%44 = load double, double* %43
%45 = call i32 (i32*, i8*, ...) @fprintf(i32* %24, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), double %29, double %34, double %39, double %44)
br label %46
46: ; preds = %23
%47 = load i32, i32* %15
%48 = add nsw i32 %47, 1
store i32 %48, i32* %15
br label %19
49: ; preds = %19
store i32 0, i32* %14
br label %50
50: ; preds = %58, %49
br i1 true, label %51, label %61
51: ; preds = %50
%52 = load i32*, i32** %13
%53 = load i32, i32* %14
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds [2 x i8*], [2 x i8*]* %11, i64 0, i64 %54
%56 = load i8*, i8** %55
%57 = call i32 (i32*, i8*, ...) @fprintf(i32* %52, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i8* %56)
br label %58
58: ; preds = %51
%59 = load i32, i32* %14
%60 = add nsw i32 %59, 1
store i32 %60, i32* %14
br label %50
61: ; preds = %50
ret void
}

LLVM IR (-O2):
@.str = [55 x i8] c"set title \22Energy vs. Distance using Three Techniques\22\00"
@.str.1 = [202 x i8] c"set logscale x 2\0Aset logscale y 10\0Aset xlabel 'Distance'\0Aset ylabel '|Energy|'\0Aset grid\0Aplot 'res' u 1:2 title 'VEGAS' w 1, 'res' u 1:3 title 'Custom' w 1, 'res; u 1:4 title 'Dipole Approximation.' w 1\00"
@reltable.plot = [2 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([55 x i8]* @.str to i64), i64 ptrtoint ([2 x i32]* @reltable.plot to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([202 x i8]* @.str.1 to i64), i64 ptrtoint ([2 x i32]* @reltable.plot to i64)) to i32)]
@.str.2 = [4 x i8] c"res\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [20 x i8] c"gnuplot -persistent\00"
@.str.5 = [22 x i8] c"%1f %1f %1f %1f \0A\00"
@.str.6 = [5 x i8] c"%s \0A\00"
define void @plot(double* nocapture %0, double* nocapture %1, double* nocapture %2, double* nocapture %3, i32 %4) {
%6 = tail call i32* @fopen(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%7 = tail call i32* @popen(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%8 = icmp sgt i32 %4, 0
br i1 %8, label %9, label %24
9: ; preds = %5
%10 = zext i32 %4 to i64
br label %11
11: ; preds = %9, %11
%12 = phi i64 [ 0, %9 ], [ %22, %11 ]
%13 = getelementptr inbounds double, double* %0, i64 %12
%14 = load double, double* %13
%15 = getelementptr inbounds double, double* %1, i64 %12
%16 = load double, double* %15
%17 = getelementptr inbounds double, double* %2, i64 %12
%18 = load double, double* %17
%19 = getelementptr inbounds double, double* %3, i64 %12
%20 = load double, double* %19
%21 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %6, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), double %14, double %16, double %18, double %20)
%22 = add nuw nsw i64 %12, 1
%23 = icmp eq i64 %22, %10
br i1 %23, label %24, label %11
24: ; preds = %11, %5
br label %25
25: ; preds = %24, %25
%26 = phi i64 [ %30, %25 ], [ 0, %24 ]
%27 = shl i64 %26, 2
%28 = call i8* @llvm.load.relative.i64(i8* bitcast ([2 x i32]* @reltable.plot to i8*), i64 %27)
%29 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %7, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i8* %28)
%30 = add nuw i64 %26, 1
br label %25
}