#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 /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, int *, int *, double *,
                          double *);
int /*<<< orphan*/ legendre_dreieck_alloc(int, double ***);
int /*<<< orphan*/ printf(char *);
int read_coefficients(const char *filename, int mindegree, int maxdegree,
                      double ***c_lm, double ***s_lm) {
  FILE *fh;
  int l;
  int m;
  int degree;
  int order;
  double c;
  double s;
  fh = fopen(filename, "r");
  legendre_dreieck_alloc(maxdegree, c_lm);
  legendre_dreieck_alloc(maxdegree, s_lm);
  for (l = mindegree; l <= maxdegree; l++) {
    fscanf(fh, "%d %d %lf %lf", &degree, &order, &c, &s);
    if (degree != l || order != 0)
      printf("Error: Wrong order of coefficients in input file\n");
    (*c_lm)[l][0] = c;
    for (m = 1; m <= l; m++) {
      fscanf(fh, "%d %d %lf %lf", &degree, &order, &c, &s);
      if (degree != l || order != m)
        printf("Error: Wrong order of coefficients in input file\n");
      (*c_lm)[l][m] = c;
      (*s_lm)[l][m] = s;
    }
  }
  fclose(fh);
  return 0;
}


x86 assembly (clang, -O0):
<read_coefficients>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe8b(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1060 <legendre_dreieck_alloc@plt>
mov    -0x10(%rbp),%edi
mov    -0x20(%rbp),%rsi
call   1060 <legendre_dreieck_alloc@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x10(%rbp),%eax
jg     12b4 <read_coefficients+0x164>
mov    -0x28(%rbp),%rdi
lea    0xe4f(%rip),%rsi
lea    -0x34(%rbp),%rdx
lea    -0x38(%rbp),%rcx
lea    -0x40(%rbp),%r8
lea    -0x48(%rbp),%r9
call   1050 <fscanf@plt>
mov    -0x34(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jne    11de <read_coefficients+0x8e>
cmpl   $0x0,-0x38(%rbp)
je     11ea <read_coefficients+0x9a>
lea    0xe2b(%rip),%rdi
call   1040 <printf@plt>
movsd  -0x40(%rbp),%xmm0
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movsd  %xmm0,(%rax)
movl   $0x1,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jg     12a1 <read_coefficients+0x151>
mov    -0x28(%rbp),%rdi
lea    0xde2(%rip),%rsi
lea    -0x34(%rbp),%rdx
lea    -0x38(%rbp),%rcx
lea    -0x40(%rbp),%r8
lea    -0x48(%rbp),%r9
call   1050 <fscanf@plt>
mov    -0x34(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jne    124d <read_coefficients+0xfd>
mov    -0x38(%rbp),%eax
cmp    -0x30(%rbp),%eax
je     1259 <read_coefficients+0x109>
lea    0xdbc(%rip),%rdi
call   1040 <printf@plt>
movsd  -0x40(%rbp),%xmm0
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x30(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
movsd  -0x48(%rbp),%xmm0
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x30(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1209 <read_coefficients+0xb9>
jmp    12a6 <read_coefficients+0x156>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    119c <read_coefficients+0x4c>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_coefficients>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r8,%r14
mov    %rcx,%r12
mov    %edx,%r15d
mov    %esi,%ebp
lea    0xe90(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
mov    %r15d,%edi
mov    %r12,%rsi
call   1060 <legendre_dreieck_alloc@plt>
mov    %r15d,%edi
mov    %r14,%rsi
call   1060 <legendre_dreieck_alloc@plt>
mov    %r15d,0x14(%rsp)
cmp    %r15d,%ebp
jle    11b1 <read_coefficients+0x61>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
movslq %ebp,%r15
addl   $0x1,0x14(%rsp)
add    $0x1,%ebp
jmp    11ce <read_coefficients+0x7e>
xchg   %ax,%ax
add    $0x1,%r15
add    $0x1,%ebp
cmp    %r15d,0x14(%rsp)
je     1198 <read_coefficients+0x48>
mov    %rbx,%rdi
lea    0xe2a(%rip),%rsi
lea    0x10(%rsp),%rdx
lea    0xc(%rsp),%rcx
lea    0x18(%rsp),%r8
lea    0x20(%rsp),%r9
call   1050 <fscanf@plt>
cmp    %r15d,0x10(%rsp)
jne    11ff <read_coefficients+0xaf>
cmpl   $0x0,0xc(%rsp)
je     120b <read_coefficients+0xbb>
lea    0xe0a(%rip),%rdi
call   1030 <puts@plt>
mov    %ebp,%ebp
movsd  0x18(%rsp),%xmm0
mov    (%r12),%rax
mov    (%rax,%r15,8),%rax
movsd  %xmm0,(%rax)
test   %r15,%r15
jle    11c0 <read_coefficients+0x70>
mov    $0x1,%r13d
jmp    1270 <read_coefficients+0x120>
nopl   0x0(%rax)
lea    0xdd9(%rip),%rdi
call   1030 <puts@plt>
movsd  0x18(%rsp),%xmm0
mov    (%r12),%rax
mov    (%rax,%r15,8),%rax
movsd  %xmm0,(%rax,%r13,8)
movsd  0x20(%rsp),%xmm0
mov    (%r14),%rax
mov    (%rax,%r15,8),%rax
movsd  %xmm0,(%rax,%r13,8)
add    $0x1,%r13
cmp    %r13,%rbp
je     11c0 <read_coefficients+0x70>
mov    %rbx,%rdi
lea    0xd88(%rip),%rsi
lea    0x10(%rsp),%rdx
lea    0xc(%rsp),%rcx
lea    0x18(%rsp),%r8
lea    0x20(%rsp),%r9
call   1050 <fscanf@plt>
cmp    %r15d,0x10(%rsp)
jne    1230 <read_coefficients+0xe0>
mov    0xc(%rsp),%eax
cmp    %rax,%r13
je     123c <read_coefficients+0xec>
jmp    1230 <read_coefficients+0xe0>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [14 x i8] c"%d %d %lf %lf\00"
@.str.2 = [50 x i8] c"Error: Wrong order of coefficients in input file\0A\00"
define i32 @read_coefficients(i8* %0, i32 %1, i32 %2, double*** %3, double*** %4) {
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca double***
%10 = alloca double***
%11 = alloca i32*
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca double
%17 = alloca double
store i8* %0, i8** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store double*** %3, double**** %9
store double*** %4, double**** %10
%18 = load i8*, i8** %6
%19 = call i32* @fopen(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %19, i32** %11
%20 = load i32, i32* %8
%21 = load double***, double**** %9
%22 = call i32 @legendre_dreieck_alloc(i32 %20, double*** %21)
%23 = load i32, i32* %8
%24 = load double***, double**** %10
%25 = call i32 @legendre_dreieck_alloc(i32 %23, double*** %24)
%26 = load i32, i32* %7
store i32 %26, i32* %12
br label %27
27: ; preds = %92, %5
%28 = load i32, i32* %12
%29 = load i32, i32* %8
%30 = icmp sle i32 %28, %29
br i1 %30, label %31, label %95
31: ; preds = %27
%32 = load i32*, i32** %11
%33 = call i32 @fscanf(i32* %32, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32* %14, i32* %15, double* %16, double* %17)
%34 = load i32, i32* %14
%35 = load i32, i32* %12
%36 = icmp ne i32 %34, %35
br i1 %36, label %40, label %37
37: ; preds = %31
%38 = load i32, i32* %15
%39 = icmp ne i32 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %37, %31
%41 = call i32 @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.2, i64 0, i64 0))
br label %42
42: ; preds = %40, %37
%43 = load double, double* %16
%44 = load double***, double**** %9
%45 = load double**, double*** %44
%46 = load i32, i32* %12
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds double*, double** %45, i64 %47
%49 = load double*, double** %48
%50 = getelementptr inbounds double, double* %49, i64 0
store double %43, double* %50
store i32 1, i32* %13
br label %51
51: ; preds = %88, %42
%52 = load i32, i32* %13
%53 = load i32, i32* %12
%54 = icmp sle i32 %52, %53
br i1 %54, label %55, label %91
55: ; preds = %51
%56 = load i32*, i32** %11
%57 = call i32 @fscanf(i32* %56, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32* %14, i32* %15, double* %16, double* %17)
%58 = load i32, i32* %14
%59 = load i32, i32* %12
%60 = icmp ne i32 %58, %59
br i1 %60, label %65, label %61
61: ; preds = %55
%62 = load i32, i32* %15
%63 = load i32, i32* %13
%64 = icmp ne i32 %62, %63
br i1 %64, label %65, label %67
65: ; preds = %61, %55
%66 = call i32 @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.2, i64 0, i64 0))
br label %67
67: ; preds = %65, %61
%68 = load double, double* %16
%69 = load double***, double**** %9
%70 = load double**, double*** %69
%71 = load i32, i32* %12
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds double*, double** %70, i64 %72
%74 = load double*, double** %73
%75 = load i32, i32* %13
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds double, double* %74, i64 %76
store double %68, double* %77
%78 = load double, double* %17
%79 = load double***, double**** %10
%80 = load double**, double*** %79
%81 = load i32, i32* %12
%82 = sext i32 %81 to i64
%83 = getelementptr inbounds double*, double** %80, i64 %82
%84 = load double*, double** %83
%85 = load i32, i32* %13
%86 = sext i32 %85 to i64
%87 = getelementptr inbounds double, double* %84, i64 %86
store double %78, double* %87
br label %88
88: ; preds = %67
%89 = load i32, i32* %13
%90 = add nsw i32 %89, 1
store i32 %90, i32* %13
br label %51
91: ; preds = %51
br label %92
92: ; preds = %91
%93 = load i32, i32* %12
%94 = add nsw i32 %93, 1
store i32 %94, i32* %12
br label %27
95: ; preds = %27
%96 = load i32*, i32** %11
%97 = call i32 @fclose(i32* %96)
ret i32 0
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [14 x i8] c"%d %d %lf %lf\00"
@str.3 = [49 x i8] c"Error: Wrong order of coefficients in input file\00"
define i32 @read_coefficients(i8* nocapture %0, i32 %1, i32 %2, double*** %3, double*** %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca double
%9 = alloca double
%10 = bitcast i32* %6 to i8*
%11 = bitcast i32* %7 to i8*
%12 = bitcast double* %8 to i8*
%13 = bitcast double* %9 to i8*
%14 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%15 = tail call i32 @legendre_dreieck_alloc(i32 %2, double*** %3)
%16 = tail call i32 @legendre_dreieck_alloc(i32 %2, double*** %4)
%17 = icmp sgt i32 %1, %2
br i1 %17, label %70, label %18
18: ; preds = %5
%19 = sext i32 %1 to i64
%20 = add i32 %2, 1
br label %21
21: ; preds = %18, %66
%22 = phi i64 [ %19, %18 ], [ %67, %66 ]
%23 = phi i32 [ %1, %18 ], [ %24, %66 ]
%24 = add i32 %23, 1
%25 = call i32 @fscanf(i32* %14, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32* %6, i32* %7, double* %8, double* %9)
%26 = load i32, i32* %6
%27 = trunc i64 %22 to i32
%28 = icmp ne i32 %26, %27
%29 = load i32, i32* %7
%30 = icmp ne i32 %29, 0
%31 = select i1 %28, i1 true, i1 %30
br i1 %31, label %32, label %34
32: ; preds = %21
%33 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @str.3, i64 0, i64 0))
br label %34
34: ; preds = %21, %32
%35 = load double, double* %8
%36 = load double**, double*** %3
%37 = getelementptr inbounds double*, double** %36, i64 %22
%38 = load double*, double** %37
store double %35, double* %38
%39 = icmp slt i64 %22, 1
br i1 %39, label %66, label %40
40: ; preds = %34
%41 = zext i32 %24 to i64
br label %42
42: ; preds = %40, %53
%43 = phi i64 [ 1, %40 ], [ %64, %53 ]
%44 = call i32 @fscanf(i32* %14, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32* %6, i32* %7, double* %8, double* %9)
%45 = load i32, i32* %6
%46 = icmp eq i32 %45, %27
%47 = load i32, i32* %7
%48 = zext i32 %47 to i64
%49 = icmp eq i64 %43, %48
%50 = select i1 %46, i1 %49, i1 false
br i1 %50, label %53, label %51
51: ; preds = %42
%52 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @str.3, i64 0, i64 0))
br label %53
53: ; preds = %42, %51
%54 = load double, double* %8
%55 = load double**, double*** %3
%56 = getelementptr inbounds double*, double** %55, i64 %22
%57 = load double*, double** %56
%58 = getelementptr inbounds double, double* %57, i64 %43
store double %54, double* %58
%59 = load double, double* %9
%60 = load double**, double*** %4
%61 = getelementptr inbounds double*, double** %60, i64 %22
%62 = load double*, double** %61
%63 = getelementptr inbounds double, double* %62, i64 %43
store double %59, double* %63
%64 = add nuw nsw i64 %43, 1
%65 = icmp eq i64 %64, %41
br i1 %65, label %66, label %42
66: ; preds = %53, %34
%67 = add nsw i64 %22, 1
%68 = trunc i64 %67 to i32
%69 = icmp eq i32 %20, %68
br i1 %69, label %70, label %21
70: ; preds = %66, %5
%71 = call i32 @fclose(i32* %14)
ret i32 0
}