#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 */
scalar_t__ calloc(int, int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, int *);
char getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char *);
char *read_equations_from_file(int /*<<< orphan*/ *, int, int /*<<< orphan*/,
                               int *, char *);
char *read_polynomials_from_file(int nc, char *name, int *len, int *nq, int *nv,
                                 int *fail) {
  char *result;
  FILE *fp;
  fp = fopen(name, "r");
  if (fp == NULL) {
    printf("File with name %s could not be opened for reading!\n", name);
    *fail = 1;
  } else {
    char c;
    char *acc;
    fscanf(fp, "%d", nq);
    c = getc(fp);
    if (c == '\n')
      *nv = *nq;
    else
      fscanf(fp, "%d", nv);
    acc = (char *)calloc(1, sizeof(char));
    acc[0] = '\0';
    *len = 0;
    result = read_equations_from_file(fp, *nq, 0, len, acc);
    *fail = 0;
  }
  fclose(fp);
  return result;
}


x86 assembly (clang, -O0):
<read_polynomials_from_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe66(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    11cd <read_polynomials_from_file+0x5d>
mov    -0x10(%rbp),%rsi
lea    0xe49(%rip),%rdi
call   1040 <printf@plt>
mov    -0x30(%rbp),%rax
movl   $0x1,(%rax)
jmp    1267 <read_polynomials_from_file+0xf7>
mov    -0x40(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xe5a(%rip),%rsi
call   1050 <fscanf@plt>
mov    -0x40(%rbp),%rdi
call   1090 <getc@plt>
mov    %al,-0x41(%rbp)
movsbl -0x41(%rbp),%eax
cmp    $0xa,%eax
jne    120b <read_polynomials_from_file+0x9b>
mov    -0x20(%rbp),%rax
mov    (%rax),%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
jmp    121f <read_polynomials_from_file+0xaf>
mov    -0x40(%rbp),%rdi
mov    -0x28(%rbp),%rdx
lea    0xe1c(%rip),%rsi
call   1050 <fscanf@plt>
mov    $0x1,%esi
mov    %esi,%edi
call   1060 <calloc@plt>
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x40(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    (%rax),%esi
mov    -0x18(%rbp),%rcx
mov    -0x50(%rbp),%r8
xor    %edx,%edx
call   1070 <read_equations_from_file@plt>
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x40(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x38(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_polynomials_from_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9,%r14
mov    %r8,%r13
mov    %rcx,%r12
mov    %rdx,%r15
mov    %rsi,%rbp
lea    0xe6f(%rip),%rsi
mov    %rbp,%rdi
call   1080 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11c9 <read_polynomials_from_file+0x59>
lea    0xe8e(%rip),%rsi
mov    %rbx,%rdi
mov    %r12,%rdx
call   1050 <fscanf@plt>
mov    %rbx,%rdi
call   1090 <getc@plt>
cmp    $0xa,%al
jne    11df <read_polynomials_from_file+0x6f>
mov    (%r12),%eax
mov    %eax,0x0(%r13)
jmp    11f1 <read_polynomials_from_file+0x81>
lea    0xe32(%rip),%rdi
mov    %rbp,%rsi
call   1040 <printf@plt>
mov    $0x1,%ebp
jmp    1223 <read_polynomials_from_file+0xb3>
lea    0xe50(%rip),%rsi
mov    %rbx,%rdi
mov    %r13,%rdx
call   1050 <fscanf@plt>
mov    $0x1,%edi
mov    $0x1,%esi
call   1060 <calloc@plt>
movb   $0x0,(%rax)
movl   $0x0,(%r15)
mov    (%r12),%esi
xor    %ebp,%ebp
mov    %rbx,%rdi
xor    %edx,%edx
mov    %r15,%rcx
mov    %rax,%r8
call   1070 <read_equations_from_file@plt>
mov    %rax,%r15
mov    %ebp,(%r14)
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [52 x i8] c"File with name %s could not be opened for reading!\0A\00"
@.str.2 = [3 x i8] c"%d\00"
define i8* @read_polynomials_from_file(i32 %0, i8* %1, i32* %2, i32* %3, i32* %4, i32* %5) {
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i32*
%12 = alloca i32*
%13 = alloca i8*
%14 = alloca i32*
%15 = alloca i8
%16 = alloca i8*
store i32 %0, i32* %7
store i8* %1, i8** %8
store i32* %2, i32** %9
store i32* %3, i32** %10
store i32* %4, i32** %11
store i32* %5, i32** %12
%17 = load i8*, i8** %8
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %18, i32** %14
%19 = load i32*, i32** %14
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %25
21: ; preds = %6
%22 = load i8*, i8** %8
%23 = call i32 @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0), i8* %22)
%24 = load i32*, i32** %12
store i32 1, i32* %24
br label %55
25: ; preds = %6
%26 = load i32*, i32** %14
%27 = load i32*, i32** %10
%28 = call i32 @fscanf(i32* %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %27)
%29 = load i32*, i32** %14
%30 = call signext i8 @getc(i32* %29)
store i8 %30, i8* %15
%31 = load i8, i8* %15
%32 = sext i8 %31 to i32
%33 = icmp eq i32 %32, 10
br i1 %33, label %34, label %38
34: ; preds = %25
%35 = load i32*, i32** %10
%36 = load i32, i32* %35
%37 = load i32*, i32** %11
store i32 %36, i32* %37
br label %42
38: ; preds = %25
%39 = load i32*, i32** %14
%40 = load i32*, i32** %11
%41 = call i32 @fscanf(i32* %39, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %40)
br label %42
42: ; preds = %38, %34
%43 = call i64 @calloc(i32 1, i32 1)
%44 = inttoptr i64 %43 to i8*
store i8* %44, i8** %16
%45 = load i8*, i8** %16
%46 = getelementptr inbounds i8, i8* %45, i64 0
store i8 0, i8* %46
%47 = load i32*, i32** %9
store i32 0, i32* %47
%48 = load i32*, i32** %14
%49 = load i32*, i32** %10
%50 = load i32, i32* %49
%51 = load i32*, i32** %9
%52 = load i8*, i8** %16
%53 = call i8* @read_equations_from_file(i32* %48, i32 %50, i32 0, i32* %51, i8* %52)
store i8* %53, i8** %13
%54 = load i32*, i32** %12
store i32 0, i32* %54
br label %55
55: ; preds = %42, %21
%56 = load i32*, i32** %14
%57 = call i32 @fclose(i32* %56)
%58 = load i8*, i8** %13
ret i8* %58
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [52 x i8] c"File with name %s could not be opened for reading!\0A\00"
@.str.2 = [3 x i8] c"%d\00"
define i8* @read_polynomials_from_file(i32 %0, i8* %1, i32* %2, i32* %3, i32* %4, i32* nocapture writeonly %5) {
%7 = tail call i32* @fopen(i8* %1, 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 %11
9: ; preds = %6
%10 = tail call i32 @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0), i8* %1)
br label %24
11: ; preds = %6
%12 = tail call i32 @fscanf(i32* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%13 = tail call signext i8 @getc(i32* %7)
%14 = icmp eq i8 %13, 10
br i1 %14, label %15, label %17
15: ; preds = %11
%16 = load i32, i32* %3
store i32 %16, i32* %4
br label %19
17: ; preds = %11
%18 = tail call i32 @fscanf(i32* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %4)
br label %19
19: ; preds = %17, %15
%20 = tail call i64 @calloc(i32 1, i32 1)
%21 = inttoptr i64 %20 to i8*
store i8 0, i8* %21
store i32 0, i32* %2
%22 = load i32, i32* %3
%23 = tail call i8* @read_equations_from_file(i32* %7, i32 %22, i32 0, i32* %2, i8* %21)
br label %24
24: ; preds = %19, %9
%25 = phi i32 [ 0, %19 ], [ 1, %9 ]
%26 = phi i8* [ %23, %19 ], [ undef, %9 ]
store i32 %25, i32* %5
%27 = tail call i32 @fclose(i32* %7)
ret i8* %26
}