#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 */
float *del_array(float *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ gets(char *);
int n_lines(int /*<<< orphan*/ *, char);
float *new_array(int, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int sscanf(char *, char *, char *, float *);
int /*<<< orphan*/ stderr;
float *read_poly(char *polyname, int *ncoeff) {
  float *a = NULL;
  float *aptr;
  char line[1000];
  char junk[1000];
  FILE *ifp = NULL;
  while (!(ifp = fopen(polyname, "r"))) {
    fprintf(stderr, "ERROR: read_poly.  Cannot open %s.\n", polyname);
    printf("Enter filename again:  ");
    gets(polyname);
  }
  if ((*ncoeff = n_lines(ifp, '#')) <= 0) {
    fprintf(stderr, "ERROR: read_poly.  No data lines in input file\n");
    return NULL;
  }
  if (!(a = new_array(*ncoeff, 1))) {
    fprintf(stderr, "ERROR: read_poly.\n");
    return NULL;
  }
  rewind(ifp);
  aptr = a;
  while (fgets(line, 1000, ifp) != NULL) {
    if (line[0] != '#') {
      if (sscanf(line, "%s %f", junk, aptr) != 2) {
        fprintf(stderr, "ERROR: read poly.  Bad input format in %s.\n",
                polyname);
        return del_array(a);
      } else {
        aptr++;
      }
    }
  }
  if (ifp)
    fclose(ifp);
  return a;
}


x86 assembly (clang, -O0):
<read_poly>:
push   %rbp
mov    %rsp,%rbp
sub    $0x810,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x808(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe1f(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x808(%rbp)
cmp    $0x0,%rax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1203 <read_poly+0x53>
jmp    1238 <read_poly+0x88>
mov    0x2dd6(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xdeb(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
lea    0xe01(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   10b0 <gets@plt>
jmp    11d6 <read_poly+0x26>
mov    -0x808(%rbp),%rdi
mov    $0x23,%esi
call   1070 <n_lines@plt>
mov    -0x18(%rbp),%rcx
mov    %eax,(%rcx)
cmp    $0x0,%eax
jg     127c <read_poly+0xcc>
mov    0x2d81(%rip),%rax
mov    (%rax),%edi
lea    0xdd6(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1390 <read_poly+0x1e0>
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
mov    $0x1,%esi
call   1080 <new_array@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    12be <read_poly+0x10e>
mov    0x2d3f(%rip),%rax
mov    (%rax),%edi
lea    0xdc4(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1390 <read_poly+0x1e0>
mov    -0x808(%rbp),%rdi
call   1050 <rewind@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
lea    -0x410(%rbp),%rdi
mov    -0x808(%rbp),%rdx
mov    $0x3e8,%esi
call   1090 <fgets@plt>
cmp    $0x0,%rax
je     136e <read_poly+0x1be>
movsbl -0x410(%rbp),%eax
cmp    $0x23,%eax
je     1369 <read_poly+0x1b9>
lea    -0x410(%rbp),%rdi
lea    -0x800(%rbp),%rdx
mov    -0x28(%rbp),%rcx
lea    0xd64(%rip),%rsi
call   10c0 <sscanf@plt>
cmp    $0x2,%eax
je     1358 <read_poly+0x1a8>
mov    0x2cae(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xd48(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1060 <del_array@plt>
mov    %rax,-0x8(%rbp)
jmp    1390 <read_poly+0x1e0>
mov    -0x28(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x28(%rbp)
jmp    1369 <read_poly+0x1b9>
jmp    12d2 <read_poly+0x122>
cmpq   $0x0,-0x808(%rbp)
je     1388 <read_poly+0x1d8>
mov    -0x808(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x810,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_poly>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x7e8,%rsp
mov    %rsi,%rbp
mov    %rdi,%r15
lea    0xe32(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1238 <read_poly+0x88>
mov    %rbp,0x8(%rsp)
mov    0x2df9(%rip),%r14
lea    0xe14(%rip),%r12
lea    0xe31(%rip),%r13
lea    0xe04(%rip),%rbp
nopl   0x0(%rax)
mov    (%r14),%edi
mov    %r12,%rsi
mov    %r15,%rdx
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    %r13,%rdi
call   1040 <printf@plt>
mov    %r15,%rdi
call   10b0 <gets@plt>
mov    %r15,%rdi
mov    %rbp,%rsi
call   10d0 <fopen@plt>
test   %rax,%rax
je     1200 <read_poly+0x50>
mov    %rax,%rbx
mov    0x8(%rsp),%rbp
mov    %rbx,%rdi
mov    $0x23,%esi
call   1070 <n_lines@plt>
mov    %eax,0x0(%rbp)
test   %eax,%eax
jle    12dc <read_poly+0x12c>
mov    %eax,%edi
mov    $0x1,%esi
call   1080 <new_array@plt>
test   %rax,%rax
je     12f8 <read_poly+0x148>
mov    %rax,%r13
mov    %rbx,%rdi
call   1050 <rewind@plt>
lea    0x10(%rsp),%rdi
mov    $0x3e8,%esi
mov    %rbx,%rdx
call   1090 <fgets@plt>
test   %rax,%rax
je     12ee <read_poly+0x13e>
lea    0x10(%rsp),%r12
lea    0x400(%rsp),%rbp
mov    %r13,%r14
jmp    12b5 <read_poly+0x105>
nopl   0x0(%rax)
mov    %r12,%rdi
mov    $0x3e8,%esi
mov    %rbx,%rdx
call   1090 <fgets@plt>
test   %rax,%rax
je     12ee <read_poly+0x13e>
cmpb   $0x23,0x10(%rsp)
je     12a0 <read_poly+0xf0>
mov    %r12,%rdi
lea    0xdbb(%rip),%rsi
mov    %rbp,%rdx
mov    %r14,%rcx
call   10c0 <sscanf@plt>
cmp    $0x2,%eax
jne    1327 <read_poly+0x177>
add    $0x4,%r14
jmp    12a0 <read_poly+0xf0>
mov    0x2cfd(%rip),%rax
mov    (%rax),%edi
lea    0xd52(%rip),%rsi
jmp    1308 <read_poly+0x158>
mov    %rbx,%rdi
call   1030 <fclose@plt>
jmp    1312 <read_poly+0x162>
mov    0x2ce1(%rip),%rax
mov    (%rax),%edi
lea    0xd66(%rip),%rsi
xor    %r13d,%r13d
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    %r13,%rax
add    $0x7e8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2cb2(%rip),%rax
mov    (%rax),%edi
lea    0xd50(%rip),%rsi
mov    %r15,%rdx
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    %r13,%rdi
call   1060 <del_array@plt>
mov    %rax,%r13
jmp    1312 <read_poly+0x162>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [36 x i8] c"ERROR: read_poly. Cannot open %s.\0A\00"
@.str.2 = [24 x i8] c"Enter filename again: \00"
@.str.3 = [48 x i8] c"ERROR: read_poly. No data lines in input file\0A\00"
@.str.4 = [19 x i8] c"ERROR: read_poly.\0A\00"
@.str.5 = [6 x i8] c"%s %f\00"
@.str.6 = [44 x i8] c"ERROR: read poly. Bad input format in %s.\0A\00"
define float* @read_poly(i8* %0, i32* %1) {
%3 = alloca float*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca float*
%7 = alloca float*
%8 = alloca [1000 x i8]
%9 = alloca [1000 x i8]
%10 = alloca i32*
store i8* %0, i8** %4
store i32* %1, i32** %5
store float* null, float** %6
store i32* null, i32** %10
br label %11
11: ; preds = %16, %2
%12 = load i8*, i8** %4
%13 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %13, i32** %10
%14 = icmp ne i32* %13, null
%15 = xor i1 %14, true
br i1 %15, label %16, label %23
16: ; preds = %11
%17 = load i32, i32* @stderr
%18 = load i8*, i8** %4
%19 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i8* %18)
%20 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
%21 = load i8*, i8** %4
%22 = call i32 @gets(i8* %21)
br label %11
23: ; preds = %11
%24 = load i32*, i32** %10
%25 = call i32 @n_lines(i32* %24, i8 signext 35)
%26 = load i32*, i32** %5
store i32 %25, i32* %26
%27 = icmp sle i32 %25, 0
br i1 %27, label %28, label %31
28: ; preds = %23
%29 = load i32, i32* @stderr
%30 = call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.3, i64 0, i64 0))
store float* null, float** %3
br label %78
31: ; preds = %23
%32 = load i32*, i32** %5
%33 = load i32, i32* %32
%34 = call float* @new_array(i32 %33, i32 1)
store float* %34, float** %6
%35 = icmp ne float* %34, null
br i1 %35, label %39, label %36
36: ; preds = %31
%37 = load i32, i32* @stderr
%38 = call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
store float* null, float** %3
br label %78
39: ; preds = %31
%40 = load i32*, i32** %10
%41 = call i32 @rewind(i32* %40)
%42 = load float*, float** %6
store float* %42, float** %7
br label %43
43: ; preds = %69, %39
%44 = getelementptr inbounds [1000 x i8], [1000 x i8]* %8, i64 0, i64 0
%45 = load i32*, i32** %10
%46 = call i32* @fgets(i8* %44, i32 1000, i32* %45)
%47 = icmp ne i32* %46, null
br i1 %47, label %48, label %70
48: ; preds = %43
%49 = getelementptr inbounds [1000 x i8], [1000 x i8]* %8, i64 0, i64 0
%50 = load i8, i8* %49
%51 = sext i8 %50 to i32
%52 = icmp ne i32 %51, 35
br i1 %52, label %53, label %69
53: ; preds = %48
%54 = getelementptr inbounds [1000 x i8], [1000 x i8]* %8, i64 0, i64 0
%55 = getelementptr inbounds [1000 x i8], [1000 x i8]* %9, i64 0, i64 0
%56 = load float*, float** %7
%57 = call i32 @sscanf(i8* %54, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* %55, float* %56)
%58 = icmp ne i32 %57, 2
br i1 %58, label %59, label %65
59: ; preds = %53
%60 = load i32, i32* @stderr
%61 = load i8*, i8** %4
%62 = call i32 (i32, i8*, ...) @fprintf(i32 %60, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.6, i64 0, i64 0), i8* %61)
%63 = load float*, float** %6
%64 = call float* @del_array(float* %63)
store float* %64, float** %3
br label %78
65: ; preds = %53
%66 = load float*, float** %7
%67 = getelementptr inbounds float, float* %66, i32 1
store float* %67, float** %7
br label %68
68: ; preds = %65
br label %69
69: ; preds = %68, %48
br label %43
70: ; preds = %43
%71 = load i32*, i32** %10
%72 = icmp ne i32* %71, null
br i1 %72, label %73, label %76
73: ; preds = %70
%74 = load i32*, i32** %10
%75 = call i32 @fclose(i32* %74)
br label %76
76: ; preds = %73, %70
%77 = load float*, float** %6
store float* %77, float** %3
br label %78
78: ; preds = %76, %59, %36, %28
%79 = load float*, float** %3
ret float* %79
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [36 x i8] c"ERROR: read_poly. Cannot open %s.\0A\00"
@.str.2 = [24 x i8] c"Enter filename again: \00"
@.str.3 = [48 x i8] c"ERROR: read_poly. No data lines in input file\0A\00"
@.str.4 = [19 x i8] c"ERROR: read_poly.\0A\00"
@.str.5 = [6 x i8] c"%s %f\00"
@.str.6 = [44 x i8] c"ERROR: read poly. Bad input format in %s.\0A\00"
define float* @read_poly(i8* %0, i32* nocapture writeonly %1) {
%3 = alloca [1000 x i8]
%4 = alloca [1000 x i8]
%5 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%7 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %16
9: ; preds = %2, %9
%10 = load i32, i32* @stderr
%11 = tail call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%12 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
%13 = tail call i32 @gets(i8* %0)
%14 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%15 = icmp eq i32* %14, null
br i1 %15, label %9, label %16
16: ; preds = %9, %2
%17 = phi i32* [ %7, %2 ], [ %14, %9 ]
%18 = tail call i32 @n_lines(i32* %17, i8 signext 35)
store i32 %18, i32* %1
%19 = icmp slt i32 %18, 1
br i1 %19, label %20, label %23
20: ; preds = %16
%21 = load i32, i32* @stderr
%22 = tail call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.3, i64 0, i64 0))
br label %52
23: ; preds = %16
%24 = tail call float* @new_array(i32 %18, i32 1)
%25 = icmp eq float* %24, null
br i1 %25, label %26, label %29
26: ; preds = %23
%27 = load i32, i32* @stderr
%28 = tail call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
br label %52
29: ; preds = %23
%30 = tail call i32 @rewind(i32* %17)
%31 = call i32* @fgets(i8* %5, i32 1000, i32* %17)
%32 = icmp eq i32* %31, null
br i1 %32, label %50, label %33
33: ; preds = %29, %46
%34 = phi float* [ %47, %46 ], [ %24, %29 ]
%35 = load i8, i8* %5
%36 = icmp eq i8 %35, 35
br i1 %36, label %46, label %37
37: ; preds = %33
%38 = call i32 @sscanf(i8* %5, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* %6, float* %34)
%39 = icmp eq i32 %38, 2
br i1 %39, label %44, label %40
40: ; preds = %37
%41 = load i32, i32* @stderr
%42 = call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.6, i64 0, i64 0), i8* %0)
%43 = call float* @del_array(float* %24)
br label %52
44: ; preds = %37
%45 = getelementptr inbounds float, float* %34, i64 1
br label %46
46: ; preds = %44, %33
%47 = phi float* [ %45, %44 ], [ %34, %33 ]
%48 = call i32* @fgets(i8* %5, i32 1000, i32* %17)
%49 = icmp eq i32* %48, null
br i1 %49, label %50, label %33
50: ; preds = %46, %29
%51 = call i32 @fclose(i32* %17)
br label %52
52: ; preds = %50, %40, %26, %20
%53 = phi float* [ null, %20 ], [ %43, %40 ], [ null, %26 ], [ %24, %50 ]
ret float* %53
}