#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*/ fprint(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, double, double);
int /*<<< orphan*/ *popen(char *, char *);
void plot(double x[], double y[], int points) {
  char *commandsForGnuplot[] = {"set title \"Specific Heat vs. Temperature\"",
                                "plot 'res' 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 \n", x[q], y[q]);
  }
  for (i = 0; i < 2; i++) {
    fprint(gnuplotPipe, "%s \n", commandsForGnuplot[i]);
  }
}


x86 assembly (clang, -O0):
<plot>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    0x2cb6(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0x2cb3(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    0xec9(%rip),%rdi
lea    0xec6(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x38(%rbp)
lea    0xeb8(%rip),%rdi
lea    0xeaf(%rip),%rsi
call   1050 <popen@plt>
mov    %rax,-0x40(%rbp)
movl   $0x0,-0x48(%rbp)
mov    -0x48(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11e2 <plot+0xa2>
mov    -0x38(%rbp),%rdi
mov    -0x8(%rbp),%rax
movslq -0x48(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x48(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
lea    0xe84(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x48(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x48(%rbp)
jmp    119e <plot+0x5e>
movl   $0x0,-0x44(%rbp)
cmpl   $0x2,-0x44(%rbp)
jge    121a <plot+0xda>
mov    -0x40(%rbp),%rdi
movslq -0x44(%rbp),%rax
mov    -0x30(%rbp,%rax,8),%rdx
lea    0xe56(%rip),%rsi
call   1030 <fprint@plt>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    11e9 <plot+0xa9>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<plot>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %rsi,%r14
mov    %rdi,%r12
lea    0xedf(%rip),%rdi
lea    0xedc(%rip),%r15
mov    %r15,%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
lea    0xecc(%rip),%rdi
mov    %r15,%rsi
call   1050 <popen@plt>
mov    %rax,(%rsp)
test   %ebp,%ebp
jle    11b0 <plot+0x70>
mov    %ebp,%ebp
xor    %r15d,%r15d
lea    0xec4(%rip),%r13
nop
movsd  (%r12,%r15,8),%xmm0
movsd  (%r14,%r15,8),%xmm1
mov    %rbx,%rdi
mov    %r13,%rsi
call   1040 <fprintf@plt>
add    $0x1,%r15
cmp    %r15,%rbp
jne    1190 <plot+0x50>
lea    0xea6(%rip),%rbx
lea    0xe42(%rip),%rdx
mov    (%rsp),%rbp
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1030 <fprint@plt>
lea    0xe56(%rip),%rdx
mov    %rbp,%rdi
mov    %rbx,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fprint@plt>

LLVM IR (-O0):
@.str = [42 x i8] c"set title \22Specific Heat vs. Temperature\22\00"
@.str.1 = [15 x i8] c"plot 'res' w 1\00"
@__const.plot.commandsForGnuplot = [2 x i8*] [i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([15 x i8], [15 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 = [10 x i8] c"%1f %1f \0A\00"
@.str.6 = [5 x i8] c"%s \0A\00"
define void @plot(double* %0, double* %1, i32 %2) {
%4 = alloca double*
%5 = alloca double*
%6 = alloca i32
%7 = alloca [2 x i8*]
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i32
store double* %0, double** %4
store double* %1, double** %5
store i32 %2, i32* %6
%12 = bitcast [2 x i8*]* %7 to i8*
%13 = 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* %13, i32** %8
%14 = 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* %14, i32** %9
store i32 0, i32* %11
br label %15
15: ; preds = %32, %3
%16 = load i32, i32* %11
%17 = load i32, i32* %6
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %35
19: ; preds = %15
%20 = load i32*, i32** %8
%21 = load double*, double** %4
%22 = load i32, i32* %11
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds double, double* %21, i64 %23
%25 = load double, double* %24
%26 = load double*, double** %5
%27 = load i32, i32* %11
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds double, double* %26, i64 %28
%30 = load double, double* %29
%31 = call i32 @fprintf(i32* %20, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), double %25, double %30)
br label %32
32: ; preds = %19
%33 = load i32, i32* %11
%34 = add nsw i32 %33, 1
store i32 %34, i32* %11
br label %15
35: ; preds = %15
store i32 0, i32* %10
br label %36
36: ; preds = %46, %35
%37 = load i32, i32* %10
%38 = icmp slt i32 %37, 2
br i1 %38, label %39, label %49
39: ; preds = %36
%40 = load i32*, i32** %9
%41 = load i32, i32* %10
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds [2 x i8*], [2 x i8*]* %7, i64 0, i64 %42
%44 = load i8*, i8** %43
%45 = call i32 @fprint(i32* %40, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i8* %44)
br label %46
46: ; preds = %39
%47 = load i32, i32* %10
%48 = add nsw i32 %47, 1
store i32 %48, i32* %10
br label %36
49: ; preds = %36
ret void
}

LLVM IR (-O2):
@.str = [42 x i8] c"set title \22Specific Heat vs. Temperature\22\00"
@.str.1 = [15 x i8] c"plot 'res' w 1\00"
@.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 = [10 x i8] c"%1f %1f \0A\00"
@.str.6 = [5 x i8] c"%s \0A\00"
define void @plot(double* nocapture %0, double* nocapture %1, i32 %2) {
%4 = 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))
%5 = 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))
%6 = icmp sgt i32 %2, 0
br i1 %6, label %7, label %9
7: ; preds = %3
%8 = zext i32 %2 to i64
br label %12
9: ; preds = %12, %3
%10 = tail call i32 @fprint(i32* %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
%11 = tail call i32 @fprint(i32* %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
ret void
12: ; preds = %7, %12
%13 = phi i64 [ 0, %7 ], [ %19, %12 ]
%14 = getelementptr inbounds double, double* %0, i64 %13
%15 = load double, double* %14
%16 = getelementptr inbounds double, double* %1, i64 %13
%17 = load double, double* %16
%18 = tail call i32 @fprintf(i32* %4, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), double %15, double %17)
%19 = add nuw nsw i64 %13, 1
%20 = icmp eq i64 %19, %8
br i1 %20, label %9, label %12
}