#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__ EOF;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ fscanf(int /*<<< orphan*/ *, char *, int *, char *, double *);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  FILE *fp;
  char titulo[40];
  int codigo;
  double preco;
  if ((fp = fopen("arqtext.txt", "r")) == NULL) {
    printf("\nO arquivo não pode ser aberto");
    exit(1);
  } else {
    printf("\nO arquivo foi aberto para leitura.\n");
  }
  printf("\nConteúdo do arquivo:\n");
  while (fscanf(fp, "%d %s %lf ", &codigo, titulo, &preco) != EOF) {
    printf("\n%d %s %lf", codigo, titulo, preco);
  }
  fclose(fp);
  printf("\n\nFim do programa!");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
lea    0xe9f(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    1198 <main+0x48>
lea    0xe87(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
lea    0xe8f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xea6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
lea    -0x40(%rbp),%rcx
lea    0xea8(%rip),%rsi
lea    -0x44(%rbp),%rdx
lea    -0x50(%rbp),%r8
call   1050 <fscanf@plt>
mov    0x2e11(%rip),%rcx
cmp    (%rcx),%rax
je     11ff <main+0xaf>
mov    -0x44(%rbp),%esi
lea    -0x40(%rbp),%rdx
movsd  -0x50(%rbp),%xmm0
lea    0xe83(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
jmp    11b4 <main+0x64>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xe72(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
lea    0xe8b(%rip),%rdi
lea    0xe90(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     124b <main+0xeb>
mov    %rax,%r15
lea    0xec3(%rip),%rdi
call   1030 <puts@plt>
lea    0xedb(%rip),%rdi
call   1030 <puts@plt>
lea    0xe82(%rip),%rsi
lea    0x4(%rsp),%rdx
lea    0x10(%rsp),%rcx
lea    0x8(%rsp),%r8
mov    %r15,%rdi
call   1060 <fscanf@plt>
mov    0x2e1e(%rip),%r14
cmp    (%r14),%rax
je     1224 <main+0xc4>
lea    0x10(%rsp),%rbx
lea    0xe53(%rip),%r12
lea    0x4(%rsp),%r13
lea    0x8(%rsp),%rbp
cs nopw 0x0(%rax,%rax,1)
nop
mov    0x4(%rsp),%esi
movsd  0x8(%rsp),%xmm0
lea    0xe38(%rip),%rdi
mov    %rbx,%rdx
mov    $0x1,%al
call   1050 <printf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %r13,%rdx
mov    %rbx,%rcx
mov    %rbp,%r8
call   1060 <fscanf@plt>
cmp    (%r14),%rax
jne    11f0 <main+0x90>
mov    %r15,%rdi
call   1040 <fclose@plt>
lea    0xe11(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdbc(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"arqtext.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [32 x i8] c"\0AO arquivo n\C3\A3o pode ser aberto\00"
@.str.3 = [37 x i8] c"\0AO arquivo foi aberto para leitura.\0A\00"
@.str.4 = [24 x i8] c"\0AConte\C3\BAdo do arquivo:\0A\00"
@.str.5 = [11 x i8] c"%d %s %lf \00"
@EOF = global i64 0
@.str.6 = [11 x i8] c"\0A%d %s %lf\00"
@.str.7 = [19 x i8] c"\0A\0AFim do programa!\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [40 x i8]
%4 = alloca i32
%5 = alloca double
store i32 0, i32* %1
%6 = 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* %6, i32** %2
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %11
8: ; preds = %0
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
%10 = call i32 @exit(i32 1)
unreachable
11: ; preds = %0
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0))
br label %13
13: ; preds = %11
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
br label %15
15: ; preds = %21, %13
%16 = load i32*, i32** %2
%17 = getelementptr inbounds [40 x i8], [40 x i8]* %3, i64 0, i64 0
%18 = call i64 @fscanf(i32* %16, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i32* %4, i8* %17, double* %5)
%19 = load i64, i64* @EOF
%20 = icmp ne i64 %18, %19
br i1 %20, label %21, label %26
21: ; preds = %15
%22 = load i32, i32* %4
%23 = getelementptr inbounds [40 x i8], [40 x i8]* %3, i64 0, i64 0
%24 = load double, double* %5
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i32 %22, i8* %23, double %24)
br label %15
26: ; preds = %15
%27 = load i32*, i32** %2
%28 = call i32 @fclose(i32* %27)
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [12 x i8] c"arqtext.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [32 x i8] c"\0AO arquivo n\C3\A3o pode ser aberto\00"
@.str.5 = [11 x i8] c"%d %s %lf \00"
@EOF = global i64 0
@.str.6 = [11 x i8] c"\0A%d %s %lf\00"
@.str.7 = [19 x i8] c"\0A\0AFim do programa!\00"
@str = [36 x i8] c"\0AO arquivo foi aberto para leitura.\00"
@str.8 = [23 x i8] c"\0AConte\C3\BAdo do arquivo:\00"
define i32 @main() {
%1 = alloca [40 x i8]
%2 = alloca i32
%3 = alloca double
%4 = getelementptr inbounds [40 x i8], [40 x i8]* %1, i64 0, i64 0
%5 = bitcast i32* %2 to i8*
%6 = bitcast double* %3 to i8*
%7 = 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))
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %12
9: ; preds = %0
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %0
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str, i64 0, i64 0))
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.8, i64 0, i64 0))
%15 = call i64 @fscanf(i32* %7, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i32* %2, i8* %4, double* %3)
%16 = load i64, i64* @EOF
%17 = icmp eq i64 %15, %16
br i1 %17, label %25, label %18
18: ; preds = %12, %18
%19 = load i32, i32* %2
%20 = load double, double* %3
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i32 %19, i8* %4, double %20)
%22 = call i64 @fscanf(i32* %7, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i32* %2, i8* %4, double* %3)
%23 = load i64, i64* @EOF
%24 = icmp eq i64 %22, %23
br i1 %24, label %25, label %18
25: ; preds = %18, %12
%26 = call i32 @fclose(i32* %7)
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0))
ret i32 0
}