#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 */
double cos(double);
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int, double);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
double sin(double);
int main() {
  double xarray[30];
  double yarray[30];
  FILE *pipe_gp;
  pipe_gp = popen("gnuplot --persist", "w");
  int i;
  int j;
  fputs("load 'startup_2ch.p'\n", pipe_gp);
  fputs("set yrange [-1:1]\n", pipe_gp);
  for (j = 1; j <= 100; j++) {
    fputs("plot '-' w boxes, '-' w boxes\n", pipe_gp);
    for (i = 0; i < 30; ++i) {
      double x = (i + 4 * j) / 100.0;
      xarray[i] = sin(x);
      yarray[i] = cos(x);
      fprintf(pipe_gp, "%f %f\n", i + 0.25, yarray[i]);
    }
    fputs("e\n", pipe_gp);
    for (i = 0; i < 30; i++) {
      fprintf(pipe_gp, "%f %f\n", i + 0.75, xarray[i]);
    }
    fputs("e\n", pipe_gp);
    fflush(pipe_gp);
    for (i = 0; i < 10000000; i++) {
    }
  }
  pclose(pipe_gp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x210,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe8f(%rip),%rdi
lea    0xe9a(%rip),%rsi
call   1090 <popen@plt>
mov    %rax,-0x1f8(%rbp)
mov    -0x1f8(%rbp),%rsi
lea    0xe82(%rip),%rdi
call   1040 <fputs@plt>
mov    -0x1f8(%rbp),%rsi
lea    0xe85(%rip),%rdi
call   1040 <fputs@plt>
movl   $0x1,-0x200(%rbp)
cmpl   $0x64,-0x200(%rbp)
jg     1399 <main+0x229>
mov    -0x1f8(%rbp),%rsi
lea    0xe6e(%rip),%rdi
call   1040 <fputs@plt>
movl   $0x0,-0x1fc(%rbp)
cmpl   $0x1e,-0x1fc(%rbp)
jge    12b5 <main+0x145>
mov    -0x1fc(%rbp),%eax
mov    -0x200(%rbp),%ecx
shl    $0x2,%ecx
add    %ecx,%eax
cvtsi2sd %eax,%xmm0
movsd  0xdf0(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x208(%rbp)
ff
movsd  -0x208(%rbp),%xmm0
ff
call   1060 <sin@plt>
movslq -0x1fc(%rbp),%rax
movsd  %xmm0,-0x100(%rbp,%rax,8)
ff ff
movsd  -0x208(%rbp),%xmm0
ff
call   1080 <cos@plt>
movslq -0x1fc(%rbp),%rax
movsd  %xmm0,-0x1f0(%rbp,%rax,8)
ff ff
mov    -0x1f8(%rbp),%rdi
cvtsi2sdl -0x1fc(%rbp),%xmm0
ff
movsd  0xd8b(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edx
movslq -0x1fc(%rbp),%rax
movsd  -0x1f0(%rbp,%rax,8),%xmm0
ff ff
lea    0xdd8(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x1fc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1fc(%rbp)
jmp    11f6 <main+0x86>
mov    -0x1f8(%rbp),%rsi
lea    0xdb8(%rip),%rdi
call   1040 <fputs@plt>
movl   $0x0,-0x1fc(%rbp)
cmpl   $0x1e,-0x1fc(%rbp)
jge    132e <main+0x1be>
mov    -0x1f8(%rbp),%rdi
cvtsi2sdl -0x1fc(%rbp),%xmm0
ff
movsd  0xd0a(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edx
movslq -0x1fc(%rbp),%rax
movsd  -0x100(%rbp,%rax,8),%xmm0
ff ff
lea    0xd5f(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x1fc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1fc(%rbp)
jmp    12d2 <main+0x162>
mov    -0x1f8(%rbp),%rsi
lea    0xd3f(%rip),%rdi
call   1040 <fputs@plt>
mov    -0x1f8(%rbp),%rdi
call   1070 <fflush@plt>
movl   $0x0,-0x1fc(%rbp)
cmpl   $0x989680,-0x1fc(%rbp)
jge    1380 <main+0x210>
jmp    136c <main+0x1fc>
mov    -0x1fc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1fc(%rbp)
jmp    1357 <main+0x1e7>
jmp    1385 <main+0x215>
mov    -0x200(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x200(%rbp)
jmp    11cc <main+0x5c>
mov    -0x1f8(%rbp),%rdi
call   1030 <pclose@plt>
xor    %eax,%eax
add    $0x210,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x108,%rsp
lea    0xe90(%rip),%rdi
lea    0xe9b(%rip),%rsi
call   1080 <popen@plt>
mov    %rax,%rbx
lea    0xe8e(%rip),%rdi
mov    $0x1,%r13d
mov    $0x15,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1090 <fwrite@plt>
lea    0xe85(%rip),%rdi
mov    $0x12,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1090 <fwrite@plt>
mov    $0x4,%r12d
lea    0xe98(%rip),%r15
lea    0xe98(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r14,%rbp
mov    $0x1e,%esi
mov    $0x1,%edx
lea    0xe51(%rip),%rdi
mov    %rbx,%rcx
call   1090 <fwrite@plt>
xor    %r14d,%r14d
nop
lea    (%r12,%r14,1),%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
divsd  0xddd(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
call   1050 <sin@plt>
movsd  %xmm0,0x10(%rsp,%r14,8)
movsd  0x8(%rsp),%xmm0
call   1070 <cos@plt>
xorps  %xmm1,%xmm1
cvtsi2sd %r14d,%xmm1
addsd  0xdb8(%rip),%xmm1
cvttsd2si %xmm1,%edx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1040 <fprintf@plt>
add    $0x1,%r14
cmp    $0x1e,%r14
jne    1210 <main+0xa0>
mov    $0x2,%esi
mov    $0x1,%edx
mov    %rbp,%r14
mov    %rbp,%rdi
mov    %rbx,%rcx
call   1090 <fwrite@plt>
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
addsd  0xd71(%rip),%xmm0
cvttsd2si %xmm0,%edx
movsd  0x10(%rsp,%rbp,8),%xmm0
mov    %rbx,%rdi
mov    %r15,%rsi
call   1040 <fprintf@plt>
add    $0x1,%rbp
cmp    $0x1e,%rbp
jne    1290 <main+0x120>
mov    $0x2,%esi
mov    $0x1,%edx
mov    %r14,%rdi
mov    %rbx,%rcx
call   1090 <fwrite@plt>
mov    %rbx,%rdi
call   1060 <fflush@plt>
add    $0x1,%r13
add    $0x4,%r12
cmp    $0x65,%r13
jne    11f0 <main+0x80>
mov    %rbx,%rdi
call   1030 <pclose@plt>
xor    %eax,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [18 x i8] c"gnuplot --persist\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [22 x i8] c"load 'startup_2ch.p'\0A\00"
@.str.3 = [19 x i8] c"set yrange [-1:1]\0A\00"
@.str.4 = [31 x i8] c"plot '-' w boxes, '-' w boxes\0A\00"
@.str.5 = [7 x i8] c"%f %f\0A\00"
@.str.6 = [3 x i8] c"e\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [30 x double]
%3 = alloca [30 x double]
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca double
store i32 0, i32* %1
%8 = call i32* @popen(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %8, i32** %4
%9 = load i32*, i32** %4
%10 = call i32 @fputs(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i32* %9)
%11 = load i32*, i32** %4
%12 = call i32 @fputs(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32* %11)
store i32 1, i32* %6
br label %13
13: ; preds = %85, %0
%14 = load i32, i32* %6
%15 = icmp sle i32 %14, 100
br i1 %15, label %16, label %88
16: ; preds = %13
%17 = load i32*, i32** %4
%18 = call i32 @fputs(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i32* %17)
store i32 0, i32* %5
br label %19
19: ; preds = %49, %16
%20 = load i32, i32* %5
%21 = icmp slt i32 %20, 30
br i1 %21, label %22, label %52
22: ; preds = %19
%23 = load i32, i32* %5
%24 = load i32, i32* %6
%25 = mul nsw i32 4, %24
%26 = add nsw i32 %23, %25
%27 = sitofp i32 %26 to double
%28 = fdiv double %27, 1.000000e+02
store double %28, double* %7
%29 = load double, double* %7
%30 = call double @sin(double %29)
%31 = load i32, i32* %5
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [30 x double], [30 x double]* %2, i64 0, i64 %32
store double %30, double* %33
%34 = load double, double* %7
%35 = call double @cos(double %34)
%36 = load i32, i32* %5
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [30 x double], [30 x double]* %3, i64 0, i64 %37
store double %35, double* %38
%39 = load i32*, i32** %4
%40 = load i32, i32* %5
%41 = sitofp i32 %40 to double
%42 = fadd double %41, 2.500000e-01
%43 = fptosi double %42 to i32
%44 = load i32, i32* %5
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds [30 x double], [30 x double]* %3, i64 0, i64 %45
%47 = load double, double* %46
%48 = call i32 @fprintf(i32* %39, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32 %43, double %47)
br label %49
49: ; preds = %22
%50 = load i32, i32* %5
%51 = add nsw i32 %50, 1
store i32 %51, i32* %5
br label %19
52: ; preds = %19
%53 = load i32*, i32** %4
%54 = call i32 @fputs(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32* %53)
store i32 0, i32* %5
br label %55
55: ; preds = %69, %52
%56 = load i32, i32* %5
%57 = icmp slt i32 %56, 30
br i1 %57, label %58, label %72
58: ; preds = %55
%59 = load i32*, i32** %4
%60 = load i32, i32* %5
%61 = sitofp i32 %60 to double
%62 = fadd double %61, 7.500000e-01
%63 = fptosi double %62 to i32
%64 = load i32, i32* %5
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds [30 x double], [30 x double]* %2, i64 0, i64 %65
%67 = load double, double* %66
%68 = call i32 @fprintf(i32* %59, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32 %63, double %67)
br label %69
69: ; preds = %58
%70 = load i32, i32* %5
%71 = add nsw i32 %70, 1
store i32 %71, i32* %5
br label %55
72: ; preds = %55
%73 = load i32*, i32** %4
%74 = call i32 @fputs(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32* %73)
%75 = load i32*, i32** %4
%76 = call i32 @fflush(i32* %75)
store i32 0, i32* %5
br label %77
77: ; preds = %81, %72
%78 = load i32, i32* %5
%79 = icmp slt i32 %78, 10000000
br i1 %79, label %80, label %84
80: ; preds = %77
br label %81
81: ; preds = %80
%82 = load i32, i32* %5
%83 = add nsw i32 %82, 1
store i32 %83, i32* %5
br label %77
84: ; preds = %77
br label %85
85: ; preds = %84
%86 = load i32, i32* %6
%87 = add nsw i32 %86, 1
store i32 %87, i32* %6
br label %13
88: ; preds = %13
%89 = load i32*, i32** %4
%90 = call i32 @pclose(i32* %89)
ret i32 0
}

LLVM IR (-O2):
@.str = [18 x i8] c"gnuplot --persist\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [22 x i8] c"load 'startup_2ch.p'\0A\00"
@.str.3 = [19 x i8] c"set yrange [-1:1]\0A\00"
@.str.4 = [31 x i8] c"plot '-' w boxes, '-' w boxes\0A\00"
@.str.5 = [7 x i8] c"%f %f\0A\00"
@.str.6 = [3 x i8] c"e\0A\00"
define i32 @main() {
%1 = alloca [30 x double]
%2 = bitcast [30 x double]* %1 to i8*
%3 = tail call i32* @popen(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = tail call i64 @fwrite(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i64 21, i64 1, i32* %3)
%5 = tail call i64 @fwrite(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i64 18, i64 1, i32* %3)
br label %6
6: ; preds = %0, %39
%7 = phi i64 [ 1, %0 ], [ %42, %39 ]
%8 = tail call i64 @fwrite(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i64 30, i64 1, i32* %3)
%9 = shl nsw i64 %7, 2
br label %10
10: ; preds = %6, %10
%11 = phi i64 [ 0, %6 ], [ %24, %10 ]
%12 = add nuw nsw i64 %11, %9
%13 = trunc i64 %12 to i32
%14 = sitofp i32 %13 to double
%15 = fdiv double %14, 1.000000e+02
%16 = tail call double @sin(double %15)
%17 = getelementptr inbounds [30 x double], [30 x double]* %1, i64 0, i64 %11
store double %16, double* %17
%18 = tail call double @cos(double %15)
%19 = trunc i64 %11 to i32
%20 = sitofp i32 %19 to double
%21 = fadd double %20, 2.500000e-01
%22 = fptosi double %21 to i32
%23 = tail call i32 @fprintf(i32* %3, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32 %22, double %18)
%24 = add nuw nsw i64 %11, 1
%25 = icmp eq i64 %24, 30
br i1 %25, label %26, label %10
26: ; preds = %10
%27 = tail call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i64 2, i64 1, i32* %3)
br label %28
28: ; preds = %26, %28
%29 = phi i64 [ 0, %26 ], [ %37, %28 ]
%30 = trunc i64 %29 to i32
%31 = sitofp i32 %30 to double
%32 = fadd double %31, 7.500000e-01
%33 = fptosi double %32 to i32
%34 = getelementptr inbounds [30 x double], [30 x double]* %1, i64 0, i64 %29
%35 = load double, double* %34
%36 = tail call i32 @fprintf(i32* %3, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32 %33, double %35)
%37 = add nuw nsw i64 %29, 1
%38 = icmp eq i64 %37, 30
br i1 %38, label %39, label %28
39: ; preds = %28
%40 = tail call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i64 2, i64 1, i32* %3)
%41 = tail call i32 @fflush(i32* %3)
%42 = add nuw nsw i64 %7, 1
%43 = icmp eq i64 %42, 101
br i1 %43, label %44, label %6
44: ; preds = %39
%45 = tail call i32 @pclose(i32* %3)
ret i32 0
}