#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 *, double);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ *gnuplot();
char *strdup(int /*<<< orphan*/);
int /*<<< orphan*/ tmpnam(int /*<<< orphan*/);
int /*<<< orphan*/ unlink(char *);
void plot_histogram(FILE *f, const char **opts, int sz, double d[]) {
  char *tmpfname = strdup(tmpnam(0));
  FILE *tmp = fopen(tmpfname, "w");
  int i;
  for (i = 0; i < sz; i++)
    fprintf(tmp, "%g\n", d[i]);
  fclose(tmp);
  FILE *gp = gnuplot();
  fclose(gp);
  unlink(tmpfname);
  free(tmpfname);
}


x86 assembly (clang, -O0):
<plot_histogram>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
xor    %edi,%edi
call   1080 <tmpnam@plt>
mov    %eax,%edi
call   1090 <strdup@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xe4c(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11fb <plot_histogram+0x7b>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xe1a(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11c4 <plot_histogram+0x44>
mov    -0x30(%rbp),%rdi
call   1050 <fclose@plt>
mov    $0x0,%al
call   10a0 <gnuplot@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1040 <unlink@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<plot_histogram>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r15
mov    %edx,%ebp
xor    %edi,%edi
call   1080 <tmpnam@plt>
mov    %eax,%edi
call   1090 <strdup@plt>
mov    %rax,%r14
lea    0xe58(%rip),%rsi
mov    %rax,%rdi
call   1070 <fopen@plt>
mov    %rax,%r13
test   %ebp,%ebp
jle    11ea <plot_histogram+0x6a>
mov    %ebp,%ebp
xor    %ebx,%ebx
lea    0xe40(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsd  (%r15,%rbx,8),%xmm0
mov    %r13,%rdi
mov    %r12,%rsi
call   1060 <fprintf@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    11d0 <plot_histogram+0x50>
mov    %r13,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
call   10a0 <gnuplot@plt>
mov    %rax,%rdi
call   1050 <fclose@plt>
mov    %r14,%rdi
call   1040 <unlink@plt>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"w\00"
@.str.1 = [4 x i8] c"%g\0A\00"
define void @plot_histogram(i32* %0, i8** %1, i32 %2, double* %3) {
%5 = alloca i32*
%6 = alloca i8**
%7 = alloca i32
%8 = alloca double*
%9 = alloca i8*
%10 = alloca i32*
%11 = alloca i32
%12 = alloca i32*
store i32* %0, i32** %5
store i8** %1, i8*** %6
store i32 %2, i32* %7
store double* %3, double** %8
%13 = call i32 @tmpnam(i32 0)
%14 = call i8* @strdup(i32 %13)
store i8* %14, i8** %9
%15 = load i8*, i8** %9
%16 = call i32* @fopen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %16, i32** %10
store i32 0, i32* %11
br label %17
17: ; preds = %29, %4
%18 = load i32, i32* %11
%19 = load i32, i32* %7
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %32
21: ; preds = %17
%22 = load i32*, i32** %10
%23 = load double*, double** %8
%24 = load i32, i32* %11
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds double, double* %23, i64 %25
%27 = load double, double* %26
%28 = call i32 @fprintf(i32* %22, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double %27)
br label %29
29: ; preds = %21
%30 = load i32, i32* %11
%31 = add nsw i32 %30, 1
store i32 %31, i32* %11
br label %17
32: ; preds = %17
%33 = load i32*, i32** %10
%34 = call i32 @fclose(i32* %33)
%35 = call i32* (...) @gnuplot()
store i32* %35, i32** %12
%36 = load i32*, i32** %12
%37 = call i32 @fclose(i32* %36)
%38 = load i8*, i8** %9
%39 = call i32 @unlink(i8* %38)
%40 = load i8*, i8** %9
%41 = call i32 @free(i8* %40)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@.str.1 = [4 x i8] c"%g\0A\00"
define void @plot_histogram(i32* nocapture readnone %0, i8** nocapture readnone %1, i32 %2, double* nocapture %3) {
%5 = tail call i32 @tmpnam(i32 0)
%6 = tail call i8* @strdup(i32 %5)
%7 = tail call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = icmp sgt i32 %2, 0
br i1 %8, label %9, label %18
9: ; preds = %4
%10 = zext i32 %2 to i64
br label %11
11: ; preds = %9, %11
%12 = phi i64 [ 0, %9 ], [ %16, %11 ]
%13 = getelementptr inbounds double, double* %3, i64 %12
%14 = load double, double* %13
%15 = tail call i32 @fprintf(i32* %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double %14)
%16 = add nuw nsw i64 %12, 1
%17 = icmp eq i64 %16, %10
br i1 %17, label %18, label %11
18: ; preds = %11, %4
%19 = tail call i32 @fclose(i32* %7)
%20 = tail call i32* (...) @gnuplot()
%21 = tail call i32 @fclose(i32* %20)
%22 = tail call i32 @unlink(i8* %6)
%23 = tail call i32 @free(i8* %6)
ret void
}