#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 const *, char *);
int fscanf(int /*<<< orphan*/ *, char *, double *);
int /*<<< orphan*/ printf(char *, char const *);
double readClock(const char *clockfile) {
  double jdate = -1.;
  FILE *fptr;
  fptr = fopen(clockfile, "r");
  if (fptr == NULL) {
    printf("Error opening file: %s\n", clockfile);
    return -1;
  }
  int ret_code = fscanf(fptr, "%lf", &jdate);
  if (ret_code != 1) {
    printf("There was an error retrieving data from: %s\n", clockfile);
    fclose(fptr);
    return -1;
  }
  fclose(fptr);
  return jdate;
}


x86 assembly (clang, -O0):
<readClock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movsd  0xeac(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea4(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    119a <readClock+0x5a>
mov    -0x10(%rbp),%rsi
lea    0xe87(%rip),%rdi
call   1040 <printf@plt>
movsd  0xe70(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11f9 <readClock+0xb9>
mov    -0x20(%rbp),%rdi
lea    0xe7d(%rip),%rsi
lea    -0x18(%rbp),%rdx
call   1050 <fscanf@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x1,-0x24(%rbp)
je     11e6 <readClock+0xa6>
mov    -0x10(%rbp),%rsi
lea    0xe60(%rip),%rdi
call   1040 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movsd  0xe24(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11f9 <readClock+0xb9>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readClock>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
movabs $0xbff0000000000000,%rax
mov    %rax,(%rsp)
lea    0xeac(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     118f <readClock+0x4f>
mov    %rax,%rbx
lea    0xeb2(%rip),%rsi
mov    %rsp,%rdx
mov    %rax,%rdi
call   1050 <fscanf@plt>
cmp    $0x1,%eax
jne    11a0 <readClock+0x60>
mov    %rbx,%rdi
call   1030 <fclose@plt>
movsd  (%rsp),%xmm0
jmp    11bf <readClock+0x7f>
lea    0xe74(%rip),%rdi
mov    %r14,%rsi
call   1040 <printf@plt>
jmp    11b7 <readClock+0x77>
lea    0xe7f(%rip),%rdi
mov    %r14,%rsi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
movsd  0xe41(%rip),%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [24 x i8] c"Error opening file: %s\0A\00"
@.str.2 = [4 x i8] c"%lf\00"
@.str.3 = [45 x i8] c"There was an error retrieving data from: %s\0A\00"
define double @readClock(i8* %0) {
%2 = alloca double
%3 = alloca i8*
%4 = alloca double
%5 = alloca i32*
%6 = alloca i32
store i8* %0, i8** %3
store double -1.000000e+00, double* %4
%7 = load i8*, i8** %3
%8 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %8, i32** %5
%9 = load i32*, i32** %5
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %14
11: ; preds = %1
%12 = load i8*, i8** %3
%13 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %12)
store double -1.000000e+00, double* %2
br label %28
14: ; preds = %1
%15 = load i32*, i32** %5
%16 = call i32 @fscanf(i32* %15, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double* %4)
store i32 %16, i32* %6
%17 = load i32, i32* %6
%18 = icmp ne i32 %17, 1
br i1 %18, label %19, label %24
19: ; preds = %14
%20 = load i8*, i8** %3
%21 = call i32 @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.3, i64 0, i64 0), i8* %20)
%22 = load i32*, i32** %5
%23 = call i32 @fclose(i32* %22)
store double -1.000000e+00, double* %2
br label %28
24: ; preds = %14
%25 = load i32*, i32** %5
%26 = call i32 @fclose(i32* %25)
%27 = load double, double* %4
store double %27, double* %2
br label %28
28: ; preds = %24, %19, %11
%29 = load double, double* %2
ret double %29
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [24 x i8] c"Error opening file: %s\0A\00"
@.str.2 = [4 x i8] c"%lf\00"
@.str.3 = [45 x i8] c"There was an error retrieving data from: %s\0A\00"
define double @readClock(i8* %0) {
%2 = alloca double
%3 = bitcast double* %2 to i8*
store double -1.000000e+00, double* %2
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = tail call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %17
8: ; preds = %1
%9 = call i32 @fscanf(i32* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double* %2)
%10 = icmp eq i32 %9, 1
br i1 %10, label %14, label %11
11: ; preds = %8
%12 = call i32 @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.3, i64 0, i64 0), i8* %0)
%13 = call i32 @fclose(i32* %4)
br label %17
14: ; preds = %8
%15 = call i32 @fclose(i32* %4)
%16 = load double, double* %2
br label %17
17: ; preds = %11, %14, %6
%18 = phi double [ -1.000000e+00, %6 ], [ -1.000000e+00, %11 ], [ %16, %14 ]
ret double %18
}