#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 extrair_numero(char *, int *, char);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, char *);
float *ler_polinomio(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int ler_arquivo_polinomio(float **polinomio1, float **polinomio2, float *x,
                          FILE **saida) {
  FILE *arquivo = NULL;
  int aux = 2;
  char *linha = NULL;
  linha = (char *)malloc(100 * sizeof(char));
  arquivo = fopen("p-input.txt", "r");
  if (!arquivo) {
    printf("Erro ao abrir arquivo!\n");
    return 1;
  }
  fscanf(arquivo, "%s\n", linha);
  printf("%s\n", linha);
  fprintf(*saida, "%s\n", linha);
  *polinomio1 = ler_polinomio(linha);
  fscanf(arquivo, "%s\n", linha);
  printf("%s\n", linha);
  fprintf(*saida, "%s\n", linha);
  *polinomio2 = ler_polinomio(linha);
  fscanf(arquivo, "%s\n", linha);
  *x = extrair_numero(linha, &aux, '+');
  printf("x=%.2f\n", *x);
  fprintf(*saida, "x=%.2f\n", *x);
  fclose(arquivo);
  return 0;
}


x86 assembly (clang, -O0):
<ler_arquivo_polinomio>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movl   $0x2,-0x34(%rbp)
movq   $0x0,-0x40(%rbp)
mov    $0x64,%edi
call   1090 <malloc@plt>
mov    %rax,-0x40(%rbp)
lea    0xe3c(%rip),%rdi
lea    0xe41(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11f9 <ler_arquivo_polinomio+0x79>
lea    0xe28(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1316 <ler_arquivo_polinomio+0x196>
mov    -0x30(%rbp),%rdi
mov    -0x40(%rbp),%rdx
lea    0xe1e(%rip),%rsi
call   1070 <fscanf@plt>
mov    -0x40(%rbp),%rsi
lea    0xe0e(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x28(%rbp),%rax
mov    (%rax),%rdi
mov    -0x40(%rbp),%rdx
lea    0xdf5(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x40(%rbp),%rdi
call   1030 <ler_polinomio@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x30(%rbp),%rdi
mov    -0x40(%rbp),%rdx
lea    0xdcc(%rip),%rsi
call   1070 <fscanf@plt>
mov    -0x40(%rbp),%rsi
lea    0xdbc(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x28(%rbp),%rax
mov    (%rax),%rdi
mov    -0x40(%rbp),%rdx
lea    0xda3(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x40(%rbp),%rdi
call   1030 <ler_polinomio@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x30(%rbp),%rdi
mov    -0x40(%rbp),%rdx
lea    0xd7a(%rip),%rsi
call   1070 <fscanf@plt>
mov    -0x40(%rbp),%rdi
lea    -0x34(%rbp),%rsi
mov    $0x2b,%edx
call   1040 <extrair_numero@plt>
mov    -0x20(%rbp),%rax
movss  %xmm0,(%rax)
mov    -0x20(%rbp),%rax
movss  (%rax),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xd4c(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
mov    -0x28(%rbp),%rax
mov    (%rax),%rdi
mov    -0x20(%rbp),%rax
movss  (%rax),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xd2b(%rip),%rsi
mov    $0x1,%al
call   1080 <fprintf@plt>
mov    -0x30(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ler_arquivo_polinomio>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%r15
mov    %rdx,%r12
mov    %rsi,%r13
mov    %rdi,%r14
movl   $0x2,0xc(%rsp)
mov    $0x64,%edi
call   10a0 <malloc@plt>
mov    %rax,%rbp
lea    0xe3a(%rip),%rdi
lea    0xe3f(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     12af <ler_arquivo_polinomio+0x11f>
mov    %rax,%rbx
mov    %r13,0x10(%rsp)
lea    0xe24(%rip),%r13
mov    %rax,%rdi
mov    %r13,%rsi
mov    %rbp,%rdx
call   1080 <fscanf@plt>
mov    %rbp,%rdi
call   1040 <puts@plt>
mov    (%r15),%rdi
mov    %r13,%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    %rbp,%rdi
call   1030 <ler_polinomio@plt>
mov    %rax,(%r14)
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %rbp,%rdx
call   1080 <fscanf@plt>
mov    %rbp,%rdi
call   1040 <puts@plt>
mov    (%r15),%rdi
mov    %r13,%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    %rbp,%rdi
call   1030 <ler_polinomio@plt>
mov    0x10(%rsp),%rcx
mov    %rax,(%rcx)
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %rbp,%rdx
call   1080 <fscanf@plt>
lea    0xc(%rsp),%rsi
mov    %rbp,%rdi
mov    $0x2b,%edx
call   1050 <extrair_numero@plt>
movss  %xmm0,(%r12)
cvtss2sd %xmm0,%xmm0
lea    0xd90(%rip),%rbp
mov    %rbp,%rdi
mov    $0x1,%al
call   1070 <printf@plt>
mov    (%r15),%rdi
movss  (%r12),%xmm0
cvtss2sd %xmm0,%xmm0
mov    %rbp,%rsi
mov    $0x1,%al
call   1090 <fprintf@plt>
mov    %rbx,%rdi
call   1060 <fclose@plt>
xor    %eax,%eax
jmp    12c0 <ler_arquivo_polinomio+0x130>
lea    0xd64(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"p-input.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [24 x i8] c"Erro ao abrir arquivo!\0A\00"
@.str.3 = [4 x i8] c"%s\0A\00"
@.str.4 = [8 x i8] c"x=%.2f\0A\00"
define i32 @ler_arquivo_polinomio(float** %0, float** %1, float* %2, i32** %3) {
%5 = alloca i32
%6 = alloca float**
%7 = alloca float**
%8 = alloca float*
%9 = alloca i32**
%10 = alloca i32*
%11 = alloca i32
%12 = alloca i8*
store float** %0, float*** %6
store float** %1, float*** %7
store float* %2, float** %8
store i32** %3, i32*** %9
store i32* null, i32** %10
store i32 2, i32* %11
store i8* null, i8** %12
%13 = call i64 @malloc(i32 100)
%14 = inttoptr i64 %13 to i8*
store i8* %14, i8** %12
%15 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %15, i32** %10
%16 = load i32*, i32** %10
%17 = icmp ne i32* %16, null
br i1 %17, label %20, label %18
18: ; preds = %4
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %5
br label %63
20: ; preds = %4
%21 = load i32*, i32** %10
%22 = load i8*, i8** %12
%23 = call i32 @fscanf(i32* %21, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %22)
%24 = load i8*, i8** %12
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %24)
%26 = load i32**, i32*** %9
%27 = load i32*, i32** %26
%28 = load i8*, i8** %12
%29 = call i32 (i32*, i8*, ...) @fprintf(i32* %27, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %28)
%30 = load i8*, i8** %12
%31 = call float* @ler_polinomio(i8* %30)
%32 = load float**, float*** %6
store float* %31, float** %32
%33 = load i32*, i32** %10
%34 = load i8*, i8** %12
%35 = call i32 @fscanf(i32* %33, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %34)
%36 = load i8*, i8** %12
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %36)
%38 = load i32**, i32*** %9
%39 = load i32*, i32** %38
%40 = load i8*, i8** %12
%41 = call i32 (i32*, i8*, ...) @fprintf(i32* %39, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %40)
%42 = load i8*, i8** %12
%43 = call float* @ler_polinomio(i8* %42)
%44 = load float**, float*** %7
store float* %43, float** %44
%45 = load i32*, i32** %10
%46 = load i8*, i8** %12
%47 = call i32 @fscanf(i32* %45, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %46)
%48 = load i8*, i8** %12
%49 = call float @extrair_numero(i8* %48, i32* %11, i8 signext 43)
%50 = load float*, float** %8
store float %49, float* %50
%51 = load float*, float** %8
%52 = load float, float* %51
%53 = fpext float %52 to double
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), double %53)
%55 = load i32**, i32*** %9
%56 = load i32*, i32** %55
%57 = load float*, float** %8
%58 = load float, float* %57
%59 = fpext float %58 to double
%60 = call i32 (i32*, i8*, ...) @fprintf(i32* %56, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), double %59)
%61 = load i32*, i32** %10
%62 = call i32 @fclose(i32* %61)
store i32 0, i32* %5
br label %63
63: ; preds = %20, %18
%64 = load i32, i32* %5
ret i32 %64
}

LLVM IR (-O2):
@.str = [12 x i8] c"p-input.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.3 = [4 x i8] c"%s\0A\00"
@.str.4 = [8 x i8] c"x=%.2f\0A\00"
@str = [23 x i8] c"Erro ao abrir arquivo!\00"
define i32 @ler_arquivo_polinomio(float** nocapture writeonly %0, float** nocapture writeonly %1, float* nocapture %2, i32** nocapture %3) {
%5 = alloca i32
%6 = bitcast i32* %5 to i8*
store i32 2, i32* %5
%7 = tail call i64 @malloc(i32 100)
%8 = inttoptr i64 %7 to i8*
%9 = tail call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %4
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
br label %33
13: ; preds = %4
%14 = tail call i32 @fscanf(i32* %9, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %8)
%15 = tail call i32 @puts(i8* dereferenceable(1) %8)
%16 = load i32*, i32** %3
%17 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %16, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %8)
%18 = tail call float* @ler_polinomio(i8* %8)
store float* %18, float** %0
%19 = tail call i32 @fscanf(i32* %9, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %8)
%20 = tail call i32 @puts(i8* dereferenceable(1) %8)
%21 = load i32*, i32** %3
%22 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %21, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %8)
%23 = tail call float* @ler_polinomio(i8* %8)
store float* %23, float** %1
%24 = tail call i32 @fscanf(i32* %9, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %8)
%25 = call float @extrair_numero(i8* %8, i32* %5, i8 signext 43)
store float %25, float* %2
%26 = fpext float %25 to double
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), double %26)
%28 = load i32*, i32** %3
%29 = load float, float* %2
%30 = fpext float %29 to double
%31 = call i32 (i32*, i8*, ...) @fprintf(i32* %28, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), double %30)
%32 = call i32 @fclose(i32* %9)
br label %33
33: ; preds = %13, %11
%34 = phi i32 [ 0, %13 ], [ 1, %11 ]
ret i32 %34
}