#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*/ Error(char *, char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
void *malloc(int);
double *realloc(double *, int);
int sscanf(char *, char *, ...);
int ReadMesh(char *fn, double **x, double **y) {
  FILE *f;
  char c, *line;
  int k, Nm = 0, Nalloc = 100;
  (*x) = malloc((Nalloc + 1) * sizeof(double));
  (*y) = malloc((Nalloc + 1) * sizeof(double));
  if ((f = fopen(fn, "r")) == NULL)
    Error("Cannot open %s for reading\n", fn);
  line = malloc(256 * sizeof(char));
  fgets(line, 256 - 1, f);
  while (feof(f) == 0) {
    k = sscanf(line, " %c", &c);
    if ((k != -1) && (c != '#')) {
      k = sscanf(line, " %le %le", (*x) + Nm, (*y) + Nm);
      if (k != -1) {
        Nm++;
        if (Nalloc == Nm) {
          Nalloc += 100;
          (*x) = realloc((*x), (Nalloc + 1) * sizeof(double));
          (*y) = realloc((*y), (Nalloc + 1) * sizeof(double));
        }
      }
    }
    fgets(line, 256 - 1, f);
  }
  free(line);
  (*x) = realloc((*x), (Nm + 1) * sizeof(double));
  (*y) = realloc((*y), (Nm + 1) * sizeof(double));
  fclose(f);
  return Nm - 1;
}


x86 assembly (clang, -O0):
<ReadMesh>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x38(%rbp)
movl   $0x64,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rdi
lea    0xe09(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    121a <ReadMesh+0x8a>
mov    -0x8(%rbp),%rsi
lea    0xded(%rip),%rdi
call   1050 <Error@plt>
mov    $0x100,%edi
call   1080 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0xff,%esi
call   1060 <fgets@plt>
mov    -0x20(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%rax
jne    1347 <ReadMesh+0x1b7>
mov    -0x30(%rbp),%rdi
lea    0xdc6(%rip),%rsi
lea    -0x21(%rbp),%rdx
mov    $0x0,%al
call   1090 <sscanf@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0xffffffff,-0x34(%rbp)
je     1330 <ReadMesh+0x1a0>
movsbl -0x21(%rbp),%eax
cmp    $0x23,%eax
je     1330 <ReadMesh+0x1a0>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
movslq -0x38(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdx
mov    -0x18(%rbp),%rax
mov    (%rax),%rcx
movslq -0x38(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rcx
lea    0xd76(%rip),%rsi
mov    $0x0,%al
call   1090 <sscanf@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0xffffffff,-0x34(%rbp)
je     132b <ReadMesh+0x19b>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x38(%rbp),%eax
jne    1326 <ReadMesh+0x196>
mov    -0x3c(%rbp),%eax
add    $0x64,%eax
mov    %eax,-0x3c(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%esi
call   10a0 <realloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%esi
call   10a0 <realloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
jmp    132b <ReadMesh+0x19b>
jmp    1330 <ReadMesh+0x1a0>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0xff,%esi
call   1060 <fgets@plt>
jmp    123a <ReadMesh+0xaa>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x38(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%esi
call   10a0 <realloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    -0x38(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%esi
call   10a0 <realloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x38(%rbp),%eax
sub    $0x1,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ReadMesh>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%rbp
mov    %rsi,%r15
mov    %rdi,%rbx
mov    $0x328,%edi
call   1080 <malloc@plt>
mov    %rax,(%r15)
mov    $0x328,%edi
call   1080 <malloc@plt>
mov    %rax,0x0(%rbp)
lea    0xe3a(%rip),%rsi
mov    %rbx,%rdi
call   10b0 <fopen@plt>
mov    %rax,%r12
test   %rax,%rax
jne    11e5 <ReadMesh+0x55>
lea    0xe25(%rip),%rdi
mov    %rbx,%rsi
call   1050 <Error@plt>
mov    $0x100,%edi
call   1080 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0xff,%esi
mov    %r12,%rdx
call   1060 <fgets@plt>
mov    %r12,%rdi
call   1070 <feof@plt>
xor    %r13d,%r13d
test   %rax,%rax
je     125c <ReadMesh+0xcc>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    (%r15),%rdi
lea    0x8(,%r13,8),%ebx
mov    %ebx,%esi
call   10a0 <realloc@plt>
mov    %rax,(%r15)
mov    0x0(%rbp),%rdi
mov    %ebx,%esi
call   10a0 <realloc@plt>
mov    %rax,0x0(%rbp)
mov    %r12,%rdi
call   1040 <fclose@plt>
add    $0xffffffff,%r13d
mov    %r13d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x64,%r14d
xor    %r13d,%r13d
jmp    128d <ReadMesh+0xfd>
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0xff,%esi
mov    %r12,%rdx
call   1060 <fgets@plt>
mov    %r12,%rdi
call   1070 <feof@plt>
test   %rax,%rax
jne    1212 <ReadMesh+0x82>
mov    %rbx,%rdi
lea    0xd87(%rip),%rsi
lea    0x3(%rsp),%rdx
xor    %eax,%eax
call   1090 <sscanf@plt>
cmp    $0xffffffff,%eax
je     1270 <ReadMesh+0xe0>
cmpb   $0x23,0x3(%rsp)
je     1270 <ReadMesh+0xe0>
movslq %r13d,%rcx
shl    $0x3,%rcx
mov    (%r15),%rdx
add    %rcx,%rdx
add    0x0(%rbp),%rcx
mov    %rbx,%rdi
lea    0xd58(%rip),%rsi
xor    %eax,%eax
call   1090 <sscanf@plt>
cmp    $0xffffffff,%eax
je     1270 <ReadMesh+0xe0>
add    $0x1,%r13d
cmp    %r13d,%r14d
jne    1270 <ReadMesh+0xe0>
lea    0x64(%r14),%eax
mov    %eax,0x4(%rsp)
mov    (%r15),%rdi
mov    %rbp,%r13
lea    0x328(,%r14,8),%ebp
mov    %ebp,%esi
call   10a0 <realloc@plt>
mov    %rax,(%r15)
mov    0x0(%r13),%rdi
mov    %ebp,%esi
mov    %r13,%rbp
call   10a0 <realloc@plt>
mov    %rax,0x0(%r13)
mov    %r14d,%r13d
mov    0x4(%rsp),%eax
mov    %eax,%r14d
jmp    1270 <ReadMesh+0xe0>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [28 x i8] c"Cannot open %s for reading\0A\00"
@.str.2 = [4 x i8] c" %c\00"
@.str.3 = [9 x i8] c" %le %le\00"
define i32 @ReadMesh(i8* %0, double** %1, double** %2) {
%4 = alloca i8*
%5 = alloca double**
%6 = alloca double**
%7 = alloca i32*
%8 = alloca i8
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i8* %0, i8** %4
store double** %1, double*** %5
store double** %2, double*** %6
store i32 0, i32* %11
store i32 100, i32* %12
%13 = load i32, i32* %12
%14 = add nsw i32 %13, 1
%15 = sext i32 %14 to i64
%16 = mul i64 %15, 8
%17 = trunc i64 %16 to i32
%18 = call i8* @malloc(i32 %17)
%19 = bitcast i8* %18 to double*
%20 = load double**, double*** %5
store double* %19, double** %20
%21 = load i32, i32* %12
%22 = add nsw i32 %21, 1
%23 = sext i32 %22 to i64
%24 = mul i64 %23, 8
%25 = trunc i64 %24 to i32
%26 = call i8* @malloc(i32 %25)
%27 = bitcast i8* %26 to double*
%28 = load double**, double*** %6
store double* %27, double** %28
%29 = load i8*, i8** %4
%30 = call i32* @fopen(i8* %29, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %30, i32** %7
%31 = icmp eq i32* %30, null
br i1 %31, label %32, label %35
32: ; preds = %3
%33 = load i8*, i8** %4
%34 = call i32 @Error(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %33)
br label %35
35: ; preds = %32, %3
%36 = call i8* @malloc(i32 256)
store i8* %36, i8** %9
%37 = load i8*, i8** %9
%38 = load i32*, i32** %7
%39 = call i32 @fgets(i8* %37, i32 255, i32* %38)
br label %40
40: ; preds = %97, %35
%41 = load i32*, i32** %7
%42 = call i64 @feof(i32* %41)
%43 = icmp eq i64 %42, 0
br i1 %43, label %44, label %101
44: ; preds = %40
%45 = load i8*, i8** %9
%46 = call i32 (i8*, i8*, ...) @sscanf(i8* %45, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %8)
store i32 %46, i32* %10
%47 = load i32, i32* %10
%48 = icmp ne i32 %47, -1
br i1 %48, label %49, label %97
49: ; preds = %44
%50 = load i8, i8* %8
%51 = sext i8 %50 to i32
%52 = icmp ne i32 %51, 35
br i1 %52, label %53, label %97
53: ; preds = %49
%54 = load i8*, i8** %9
%55 = load double**, double*** %5
%56 = load double*, double** %55
%57 = load i32, i32* %11
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds double, double* %56, i64 %58
%60 = load double**, double*** %6
%61 = load double*, double** %60
%62 = load i32, i32* %11
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds double, double* %61, i64 %63
%65 = call i32 (i8*, i8*, ...) @sscanf(i8* %54, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), double* %59, double* %64)
store i32 %65, i32* %10
%66 = load i32, i32* %10
%67 = icmp ne i32 %66, -1
br i1 %67, label %68, label %96
68: ; preds = %53
%69 = load i32, i32* %11
%70 = add nsw i32 %69, 1
store i32 %70, i32* %11
%71 = load i32, i32* %12
%72 = load i32, i32* %11
%73 = icmp eq i32 %71, %72
br i1 %73, label %74, label %95
74: ; preds = %68
%75 = load i32, i32* %12
%76 = add nsw i32 %75, 100
store i32 %76, i32* %12
%77 = load double**, double*** %5
%78 = load double*, double** %77
%79 = load i32, i32* %12
%80 = add nsw i32 %79, 1
%81 = sext i32 %80 to i64
%82 = mul i64 %81, 8
%83 = trunc i64 %82 to i32
%84 = call double* @realloc(double* %78, i32 %83)
%85 = load double**, double*** %5
store double* %84, double** %85
%86 = load double**, double*** %6
%87 = load double*, double** %86
%88 = load i32, i32* %12
%89 = add nsw i32 %88, 1
%90 = sext i32 %89 to i64
%91 = mul i64 %90, 8
%92 = trunc i64 %91 to i32
%93 = call double* @realloc(double* %87, i32 %92)
%94 = load double**, double*** %6
store double* %93, double** %94
br label %95
95: ; preds = %74, %68
br label %96
96: ; preds = %95, %53
br label %97
97: ; preds = %96, %49, %44
%98 = load i8*, i8** %9
%99 = load i32*, i32** %7
%100 = call i32 @fgets(i8* %98, i32 255, i32* %99)
br label %40
101: ; preds = %40
%102 = load i8*, i8** %9
%103 = call i32 @free(i8* %102)
%104 = load double**, double*** %5
%105 = load double*, double** %104
%106 = load i32, i32* %11
%107 = add nsw i32 %106, 1
%108 = sext i32 %107 to i64
%109 = mul i64 %108, 8
%110 = trunc i64 %109 to i32
%111 = call double* @realloc(double* %105, i32 %110)
%112 = load double**, double*** %5
store double* %111, double** %112
%113 = load double**, double*** %6
%114 = load double*, double** %113
%115 = load i32, i32* %11
%116 = add nsw i32 %115, 1
%117 = sext i32 %116 to i64
%118 = mul i64 %117, 8
%119 = trunc i64 %118 to i32
%120 = call double* @realloc(double* %114, i32 %119)
%121 = load double**, double*** %6
store double* %120, double** %121
%122 = load i32*, i32** %7
%123 = call i32 @fclose(i32* %122)
%124 = load i32, i32* %11
%125 = sub nsw i32 %124, 1
ret i32 %125
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [28 x i8] c"Cannot open %s for reading\0A\00"
@.str.2 = [4 x i8] c" %c\00"
@.str.3 = [9 x i8] c" %le %le\00"
define i32 @ReadMesh(i8* %0, double** nocapture %1, double** nocapture %2) {
%4 = alloca i8
%5 = tail call dereferenceable_or_null(808) i8* @malloc(i32 808)
%6 = bitcast double** %1 to i8**
store i8* %5, i8** %6
%7 = tail call dereferenceable_or_null(808) i8* @malloc(i32 808)
%8 = bitcast double** %2 to i8**
store i8* %7, i8** %8
%9 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %3
%12 = tail call i32 @Error(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %13
13: ; preds = %11, %3
%14 = tail call dereferenceable_or_null(256) i8* @malloc(i32 256)
%15 = tail call i32 @fgets(i8* %14, i32 255, i32* %9)
%16 = call i64 @feof(i32* %9)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %51
18: ; preds = %13, %45
%19 = phi i32 [ %47, %45 ], [ 100, %13 ]
%20 = phi i32 [ %46, %45 ], [ 0, %13 ]
%21 = call i32 (i8*, i8*, ...) @sscanf(i8* %14, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %4)
%22 = icmp ne i32 %21, -1
%23 = load i8, i8* %4
%24 = icmp ne i8 %23, 35
%25 = select i1 %22, i1 %24, i1 false
br i1 %25, label %26, label %45
26: ; preds = %18
%27 = load double*, double** %1
%28 = sext i32 %20 to i64
%29 = getelementptr inbounds double, double* %27, i64 %28
%30 = load double*, double** %2
%31 = getelementptr inbounds double, double* %30, i64 %28
%32 = call i32 (i8*, i8*, ...) @sscanf(i8* %14, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), double* %29, double* %31)
%33 = icmp eq i32 %32, -1
br i1 %33, label %45, label %34
34: ; preds = %26
%35 = add nsw i32 %20, 1
%36 = icmp eq i32 %19, %35
br i1 %36, label %37, label %45
37: ; preds = %34
%38 = add nsw i32 %19, 100
%39 = load double*, double** %1
%40 = shl i32 %19, 3
%41 = add i32 %40, 808
%42 = call double* @realloc(double* %39, i32 %41)
store double* %42, double** %1
%43 = load double*, double** %2
%44 = call double* @realloc(double* %43, i32 %41)
store double* %44, double** %2
br label %45
45: ; preds = %26, %37, %34, %18
%46 = phi i32 [ %19, %37 ], [ %35, %34 ], [ %20, %26 ], [ %20, %18 ]
%47 = phi i32 [ %38, %37 ], [ %19, %34 ], [ %19, %26 ], [ %19, %18 ]
%48 = call i32 @fgets(i8* %14, i32 255, i32* %9)
%49 = call i64 @feof(i32* %9)
%50 = icmp eq i64 %49, 0
br i1 %50, label %18, label %51
51: ; preds = %45, %13
%52 = phi i32 [ 0, %13 ], [ %46, %45 ]
%53 = call i32 @free(i8* %14)
%54 = load double*, double** %1
%55 = shl i32 %52, 3
%56 = add i32 %55, 8
%57 = call double* @realloc(double* %54, i32 %56)
store double* %57, double** %1
%58 = load double*, double** %2
%59 = call double* @realloc(double* %58, i32 %56)
store double* %59, double** %2
%60 = call i32 @fclose(i32* %9)
%61 = add nsw i32 %52, -1
ret i32 %61
}