#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fscanf(int /*<<< orphan*/ *, char *, int *);
int /*<<< orphan*/ printf(char *, int, int);
int main() {
  FILE *arquivo;
  int n;
  arquivo = fopen("dados.txt", "r");
  while (!feof(arquivo)) {
    int r = fscanf(arquivo, "%i", &n);
    printf("Resultado do scanf=%i; o número lido foi %i.\n", r, n);
  }
  fclose(arquivo);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
lea    0xe9d(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1194 <main+0x44>
jmp    11c2 <main+0x72>
mov    -0x10(%rbp),%rdi
lea    0xe6d(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1050 <fscanf@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%esi
mov    -0x14(%rbp),%edx
lea    0xe57(%rip),%rdi
call   1040 <printf@plt>
jmp    1176 <main+0x26>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xea1(%rip),%rdi
lea    0xea4(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <feof@plt>
test   %eax,%eax
jne    11b8 <main+0x68>
lea    0xe8b(%rip),%r14
lea    0x4(%rsp),%r15
lea    0xe82(%rip),%r12
nopl   (%rax)
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1050 <fscanf@plt>
mov    0x4(%rsp),%edx
mov    %r12,%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1060 <feof@plt>
test   %eax,%eax
je     1190 <main+0x40>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [10 x i8] c"dados.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%i\00"
@.str.3 = [47 x i8] c"Resultado do scanf=%i; o n\C3\BAmero lido foi %i.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %5, i32** %2
br label %6
6: ; preds = %11, %0
%7 = load i32*, i32** %2
%8 = call i32 @feof(i32* %7)
%9 = icmp ne i32 %8, 0
%10 = xor i1 %9, true
br i1 %10, label %11, label %17
11: ; preds = %6
%12 = load i32*, i32** %2
%13 = call i32 @fscanf(i32* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
store i32 %13, i32* %4
%14 = load i32, i32* %4
%15 = load i32, i32* %3
%16 = call i32 @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.3, i64 0, i64 0), i32 %14, i32 %15)
br label %6
17: ; preds = %6
%18 = load i32*, i32** %2
%19 = call i32 @fclose(i32* %18)
ret i32 0
}

LLVM IR (-O2):
@.str = [10 x i8] c"dados.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%i\00"
@.str.3 = [47 x i8] c"Resultado do scanf=%i; o n\C3\BAmero lido foi %i.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = call i32 @feof(i32* %3)
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %12
6: ; preds = %0, %6
%7 = call i32 @fscanf(i32* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%8 = load i32, i32* %1
%9 = call i32 @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.3, i64 0, i64 0), i32 %7, i32 %8)
%10 = call i32 @feof(i32* %3)
%11 = icmp eq i32 %10, 0
br i1 %11, label %6, label %12
12: ; preds = %6, %0
%13 = call i32 @fclose(i32* %3)
ret i32 0
}