#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 */

/* Variables and functions */
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ dup2(int, int);
int /*<<< orphan*/ execl(char *, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fork();
int /*<<< orphan*/ perror(char *);
scalar_t__ pipe(int *);
int /*<<< orphan*/ puts(char *);
int main() {
  int pipes[2];
  if (pipe(pipes) < 0) {
    perror("pipe()");
  }
  if (fork() == 0) {
    close(pipes[1]);
    dup2(pipes[0], 0);
    execl("/usr/bin/gnuplot", "gnuplot", NULL);
    exit(0);
  } else {
    close(pipes[0]);
    dup2(pipes[1], 1);
    puts("set terminal dumb;");
    puts("plot log(x);");
    puts("plot cos(x);");
    puts("exit;");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0xc(%rbp),%rdi
call   1060 <pipe@plt>
cmp    $0x0,%rax
jge    11ae <main+0x2e>
lea    0xe57(%rip),%rdi
call   1070 <perror@plt>
mov    $0x0,%al
call   10a0 <fork@plt>
cmp    $0x0,%rax
jne    11ef <main+0x6f>
mov    -0x8(%rbp),%edi
call   1050 <close@plt>
mov    -0xc(%rbp),%edi
xor    %esi,%esi
call   1040 <dup2@plt>
lea    0xe2f(%rip),%rdi
lea    0xe31(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1090 <execl@plt>
xor    %edi,%edi
call   1080 <exit@plt>
mov    -0xc(%rbp),%edi
call   1050 <close@plt>
mov    -0x8(%rbp),%edi
mov    $0x1,%esi
call   1040 <dup2@plt>
lea    0xe0d(%rip),%rdi
call   1030 <puts@plt>
lea    0xe14(%rip),%rdi
call   1030 <puts@plt>
lea    0xe15(%rip),%rdi
call   1030 <puts@plt>
lea    0xe16(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
mov    %rsp,%rdi
call   1060 <pipe@plt>
test   %rax,%rax
js     11e4 <main+0x64>
xor    %eax,%eax
call   10a0 <fork@plt>
test   %rax,%rax
je     11f2 <main+0x72>
mov    (%rsp),%edi
call   1050 <close@plt>
mov    0x4(%rsp),%edi
mov    $0x1,%esi
call   1040 <dup2@plt>
lea    0xe61(%rip),%rdi
call   1030 <puts@plt>
lea    0xe68(%rip),%rdi
call   1030 <puts@plt>
lea    0xe69(%rip),%rdi
call   1030 <puts@plt>
lea    0xe6a(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rcx
ret
lea    0xe15(%rip),%rdi
call   1070 <perror@plt>
jmp    118e <main+0xe>
mov    0x4(%rsp),%edi
call   1050 <close@plt>
mov    (%rsp),%edi
xor    %esi,%esi
call   1040 <dup2@plt>
lea    0xdfb(%rip),%rdi
lea    0xdfd(%rip),%rsi
xor    %edx,%edx
call   1090 <execl@plt>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"pipe()\00"
@.str.1 = [17 x i8] c"/usr/bin/gnuplot\00"
@.str.2 = [8 x i8] c"gnuplot\00"
@.str.3 = [19 x i8] c"set terminal dumb;\00"
@.str.4 = [13 x i8] c"plot log(x);\00"
@.str.5 = [13 x i8] c"plot cos(x);\00"
@.str.6 = [6 x i8] c"exit;\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [2 x i32]
store i32 0, i32* %1
%3 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%4 = call i64 @pipe(i32* %3)
%5 = icmp slt i64 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %6, %0
%9 = call i64 (...) @fork()
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %20
11: ; preds = %8
%12 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%13 = load i32, i32* %12
%14 = call i32 @close(i32 %13)
%15 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%16 = load i32, i32* %15
%17 = call i32 @dup2(i32 %16, i32 0)
%18 = call i32 @execl(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32* null)
%19 = call i32 @exit(i32 0)
unreachable
20: ; preds = %8
%21 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%22 = load i32, i32* %21
%23 = call i32 @close(i32 %22)
%24 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%25 = load i32, i32* %24
%26 = call i32 @dup2(i32 %25, i32 1)
%27 = call i32 @puts(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
%28 = call i32 @puts(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
%29 = call i32 @puts(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
%30 = call i32 @puts(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
br label %31
31: ; preds = %20
ret i32 0
}

LLVM IR (-O2):
@.str = [7 x i8] c"pipe()\00"
@.str.1 = [17 x i8] c"/usr/bin/gnuplot\00"
@.str.2 = [8 x i8] c"gnuplot\00"
@.str.3 = [19 x i8] c"set terminal dumb;\00"
@.str.4 = [13 x i8] c"plot log(x);\00"
@.str.5 = [13 x i8] c"plot cos(x);\00"
@.str.6 = [6 x i8] c"exit;\00"
define i32 @main() {
%1 = alloca [2 x i32]
%2 = bitcast [2 x i32]* %1 to i8*
%3 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%4 = call i64 @pipe(i32* %3)
%5 = icmp slt i64 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %6, %0
%9 = call i64 (...) @fork()
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %19
11: ; preds = %8
%12 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%13 = load i32, i32* %12
%14 = call i32 @close(i32 %13)
%15 = load i32, i32* %3
%16 = call i32 @dup2(i32 %15, i32 0)
%17 = call i32 @execl(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32* null)
%18 = call i32 @exit(i32 0)
unreachable
19: ; preds = %8
%20 = load i32, i32* %3
%21 = call i32 @close(i32 %20)
%22 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%23 = load i32, i32* %22
%24 = call i32 @dup2(i32 %23, i32 1)
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
%26 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
%27 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
%28 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
ret i32 0
}