#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 */
struct stat {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sprintf(char *, char *, double const, double const,
                           double const, double const, int);
scalar_t__ stat(char *, struct stat *);
int CheckPt_Cluster(const double Vx, const double Vy, const double Vz,
                    const double T, int r) {
  if (T < 0) {
    printf("ERROR Temperature negative\n");
    return -1;
  }
  struct stat st;
  char FileName[256];
  FILE *file;
  FileName[0] = '\0';
  sprintf(FileName, "CHECKFILE/DataT%gVx%gVy%gVz%gR%d", T, Vx, Vy, Vz, r);
  if (stat("CLUSTERFILE", &st) == 0) {
    if ((file = fopen(FileName, "r"))) {
      fclose(file);
      printf("Cluster file exists\n");
      return 0;
    } else {
      printf("Cluster file does not exist\n");
      return -1;
    }
  } else {
    printf("ERROR CHECKPOINT Cluster directory not found\n");
    return -1;
  }
}


x86 assembly (clang, -O0):
<CheckPt_Cluster>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  %xmm2,-0x20(%rbp)
movsd  %xmm3,-0x28(%rbp)
mov    %edi,-0x2c(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x28(%rbp),%xmm0
jbe    1198 <CheckPt_Cluster+0x48>
lea    0xe79(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1256 <CheckPt_Cluster+0x106>
movb   $0x0,-0x130(%rbp)
lea    -0x130(%rbp),%rdi
movsd  -0x28(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm2
movsd  -0x20(%rbp),%xmm3
mov    -0x2c(%rbp),%edx
lea    0xe58(%rip),%rsi
call   1070 <sprintf@plt>
lea    0xe6d(%rip),%rdi
lea    -0x30(%rbp),%rsi
call   1050 <stat@plt>
cmp    $0x0,%rax
jne    1243 <CheckPt_Cluster+0xf3>
lea    -0x130(%rbp),%rdi
lea    0xe58(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x138(%rbp)
cmp    $0x0,%rax
je     122b <CheckPt_Cluster+0xdb>
mov    -0x138(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xe31(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1256 <CheckPt_Cluster+0x106>
lea    0xe2e(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1256 <CheckPt_Cluster+0x106>
lea    0xe33(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CheckPt_Cluster>:
push   %rbx
sub    $0x110,%rsp
movapd %xmm2,%xmm4
movaps %xmm1,%xmm2
movapd %xmm0,%xmm1
xorpd  %xmm0,%xmm0
ucomisd %xmm3,%xmm0
jbe    1180 <CheckPt_Cluster+0x30>
lea    0xf18(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%ebx
jmp    11f9 <CheckPt_Cluster+0xa9>
mov    %edi,%edx
movb   $0x0,0x10(%rsp)
lea    0xe72(%rip),%rsi
lea    0x10(%rsp),%rdi
movapd %xmm3,%xmm0
movapd %xmm4,%xmm3
call   1070 <sprintf@plt>
lea    0xe7a(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1050 <stat@plt>
mov    $0xffffffff,%ebx
test   %rax,%rax
je     11c4 <CheckPt_Cluster+0x74>
lea    0xe6d(%rip),%rdi
jmp    11f4 <CheckPt_Cluster+0xa4>
lea    0xe62(%rip),%rsi
lea    0x10(%rsp),%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     11ed <CheckPt_Cluster+0x9d>
mov    %rax,%rdi
call   1040 <fclose@plt>
xor    %ebx,%ebx
lea    0xe8d(%rip),%rdi
jmp    11f4 <CheckPt_Cluster+0xa4>
lea    0xe68(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%eax
add    $0x110,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [28 x i8] c"ERROR Temperature negative\0A\00"
@.str.1 = [33 x i8] c"CHECKFILE/DataT%gVx%gVy%gVz%gR%d\00"
@.str.2 = [12 x i8] c"CLUSTERFILE\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [21 x i8] c"Cluster file exists\0A\00"
@.str.5 = [29 x i8] c"Cluster file does not exist\0A\00"
@.str.6 = [46 x i8] c"ERROR CHECKPOINT Cluster directory not found\0A\00"
define i32 @CheckPt_Cluster(double %0, double %1, double %2, double %3, i32 %4) {
%6 = alloca i32
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca i32
%12 = alloca %struct.stat
%13 = alloca [256 x i8]
%14 = alloca i32*
store double %0, double* %7
store double %1, double* %8
store double %2, double* %9
store double %3, double* %10
store i32 %4, i32* %11
%15 = load double, double* %10
%16 = fcmp olt double %15, 0.000000e+00
br i1 %16, label %17, label %19
17: ; preds = %5
%18 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %6
br label %42
19: ; preds = %5
%20 = getelementptr inbounds [256 x i8], [256 x i8]* %13, i64 0, i64 0
store i8 0, i8* %20
%21 = getelementptr inbounds [256 x i8], [256 x i8]* %13, i64 0, i64 0
%22 = load double, double* %10
%23 = load double, double* %7
%24 = load double, double* %8
%25 = load double, double* %9
%26 = load i32, i32* %11
%27 = call i32 @sprintf(i8* %21, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), double %22, double %23, double %24, double %25, i32 %26)
%28 = call i64 @stat(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), %struct.stat* %12)
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %40
30: ; preds = %19
%31 = getelementptr inbounds [256 x i8], [256 x i8]* %13, i64 0, i64 0
%32 = call i32* @fopen(i8* %31, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %32, i32** %14
%33 = icmp ne i32* %32, null
br i1 %33, label %34, label %38
34: ; preds = %30
%35 = load i32*, i32** %14
%36 = call i32 @fclose(i32* %35)
%37 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %6
br label %42
38: ; preds = %30
%39 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0))
store i32 -1, i32* %6
br label %42
40: ; preds = %19
%41 = call i32 @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.6, i64 0, i64 0))
store i32 -1, i32* %6
br label %42
42: ; preds = %40, %38, %34, %17
%43 = load i32, i32* %6
ret i32 %43
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str.1 = [33 x i8] c"CHECKFILE/DataT%gVx%gVy%gVz%gR%d\00"
@.str.2 = [12 x i8] c"CLUSTERFILE\00"
@.str.3 = [2 x i8] c"r\00"
@str = [45 x i8] c"ERROR CHECKPOINT Cluster directory not found\00"
@str.7 = [28 x i8] c"Cluster file does not exist\00"
@str.8 = [20 x i8] c"Cluster file exists\00"
@str.9 = [27 x i8] c"ERROR Temperature negative\00"
define i32 @CheckPt_Cluster(double %0, double %1, double %2, double %3, i32 %4) {
%6 = alloca %struct.stat
%7 = alloca [256 x i8]
%8 = fcmp olt double %3, 0.000000e+00
br i1 %8, label %9, label %11
9: ; preds = %5
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.9, i64 0, i64 0))
br label %26
11: ; preds = %5
%12 = bitcast %struct.stat* %6 to i8*
%13 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
store i8 0, i8* %13
%14 = call i32 @sprintf(i8* %13, i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), double %3, double %0, double %1, double %2, i32 %4)
%15 = call i64 @stat(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), %struct.stat* %6)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %22
17: ; preds = %11
%18 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%19 = icmp eq i32* %18, null
br i1 %19, label %22, label %20
20: ; preds = %17
%21 = call i32 @fclose(i32* %18)
br label %22
22: ; preds = %11, %17, %20
%23 = phi i8* [ getelementptr inbounds ([20 x i8], [20 x i8]* @str.8, i64 0, i64 0), %20 ], [ getelementptr inbounds ([28 x i8], [28 x i8]* @str.7, i64 0, i64 0), %17 ], [ getelementptr inbounds ([45 x i8], [45 x i8]* @str, i64 0, i64 0), %11 ]
%24 = phi i32 [ 0, %20 ], [ -1, %17 ], [ -1, %11 ]
%25 = call i32 @puts(i8* dereferenceable(1) %23)
br label %26
26: ; preds = %22, %9
%27 = phi i32 [ -1, %9 ], [ %24, %22 ]
ret i32 %27
}