#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 fprintf(int /*<<< orphan*/ *, char *, double);
int /*<<< orphan*/ printf(char *, char const *);
void writeClock(const char *clockfile, double new_jdate) {
  FILE *fptr;
  fptr = fopen(clockfile, "w");
  if (fptr == NULL) {
    printf("Error opening file: %s\n", clockfile);
    return;
  }
  int ret_code = fprintf(fptr, "%.5lf", new_jdate);
  if (ret_code < 0) {
    printf("There was an error writing data to: %s\n", clockfile);
    fclose(fptr);
    return;
  }
  fclose(fptr);
  return;
}


x86 assembly (clang, -O0):
<writeClock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xea4(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1185 <writeClock+0x45>
mov    -0x8(%rbp),%rsi
lea    0xe87(%rip),%rdi
call   1040 <printf@plt>
jmp    11ce <writeClock+0x8e>
mov    -0x18(%rbp),%rdi
movsd  -0x10(%rbp),%xmm0
lea    0xe85(%rip),%rsi
call   1050 <fprintf@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    11c5 <writeClock+0x85>
mov    -0x8(%rbp),%rsi
lea    0xe6e(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
jmp    11ce <writeClock+0x8e>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writeClock>:
push   %r14
push   %rbx
push   %rax
movsd  %xmm0,(%rsp)
mov    %rdi,%r14
lea    0xead(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1196 <writeClock+0x56>
mov    %rax,%rbx
lea    0xeb3(%rip),%rsi
mov    %rax,%rdi
movsd  (%rsp),%xmm0
call   1050 <fprintf@plt>
test   %eax,%eax
jns    1187 <writeClock+0x47>
lea    0xea1(%rip),%rdi
mov    %r14,%rsi
call   1040 <printf@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <fclose@plt>
lea    0xe65(%rip),%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <printf@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"w\00"
@.str.1 = [24 x i8] c"Error opening file: %s\0A\00"
@.str.2 = [6 x i8] c"%.5lf\00"
@.str.3 = [40 x i8] c"There was an error writing data to: %s\0A\00"
define void @writeClock(i8* %0, double %1) {
%3 = alloca i8*
%4 = alloca double
%5 = alloca i32*
%6 = alloca i32
store i8* %0, i8** %3
store double %1, 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 = %2
%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)
br label %28
14: ; preds = %2
%15 = load i32*, i32** %5
%16 = load double, double* %4
%17 = call i32 @fprintf(i32* %15, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), double %16)
store i32 %17, i32* %6
%18 = load i32, i32* %6
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %25
20: ; preds = %14
%21 = load i8*, i8** %3
%22 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), i8* %21)
%23 = load i32*, i32** %5
%24 = call i32 @fclose(i32* %23)
br label %28
25: ; preds = %14
%26 = load i32*, i32** %5
%27 = call i32 @fclose(i32* %26)
br label %28
28: ; preds = %25, %20, %11
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@.str.1 = [24 x i8] c"Error opening file: %s\0A\00"
@.str.2 = [6 x i8] c"%.5lf\00"
@.str.3 = [40 x i8] c"There was an error writing data to: %s\0A\00"
define void @writeClock(i8* %0, double %1) {
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %15
7: ; preds = %2
%8 = tail call i32 @fprintf(i32* %3, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), double %1)
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %7
%11 = tail call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), i8* %0)
%12 = tail call i32 @fclose(i32* %3)
br label %15
13: ; preds = %7
%14 = tail call i32 @fclose(i32* %3)
br label %15
15: ; preds = %10, %13, %5
ret void
}