#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 atoi(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ getc(int /*<<< orphan*/);
int /*<<< orphan*/ perror(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ stdin;
void draw_plot(char **argv) {
  FILE *gnuplotPipe = popen("gnuplot", "w");
  if (gnuplotPipe == NULL) {
    perror(NULL);
  }
  char xrange[32];
  sprintf(xrange, "set xrange [0:%d]\n", (atoi(argv[2]) - 1));
  char yrange[32];
  sprintf(yrange, "set yrange [0:%d]\n", (atoi(argv[2]) - 1));
  printf("%s\n", xrange);
  printf("%s\n", yrange);
  fprintf(gnuplotPipe, "set view map\n");
  fprintf(gnuplotPipe, xrange);
  fprintf(gnuplotPipe, yrange);
  fprintf(gnuplotPipe, "plot 'data' with image\n");
  fflush(gnuplotPipe);
  getc(stdin);
  fclose(gnuplotPipe);
}


x86 assembly (clang, -O0):
<draw_plot>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xe5d(%rip),%rdi
lea    0xe5e(%rip),%rsi
call   1070 <popen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11c7 <draw_plot+0x37>
xor    %eax,%eax
mov    %eax,%edi
call   1080 <perror@plt>
lea    -0x30(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x8(%rbp),%rax
mov    0x10(%rax),%rdi
call   1090 <atoi@plt>
mov    -0x60(%rbp),%rdi
mov    %eax,%edx
sub    $0x1,%edx
lea    0xe1e(%rip),%rsi
call   10a0 <sprintf@plt>
lea    -0x50(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x8(%rbp),%rax
mov    0x10(%rax),%rdi
call   1090 <atoi@plt>
mov    -0x58(%rbp),%rdi
mov    %eax,%edx
sub    $0x1,%edx
lea    0xe07(%rip),%rsi
call   10a0 <sprintf@plt>
lea    -0x30(%rbp),%rsi
lea    0xe0a(%rip),%rdi
call   1040 <printf@plt>
lea    -0x50(%rbp),%rsi
lea    0xdfa(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
lea    0xdee(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x10(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1050 <fprintf@plt>
mov    -0x10(%rbp),%rdi
lea    -0x50(%rbp),%rsi
call   1050 <fprintf@plt>
mov    -0x10(%rbp),%rdi
lea    0xdd2(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1060 <fflush@plt>
mov    0x2d63(%rip),%rax
mov    (%rax),%edi
call   10b0 <getc@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<draw_plot>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rdi,%r15
lea    0xe4b(%rip),%rdi
lea    0xe4c(%rip),%rsi
call   1070 <popen@plt>
mov    %rax,%rbx
test   %rax,%rax
je     129a <draw_plot+0xfa>
mov    0x10(%r15),%rdi
call   1090 <atoi@plt>
lea    -0x1(%rax),%edx
lea    0xe2a(%rip),%rsi
lea    0x20(%rsp),%r14
mov    %r14,%rdi
call   10a0 <sprintf@plt>
mov    0x10(%r15),%rdi
call   1090 <atoi@plt>
lea    -0x1(%rax),%edx
lea    0xe1d(%rip),%rsi
mov    %rsp,%r15
mov    %r15,%rdi
call   10a0 <sprintf@plt>
lea    0xe1e(%rip),%r12
mov    %r12,%rdi
mov    %r14,%rsi
call   1040 <printf@plt>
mov    %r12,%rdi
mov    %r15,%rsi
call   1040 <printf@plt>
lea    0xe05(%rip),%rdi
mov    $0xd,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   10b0 <fwrite@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <fprintf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <fprintf@plt>
lea    0xde4(%rip),%rdi
mov    $0x17,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   10b0 <fwrite@plt>
mov    %rbx,%rdi
call   1060 <fflush@plt>
mov    0x2d69(%rip),%rax
mov    (%rax),%edi
call   10c0 <getc@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
xor    %edi,%edi
call   1080 <perror@plt>
jmp    11cd <draw_plot+0x2d>

LLVM IR (-O0):
@.str = [8 x i8] c"gnuplot\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [19 x i8] c"set xrange [0:%d]\0A\00"
@.str.3 = [19 x i8] c"set yrange [0:%d]\0A\00"
@.str.4 = [4 x i8] c"%s\0A\00"
@.str.5 = [14 x i8] c"set view map\0A\00"
@.str.6 = [24 x i8] c"plot 'data' with image\0A\00"
@stdin = global i32 0
define void @draw_plot(i8** %0) {
%2 = alloca i8**
%3 = alloca i32*
%4 = alloca [32 x i8]
%5 = alloca [32 x i8]
store i8** %0, i8*** %2
%6 = call i32* @popen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %6, i32** %3
%7 = load i32*, i32** %3
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = call i32 @perror(i32* null)
br label %11
11: ; preds = %9, %1
%12 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%13 = load i8**, i8*** %2
%14 = getelementptr inbounds i8*, i8** %13, i64 2
%15 = load i8*, i8** %14
%16 = call i32 @atoi(i8* %15)
%17 = sub nsw i32 %16, 1
%18 = call i32 @sprintf(i8* %12, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %17)
%19 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%20 = load i8**, i8*** %2
%21 = getelementptr inbounds i8*, i8** %20, i64 2
%22 = load i8*, i8** %21
%23 = call i32 @atoi(i8* %22)
%24 = sub nsw i32 %23, 1
%25 = call i32 @sprintf(i8* %19, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %24)
%26 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%27 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %26)
%28 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%29 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %28)
%30 = load i32*, i32** %3
%31 = call i32 @fprintf(i32* %30, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0))
%32 = load i32*, i32** %3
%33 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%34 = call i32 @fprintf(i32* %32, i8* %33)
%35 = load i32*, i32** %3
%36 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%37 = call i32 @fprintf(i32* %35, i8* %36)
%38 = load i32*, i32** %3
%39 = call i32 @fprintf(i32* %38, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0))
%40 = load i32*, i32** %3
%41 = call i32 @fflush(i32* %40)
%42 = load i32, i32* @stdin
%43 = call i32 @getc(i32 %42)
%44 = load i32*, i32** %3
%45 = call i32 @fclose(i32* %44)
ret void
}

LLVM IR (-O2):
@.str = [8 x i8] c"gnuplot\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [19 x i8] c"set xrange [0:%d]\0A\00"
@.str.3 = [19 x i8] c"set yrange [0:%d]\0A\00"
@.str.4 = [4 x i8] c"%s\0A\00"
@.str.5 = [14 x i8] c"set view map\0A\00"
@.str.6 = [24 x i8] c"plot 'data' with image\0A\00"
@stdin = global i32 0
define void @draw_plot(i8** nocapture %0) {
%2 = alloca [32 x i8]
%3 = alloca [32 x i8]
%4 = tail call i32* @popen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = tail call i32 @perror(i32* null)
br label %8
8: ; preds = %6, %1
%9 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%10 = getelementptr inbounds i8*, i8** %0, i64 2
%11 = load i8*, i8** %10
%12 = tail call i32 @atoi(i8* %11)
%13 = add nsw i32 %12, -1
%14 = call i32 @sprintf(i8* %9, i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %13)
%15 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%16 = load i8*, i8** %10
%17 = tail call i32 @atoi(i8* %16)
%18 = add nsw i32 %17, -1
%19 = call i32 @sprintf(i8* %15, i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %18)
%20 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %9)
%21 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %15)
%22 = call i64 @fwrite(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i64 13, i64 1, i32* %4)
%23 = call i32 @fprintf(i32* %4, i8* %9)
%24 = call i32 @fprintf(i32* %4, i8* %15)
%25 = call i64 @fwrite(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0), i64 23, i64 1, i32* %4)
%26 = call i32 @fflush(i32* %4)
%27 = load i32, i32* @stdin
%28 = call i32 @getc(i32 %27)
%29 = call i32 @fclose(i32* %4)
ret void
}