#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*/ *fdopen(int, char *);
int mkstemp(char *);
int /*<<< orphan*/ perror(char *);
int plotActual(double **, int, int, char *, char *, int /*<<< orphan*/ *,
               int /*<<< orphan*/ *);
void plot(double **data, int rows, int cols) {
  char dataFilename[] = "/tmp/ucpplotdataXXXXXX";
  char scriptFilename[] = "/tmp/ucpplotscriptXXXXXX";
  int dataFd, scriptFd;
  FILE *dataFile;
  FILE *scriptFile;
  int ret;
  dataFd = mkstemp(dataFilename);
  scriptFd = mkstemp(scriptFilename);
  if (dataFd == -1 || scriptFd == -1) {
    perror("Plotting failed - unable to create temporary files");
  } else {
    dataFile = fdopen(dataFd, "w");
    scriptFile = fdopen(scriptFd, "w");
    if (dataFile == NULL || scriptFile == NULL) {
      perror("Plotting failed - unable to open temporary file stream");
    } else {
      ret = plotActual(data, rows, cols, dataFilename, scriptFilename, dataFile,
                       scriptFile);
      if (ret % 256 != 0) {
        perror("Plotting failed - unable to run gnuplot");
      }
      fclose(dataFile);
      fclose(scriptFile);
    }
  }
}


x86 assembly (clang, -O0):
<plot>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    0xe94(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xe91(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xe8f(%rip),%eax
mov    %eax,-0x20(%rbp)
mov    0xe89(%rip),%ax
mov    %ax,-0x1c(%rbp)
mov    0xe81(%rip),%al
mov    %al,-0x1a(%rbp)
mov    0xe81(%rip),%rax
mov    %rax,-0x50(%rbp)
mov    0xe7e(%rip),%rax
mov    %rax,-0x48(%rbp)
mov    0xe7b(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0xe79(%rip),%al
mov    %al,-0x38(%rbp)
lea    -0x30(%rbp),%rdi
call   1040 <mkstemp@plt>
mov    %eax,-0x54(%rbp)
lea    -0x50(%rbp),%rdi
call   1040 <mkstemp@plt>
mov    %eax,-0x58(%rbp)
cmpl   $0xffffffff,-0x54(%rbp)
je     11ee <plot+0x9e>
cmpl   $0xffffffff,-0x58(%rbp)
jne    11ff <plot+0xaf>
lea    0xe44(%rip),%rdi
call   1070 <perror@plt>
jmp    12a9 <plot+0x159>
mov    -0x54(%rbp),%edi
lea    0xe63(%rip),%rsi
call   1060 <fdopen@plt>
mov    %rax,-0x60(%rbp)
mov    -0x58(%rbp),%edi
lea    0xe50(%rip),%rsi
call   1060 <fdopen@plt>
mov    %rax,-0x68(%rbp)
cmpq   $0x0,-0x60(%rbp)
je     123b <plot+0xeb>
cmpq   $0x0,-0x68(%rbp)
jne    124c <plot+0xfc>
lea    0xe2c(%rip),%rdi
call   1070 <perror@plt>
jmp    12a4 <plot+0x154>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
lea    -0x30(%rbp),%rcx
lea    -0x50(%rbp),%r8
mov    -0x60(%rbp),%r9
mov    -0x68(%rbp),%rax
mov    %rax,(%rsp)
call   1050 <plotActual@plt>
mov    %eax,-0x6c(%rbp)
mov    -0x6c(%rbp),%eax
mov    $0x100,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     1292 <plot+0x142>
lea    0xe18(%rip),%rdi
call   1070 <perror@plt>
mov    -0x60(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x68(%rbp),%rdi
call   1030 <fclose@plt>
jmp    12a9 <plot+0x159>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<plot>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %edx,%r15d
mov    %esi,%r12d
mov    %rdi,%r14
movaps 0xe92(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movabs $0x58585858585861,%rax
mov    %rax,0x1f(%rsp)
movups 0xea0(%rip),%xmm0
movups %xmm0,0x39(%rsp)
movaps 0xe8b(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
lea    0x10(%rsp),%rdi
call   1040 <mkstemp@plt>
mov    %eax,%ebx
lea    0x30(%rsp),%rdi
call   1040 <mkstemp@plt>
cmp    $0xffffffff,%ebx
je     1230 <plot+0xe0>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
je     1230 <plot+0xe0>
mov    %r14,0x8(%rsp)
lea    0xea4(%rip),%r14
mov    %ebx,%edi
mov    %r14,%rsi
call   1060 <fdopen@plt>
mov    %rax,%r13
mov    %ebp,%edi
mov    %r14,%rsi
call   1060 <fdopen@plt>
test   %r13,%r13
je     123e <plot+0xee>
mov    %rax,%rbx
test   %rax,%rax
je     123e <plot+0xee>
mov    %rbx,(%rsp)
lea    0x10(%rsp),%rcx
lea    0x30(%rsp),%r8
mov    0x8(%rsp),%rdi
mov    %r12d,%esi
mov    %r15d,%edx
mov    %r13,%r9
call   1050 <plotActual@plt>
test   %al,%al
jne    124c <plot+0xfc>
mov    %r13,%rdi
call   1030 <fclose@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe02(%rip),%rdi
call   1070 <perror@plt>
jmp    1221 <plot+0xd1>
lea    0xe29(%rip),%rdi
call   1070 <perror@plt>
jmp    1221 <plot+0xd1>
lea    0xe52(%rip),%rdi
call   1070 <perror@plt>
jmp    1211 <plot+0xc1>

LLVM IR (-O0):
@__const.plot.dataFilename = [23 x i8] c"/tmp/ucpplotdataXXXXXX\00"
@__const.plot.scriptFilename = [25 x i8] c"/tmp/ucpplotscriptXXXXXX\00"
@.str = [51 x i8] c"Plotting failed - unable to create temporary files\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [55 x i8] c"Plotting failed - unable to open temporary file stream\00"
@.str.3 = [40 x i8] c"Plotting failed - unable to run gnuplot\00"
define void @plot(double** %0, i32 %1, i32 %2) {
%4 = alloca double**
%5 = alloca i32
%6 = alloca i32
%7 = alloca [23 x i8]
%8 = alloca [25 x i8]
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32*
%12 = alloca i32*
%13 = alloca i32
store double** %0, double*** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%14 = bitcast [23 x i8]* %7 to i8*
%15 = bitcast [25 x i8]* %8 to i8*
%16 = getelementptr inbounds [23 x i8], [23 x i8]* %7, i64 0, i64 0
%17 = call i32 @mkstemp(i8* %16)
store i32 %17, i32* %9
%18 = getelementptr inbounds [25 x i8], [25 x i8]* %8, i64 0, i64 0
%19 = call i32 @mkstemp(i8* %18)
store i32 %19, i32* %10
%20 = load i32, i32* %9
%21 = icmp eq i32 %20, -1
br i1 %21, label %25, label %22
22: ; preds = %3
%23 = load i32, i32* %10
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %27
25: ; preds = %22, %3
%26 = call i32 @perror(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0))
br label %59
27: ; preds = %22
%28 = load i32, i32* %9
%29 = call i32* @fdopen(i32 %28, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %29, i32** %11
%30 = load i32, i32* %10
%31 = call i32* @fdopen(i32 %30, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %31, i32** %12
%32 = load i32*, i32** %11
%33 = icmp eq i32* %32, null
br i1 %33, label %37, label %34
34: ; preds = %27
%35 = load i32*, i32** %12
%36 = icmp eq i32* %35, null
br i1 %36, label %37, label %39
37: ; preds = %34, %27
%38 = call i32 @perror(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.2, i64 0, i64 0))
br label %58
39: ; preds = %34
%40 = load double**, double*** %4
%41 = load i32, i32* %5
%42 = load i32, i32* %6
%43 = getelementptr inbounds [23 x i8], [23 x i8]* %7, i64 0, i64 0
%44 = getelementptr inbounds [25 x i8], [25 x i8]* %8, i64 0, i64 0
%45 = load i32*, i32** %11
%46 = load i32*, i32** %12
%47 = call i32 @plotActual(double** %40, i32 %41, i32 %42, i8* %43, i8* %44, i32* %45, i32* %46)
store i32 %47, i32* %13
%48 = load i32, i32* %13
%49 = srem i32 %48, 256
%50 = icmp ne i32 %49, 0
br i1 %50, label %51, label %53
51: ; preds = %39
%52 = call i32 @perror(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0))
br label %53
53: ; preds = %51, %39
%54 = load i32*, i32** %11
%55 = call i32 @fclose(i32* %54)
%56 = load i32*, i32** %12
%57 = call i32 @fclose(i32* %56)
br label %58
58: ; preds = %53, %37
br label %59
59: ; preds = %58, %25
ret void
}

LLVM IR (-O2):
@__const.plot.dataFilename = [23 x i8] c"/tmp/ucpplotdataXXXXXX\00"
@__const.plot.scriptFilename = [25 x i8] c"/tmp/ucpplotscriptXXXXXX\00"
@.str = [51 x i8] c"Plotting failed - unable to create temporary files\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [55 x i8] c"Plotting failed - unable to open temporary file stream\00"
@.str.3 = [40 x i8] c"Plotting failed - unable to run gnuplot\00"
define void @plot(double** %0, i32 %1, i32 %2) {
%4 = alloca [23 x i8]
%5 = alloca [25 x i8]
%6 = getelementptr inbounds [23 x i8], [23 x i8]* %4, i64 0, i64 0
%7 = getelementptr inbounds [25 x i8], [25 x i8]* %5, i64 0, i64 0
%8 = call i32 @mkstemp(i8* %6)
%9 = call i32 @mkstemp(i8* %7)
%10 = icmp eq i32 %8, -1
%11 = icmp eq i32 %9, -1
%12 = select i1 %10, i1 true, i1 %11
br i1 %12, label %13, label %15
13: ; preds = %3
%14 = call i32 @perror(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0))
br label %32
15: ; preds = %3
%16 = call i32* @fdopen(i32 %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%17 = call i32* @fdopen(i32 %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%18 = icmp eq i32* %16, null
%19 = icmp eq i32* %17, null
%20 = or i1 %18, %19
br i1 %20, label %21, label %23
21: ; preds = %15
%22 = call i32 @perror(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.2, i64 0, i64 0))
br label %32
23: ; preds = %15
%24 = call i32 @plotActual(double** %0, i32 %1, i32 %2, i8* %6, i8* %7, i32* %16, i32* %17)
%25 = and i32 %24, 255
%26 = icmp eq i32 %25, 0
br i1 %26, label %29, label %27
27: ; preds = %23
%28 = call i32 @perror(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0))
br label %29
29: ; preds = %27, %23
%30 = call i32 @fclose(i32* %16)
%31 = call i32 @fclose(i32* %17)
br label %32
32: ; preds = %21, %29, %13
ret void
}