#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
scalar_t__ system(char *);
int /*<<< orphan*/ unlink(char *);
int graph(unsigned int *results, size_t len) {
  FILE *f;
  unsigned int i;
  if (system("which Rscript &>/dev/null") != 0) {
    fprintf(stderr, "error: could not find Rscript\n");
    return -1;
  }
  f = fopen("data.csv", "w");
  fputs("value,occurrences\n", f);
  for (i = 0; i < len; i++)
    fprintf(f, "%u,%u\n", i + 2, results[i]);
  fclose(f);
  system("Rscript ./plot.r &>/dev/null");
  unlink("data.csv");
  return 0;
}


x86 assembly (clang, -O0):
<graph>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    0xe89(%rip),%rdi
call   1050 <system@plt>
cmp    $0x0,%rax
je     11aa <graph+0x4a>
mov    0x2e53(%rip),%rax
movslq (%rax),%rdi
lea    0xe83(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    123d <graph+0xdd>
lea    0xe88(%rip),%rdi
lea    0xe8a(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
lea    0xe78(%rip),%rdi
call   1060 <fputs@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x18(%rbp),%rax
jae    1215 <graph+0xb5>
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%edx
add    $0x2,%edx
mov    -0x10(%rbp),%rax
mov    -0x24(%rbp),%ecx
mov    (%rax,%rcx,4),%ecx
lea    0xe57(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11d8 <graph+0x78>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
lea    0xe39(%rip),%rdi
call   1050 <system@plt>
lea    0xe08(%rip),%rdi
call   1030 <unlink@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<graph>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
lea    0xe8a(%rip),%rdi
call   1050 <system@plt>
test   %rax,%rax
je     11aa <graph+0x4a>
mov    0x2e59(%rip),%rax
movslq (%rax),%rcx
lea    0xe89(%rip),%rdi
mov    $0x1e,%esi
mov    $0x1,%edx
call   1080 <fwrite@plt>
mov    $0xffffffff,%eax
jmp    122e <graph+0xce>
lea    0xe88(%rip),%rdi
lea    0xe8a(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r13
lea    0xe7d(%rip),%rdi
mov    $0x12,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1080 <fwrite@plt>
test   %r15,%r15
je     120c <graph+0xac>
lea    0xe72(%rip),%r12
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
lea    0x2(%rbx),%edx
mov    (%r14,%rbx,4),%ecx
mov    %r13,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
add    $0x1,%ebx
cmp    %r15,%rbx
jb     11f0 <graph+0x90>
mov    %r13,%rdi
call   1040 <fclose@plt>
lea    0xe43(%rip),%rdi
call   1050 <system@plt>
lea    0xe12(%rip),%rdi
call   1030 <unlink@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [26 x i8] c"which Rscript &>/dev/null\00"
@stderr = global i32 0
@.str.1 = [31 x i8] c"error: could not find Rscript\0A\00"
@.str.2 = [9 x i8] c"data.csv\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [19 x i8] c"value,occurrences\0A\00"
@.str.5 = [7 x i8] c"%u,%u\0A\00"
@.str.6 = [29 x i8] c"Rscript ./plot.r &>/dev/null\00"
define i32 @graph(i32* %0, i64 %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i64
%6 = alloca i32*
%7 = alloca i32
store i32* %0, i32** %4
store i64 %1, i64* %5
%8 = call i64 @system(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %15
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = sext i32 %11 to i64
%13 = inttoptr i64 %12 to i32*
%14 = call i32 (i32*, i8*, ...) @fprintf(i32* %13, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %42
15: ; preds = %2
%16 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 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* %16, i32** %6
%17 = load i32*, i32** %6
%18 = call i32 @fputs(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i32* %17)
store i32 0, i32* %7
br label %19
19: ; preds = %34, %15
%20 = load i32, i32* %7
%21 = zext i32 %20 to i64
%22 = load i64, i64* %5
%23 = icmp ult i64 %21, %22
br i1 %23, label %24, label %37
24: ; preds = %19
%25 = load i32*, i32** %6
%26 = load i32, i32* %7
%27 = add i32 %26, 2
%28 = load i32*, i32** %4
%29 = load i32, i32* %7
%30 = zext i32 %29 to i64
%31 = getelementptr inbounds i32, i32* %28, i64 %30
%32 = load i32, i32* %31
%33 = call i32 (i32*, i8*, ...) @fprintf(i32* %25, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32 %27, i32 %32)
br label %34
34: ; preds = %24
%35 = load i32, i32* %7
%36 = add i32 %35, 1
store i32 %36, i32* %7
br label %19
37: ; preds = %19
%38 = load i32*, i32** %6
%39 = call i32 @fclose(i32* %38)
%40 = call i64 @system(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.6, i64 0, i64 0))
%41 = call i32 @unlink(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %3
br label %42
42: ; preds = %37, %10
%43 = load i32, i32* %3
ret i32 %43
}

LLVM IR (-O2):
@.str = [26 x i8] c"which Rscript &>/dev/null\00"
@stderr = global i32 0
@.str.1 = [31 x i8] c"error: could not find Rscript\0A\00"
@.str.2 = [9 x i8] c"data.csv\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [19 x i8] c"value,occurrences\0A\00"
@.str.5 = [7 x i8] c"%u,%u\0A\00"
@.str.6 = [29 x i8] c"Rscript ./plot.r &>/dev/null\00"
define i32 @graph(i32* nocapture %0, i64 %1) {
%3 = tail call i64 @system(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i64 %3, 0
br i1 %4, label %10, label %5
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = sext i32 %6 to i64
%8 = inttoptr i64 %7 to i32*
%9 = tail call i64 @fwrite(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i64 30, i64 1, i32* %8)
br label %28
10: ; preds = %2
%11 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%12 = tail call i64 @fwrite(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i64 18, i64 1, i32* %11)
%13 = icmp eq i64 %1, 0
br i1 %13, label %24, label %14
14: ; preds = %10, %14
%15 = phi i64 [ %22, %14 ], [ 0, %10 ]
%16 = trunc i64 %15 to i32
%17 = add i32 %16, 2
%18 = getelementptr inbounds i32, i32* %0, i64 %15
%19 = load i32, i32* %18
%20 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %11, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32 %17, i32 %19)
%21 = add nuw nsw i64 %15, 1
%22 = and i64 %21, 4294967295
%23 = icmp ult i64 %22, %1
br i1 %23, label %14, label %24
24: ; preds = %14, %10
%25 = tail call i32 @fclose(i32* %11)
%26 = tail call i64 @system(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.6, i64 0, i64 0))
%27 = tail call i32 @unlink(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
br label %28
28: ; preds = %24, %5
%29 = phi i32 [ -1, %5 ], [ 0, %24 ]
ret i32 %29
}