#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*/ fprintf(int /*<<< orphan*/ *, char *, double);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, double *);
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.txt", "w")) == NULL)
    printf("\a Failed to open the file.\n");
  else {
    fprintf(fp, "%23.21f", pi);
    fclose(fp);
  }
  if ((fp = fopen("PI.txt", "r")) == NULL)
    printf("\a Failed to open the file.\n");
  else {
    fscanf(fp, "%lf", &pi);
    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   1040 <printf@plt>
lea    0xea6(%rip),%rdi
lea    0xea6(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11b3 <main+0x63>
lea    0xe8e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11d1 <main+0x81>
mov    -0x10(%rbp),%rdi
movsd  -0x18(%rbp),%xmm0
lea    0xe8e(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xe54(%rip),%rdi
lea    0xe7a(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    1205 <main+0xb5>
lea    0xe3c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1235 <main+0xe5>
mov    -0x10(%rbp),%rdi
lea    0xe4b(%rip),%rsi
lea    -0x18(%rbp),%rdx
call   1050 <fscanf@plt>
movsd  -0x18(%rbp),%xmm0
lea    0xe3a(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <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   1050 <printf@plt>
lea    0xe9b(%rip),%rdi
lea    0xe9b(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     11c6 <main+0x66>
mov    %rax,%rbx
lea    0xe89(%rip),%rsi
movsd  0xe4c(%rip),%xmm0
mov    %rax,%rdi
call   1070 <fprintf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
jmp    11d2 <main+0x72>
lea    0xe95(%rip),%rdi
call   1030 <puts@plt>
lea    0xe53(%rip),%rdi
lea    0xe5d(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     121f <main+0xbf>
mov    %rax,%rbx
lea    0xe4b(%rip),%rsi
lea    0x8(%rsp),%rdx
mov    %rax,%rdi
call   1060 <fscanf@plt>
movsd  0x8(%rsp),%xmm0
lea    0xe35(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
jmp    122b <main+0xcb>
lea    0xe3c(%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.txt\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [28 x i8] c"\07 Failed to open the file.\0A\00"
@.str.4 = [8 x i8] c"%23.21f\00"
@.str.5 = [2 x i8] c"r\00"
@.str.6 = [4 x i8] c"%lf\00"
@.str.7 = [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 ([2 x i8], [2 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 %16
10: ; preds = %0
%11 = load i32*, i32** %2
%12 = load double, double* %3
%13 = call i32 @fprintf(i32* %11, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), double %12)
%14 = load i32*, i32** %2
%15 = call i32 @fclose(i32* %14)
br label %16
16: ; preds = %10, %8
%17 = call i32* @fopen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32* %17, i32** %2
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %21
19: ; preds = %16
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
br label %28
21: ; preds = %16
%22 = load i32*, i32** %2
%23 = call i32 @fscanf(i32* %22, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), double* %3)
%24 = load double, double* %3
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.7, i64 0, i64 0), double %24)
%26 = load i32*, i32** %2
%27 = call i32 @fclose(i32* %26)
br label %28
28: ; preds = %21, %19
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.txt\00"
@.str.2 = [2 x i8] c"w\00"
@.str.4 = [8 x i8] c"%23.21f\00"
@.str.5 = [2 x i8] c"r\00"
@.str.6 = [4 x i8] c"%lf\00"
@.str.7 = [31 x i8] c"The pi from the file %23.21f.\0A\00"
@str.8 = [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 ([2 x i8], [2 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.8, i64 0, i64 0))
br label %11
8: ; preds = %0
%9 = tail call i32 @fprintf(i32* %4, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), double 0x400921FB54442D18)
%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 ([2 x i8], [2 x i8]* @.str.5, 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.8, i64 0, i64 0))
br label %21
16: ; preds = %11
%17 = call i32 @fscanf(i32* %12, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), double* %1)
%18 = load double, double* %1
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.7, i64 0, i64 0), double %18)
%20 = call i32 @fclose(i32* %12)
br label %21
21: ; preds = %16, %14
ret i32 0
}