#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*/ fread(double *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(double *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int main(void) {
  FILE *fp;
  double pi = 3.14159265358979323846;
  printf("The pi from the parameter %23.21f.\n", pi);
  if ((fp = fopen("PI.bin", "wb")) == NULL)
    printf("\a Failed to open the file.\n");
  else {
    fwrite(&pi, sizeof(double), 1, fp);
    fclose(fp);
  }
  if ((fp = fopen("PI.bin", "rb")) == NULL)
    printf("\a Failed to open the file.\n");
  else {
    fread(&pi, sizeof(double), 1, fp);
    printf("The pi from the file %23.21f.\n", pi);
    fclose(fp);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movsd  0xe99(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
lea    0xe90(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
lea    0xea6(%rip),%rdi
lea    0xea6(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11b3 <main+0x63>
lea    0xe8f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    11d3 <main+0x83>
mov    -0x10(%rbp),%rcx
lea    -0x18(%rbp),%rdi
mov    $0x8,%esi
mov    $0x1,%edx
call   1070 <fwrite@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
lea    0xe52(%rip),%rdi
lea    0xe71(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    1207 <main+0xb7>
lea    0xe3b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    123a <main+0xea>
mov    -0x10(%rbp),%rcx
lea    -0x18(%rbp),%rdi
mov    $0x8,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
movsd  -0x18(%rbp),%xmm0
lea    0xe2b(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
movabs $0x400921fb54442d18,%rax
21 09 40
mov    %rax,0x8(%rsp)
lea    0xe8d(%rip),%rdi
movsd  0xe7d(%rip),%xmm0
mov    $0x1,%al
call   1060 <printf@plt>
lea    0xe9b(%rip),%rdi
lea    0xe9b(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11c6 <main+0x66>
mov    %rax,%rbx
lea    0x8(%rsp),%rdi
mov    $0x8,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1080 <fwrite@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
jmp    11d2 <main+0x72>
lea    0xe8b(%rip),%rdi
call   1030 <puts@plt>
lea    0xe53(%rip),%rdi
lea    0xe56(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1222 <main+0xc2>
mov    %rax,%rbx
lea    0x8(%rsp),%rdi
mov    $0x8,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1040 <fread@plt>
movsd  0x8(%rsp),%xmm0
lea    0xe28(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
jmp    122e <main+0xce>
lea    0xe2f(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [36 x i8] c"The pi from the parameter %23.21f.\0A\00"
@.str.1 = [7 x i8] c"PI.bin\00"
@.str.2 = [3 x i8] c"wb\00"
@.str.3 = [28 x i8] c"\07 Failed to open the file.\0A\00"
@.str.4 = [3 x i8] c"rb\00"
@.str.5 = [31 x i8] c"The pi from the file %23.21f.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca double
store i32 0, i32* %1
store double 0x400921FB54442D18, double* %3
%4 = load double, double* %3
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), double %4)
%6 = call i32* @fopen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %6, i32** %2
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
br label %15
10: ; preds = %0
%11 = load i32*, i32** %2
%12 = call i32 @fwrite(double* %3, i32 8, i32 1, i32* %11)
%13 = load i32*, i32** %2
%14 = call i32 @fclose(i32* %13)
br label %15
15: ; preds = %10, %8
%16 = call i32* @fopen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32* %16, i32** %2
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %20
18: ; preds = %15
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
br label %27
20: ; preds = %15
%21 = load i32*, i32** %2
%22 = call i32 @fread(double* %3, i32 8, i32 1, i32* %21)
%23 = load double, double* %3
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0), double %23)
%25 = load i32*, i32** %2
%26 = call i32 @fclose(i32* %25)
br label %27
27: ; preds = %20, %18
ret i32 0
}

LLVM IR (-O2):
@.str = [36 x i8] c"The pi from the parameter %23.21f.\0A\00"
@.str.1 = [7 x i8] c"PI.bin\00"
@.str.2 = [3 x i8] c"wb\00"
@.str.4 = [3 x i8] c"rb\00"
@.str.5 = [31 x i8] c"The pi from the file %23.21f.\0A\00"
@str.6 = [27 x i8] c"\07 Failed to open the file.\00"
define i32 @main() {
%1 = alloca double
%2 = bitcast double* %1 to i8*
store double 0x400921FB54442D18, double* %1
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), double 0x400921FB54442D18)
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.6, i64 0, i64 0))
br label %11
8: ; preds = %0
%9 = call i32 @fwrite(double* %1, i32 8, i32 1, i32* %4)
%10 = tail call i32 @fclose(i32* %4)
br label %11
11: ; preds = %8, %6
%12 = tail call i32* @fopen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %16
14: ; preds = %11
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.6, i64 0, i64 0))
br label %21
16: ; preds = %11
%17 = call i32 @fread(double* %1, i32 8, i32 1, i32* %12)
%18 = load double, double* %1
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0), double %18)
%20 = tail call i32 @fclose(i32* %12)
br label %21
21: ; preds = %16, %14
ret i32 0
}