#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 */

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int read(int, double *, int);
int main() {
  int fd;
  int i, j;
  double d;
  if (sizeof(double) != 8) {
    printf("Data type DOUBLE is not 8-byte. Please check!\n");
    return -1;
  }
  fd = open("calculus", O_RDONLY);
  if (fd < 0) {
    printf("Could not open file 'calculus'\n");
    return -2;
  }
  for (j = 0; j < 2; j++) {
    switch (j) {
    case 0:
      printf("double GG[241*241]={\n");
      break;
    case 1:
      printf("double GGS[241*241]={\n");
      break;
    }
    for (i = 0; i < 241 * 241; i++) {
      if (read(fd, &d, 8) != 8) {
        printf("READ ERROR\n");
        return -3;
      }
      if (i == 241 * 241 - 1) {
        printf("%30.25f};\n", d);
      } else {
        printf("%30.25f,\n", d);
      }
    }
    return 0;
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2ea2(%rip),%rax
mov    (%rax),%esi
lea    0xeb1(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    117b <main+0x4b>
lea    0xea1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    126b <main+0x13b>
movl   $0x0,-0x10(%rbp)
cmpl   $0x2,-0x10(%rbp)
jge    126b <main+0x13b>
mov    -0x10(%rbp),%eax
mov    %eax,-0x1c(%rbp)
test   %eax,%eax
je     11b0 <main+0x80>
jmp    119f <main+0x6f>
mov    -0x1c(%rbp),%eax
sub    $0x1,%eax
je     11c3 <main+0x93>
jmp    11d1 <main+0xa1>
lea    0xe72(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11d1 <main+0xa1>
lea    0xe75(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0xc(%rbp)
cmpl   $0xe2e1,-0xc(%rbp)
jge    1264 <main+0x134>
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x8,%edx
call   1040 <read@plt>
cmp    $0x8,%eax
je     1219 <main+0xe9>
lea    0xe50(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xfffffffd,-0x4(%rbp)
jmp    126b <main+0x13b>
cmpl   $0xe2e0,-0xc(%rbp)
jne    123e <main+0x10e>
movsd  -0x18(%rbp),%xmm0
lea    0xe30(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
jmp    1251 <main+0x121>
movsd  -0x18(%rbp),%xmm0
lea    0xe23(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
jmp    1256 <main+0x126>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11d8 <main+0xa8>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    0x2e9a(%rip),%rax
mov    (%rax),%esi
lea    0xea9(%rip),%rdi
call   1060 <open@plt>
test   %eax,%eax
js     11db <main+0x9b>
mov    %eax,%ebx
lea    0xeb5(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0x8,%edx
call   1050 <read@plt>
cmp    $0x8,%eax
jne    11c8 <main+0x88>
mov    $0xe2e1,%ebp
lea    0xe86(%rip),%r14
mov    %rsp,%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsd  (%rsp),%xmm0
add    $0xffffffff,%ebp
je     11ee <main+0xae>
mov    %r14,%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    %ebx,%edi
mov    %r15,%rsi
mov    $0x8,%edx
call   1050 <read@plt>
cmp    $0x8,%eax
je     11a0 <main+0x60>
lea    0xe64(%rip),%rdi
call   1030 <puts@plt>
mov    $0xfffffffd,%eax
jmp    11fe <main+0xbe>
lea    0xe5c(%rip),%rdi
call   1030 <puts@plt>
mov    $0xfffffffe,%eax
jmp    11fe <main+0xbe>
lea    0xe14(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"calculus\00"
@O_RDONLY = global i32 0
@.str.1 = [32 x i8] c"Could not open file 'calculus'\0A\00"
@.str.2 = [22 x i8] c"double GG[241*241]={\0A\00"
@.str.3 = [23 x i8] c"double GGS[241*241]={\0A\00"
@.str.4 = [12 x i8] c"READ ERROR\0A\00"
@.str.5 = [11 x i8] c"%30.25f};\0A\00"
@.str.6 = [10 x i8] c"%30.25f,\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca double
store i32 0, i32* %1
%6 = load i32, i32* @O_RDONLY
%7 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %6)
store i32 %7, i32* %2
%8 = load i32, i32* %2
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %0
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
store i32 -2, i32* %1
br label %49
12: ; preds = %0
store i32 0, i32* %4
br label %13
13: ; preds = %46, %12
%14 = load i32, i32* %4
%15 = icmp slt i32 %14, 2
br i1 %15, label %16, label %49
16: ; preds = %13
%17 = load i32, i32* %4
switch i32 %17, label %22 [
i32 0, label %18
i32 1, label %20
]
18: ; preds = %16
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
br label %22
20: ; preds = %16
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
br label %22
22: ; preds = %16, %20, %18
store i32 0, i32* %3
br label %23
23: ; preds = %42, %22
%24 = load i32, i32* %3
%25 = icmp slt i32 %24, 58081
br i1 %25, label %26, label %45
26: ; preds = %23
%27 = load i32, i32* %2
%28 = call i32 @read(i32 %27, double* %5, i32 8)
%29 = icmp ne i32 %28, 8
br i1 %29, label %30, label %32
30: ; preds = %26
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
store i32 -3, i32* %1
br label %49
32: ; preds = %26
%33 = load i32, i32* %3
%34 = icmp eq i32 %33, 58080
br i1 %34, label %35, label %38
35: ; preds = %32
%36 = load double, double* %5
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), double %36)
br label %41
38: ; preds = %32
%39 = load double, double* %5
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), double %39)
br label %41
41: ; preds = %38, %35
br label %42
42: ; preds = %41
%43 = load i32, i32* %3
%44 = add nsw i32 %43, 1
store i32 %44, i32* %3
br label %23
45: ; preds = %23
store i32 0, i32* %1
br label %49
46: ; No predecessors!
%47 = load i32, i32* %4
%48 = add nsw i32 %47, 1
store i32 %48, i32* %4
br label %13
49: ; preds = %10, %30, %45, %13
%50 = load i32, i32* %1
ret i32 %50
}

LLVM IR (-O2):
@.str = [9 x i8] c"calculus\00"
@O_RDONLY = global i32 0
@.str.5 = [11 x i8] c"%30.25f};\0A\00"
@.str.6 = [10 x i8] c"%30.25f,\0A\00"
@str = [21 x i8] c"double GG[241*241]={\00"
@str.7 = [11 x i8] c"READ ERROR\00"
@str.8 = [31 x i8] c"Could not open file 'calculus'\00"
define i32 @main() {
%1 = alloca double
%2 = bitcast double* %1 to i8*
%3 = load i32, i32* @O_RDONLY
%4 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.8, i64 0, i64 0))
br label %25
8: ; preds = %0
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
%10 = call i32 @read(i32 %4, double* %1, i32 8)
%11 = icmp eq i32 %10, 8
br i1 %11, label %14, label %12
12: ; preds = %18, %8
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.7, i64 0, i64 0))
br label %25
14: ; preds = %8, %18
%15 = phi i32 [ %20, %18 ], [ 0, %8 ]
%16 = icmp eq i32 %15, 58080
%17 = load double, double* %1
br i1 %16, label %23, label %18
18: ; preds = %14
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), double %17)
%20 = add nuw nsw i32 %15, 1
%21 = call i32 @read(i32 %4, double* %1, i32 8)
%22 = icmp eq i32 %21, 8
br i1 %22, label %14, label %12
23: ; preds = %14
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), double %17)
br label %25
25: ; preds = %23, %12, %6
%26 = phi i32 [ -2, %6 ], [ -3, %12 ], [ 0, %23 ]
ret i32 %26
}