#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*/ valor_atual;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(int *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, int, int);
int main() {
  char path[] = "arquivos/output.bin";
  FILE *arq = fopen(path, "r");
  int quant_inteiros = 0;
  int quant_inteiros_des = 0;
  int valor_anterio;
  int valor_atual;
  fread(&valor_atual, sizeof(valor_atual), 1, arq);
  quant_inteiros++;
  while (!(feof(arq))) {
    valor_anterio = valor_atual;
    fread(&valor_atual, sizeof(valor_atual), 1, arq);
    quant_inteiros++;
    if (valor_anterio > valor_atual) {
      quant_inteiros_des++;
    }
  }
  printf("Foram %d Inteiros e deste %d estão desordenados\n",
         quant_inteiros - 1, quant_inteiros_des);
  fclose(arq);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xe9a(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xe97(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xe95(%rip),%eax
mov    %eax,-0x10(%rbp)
lea    -0x20(%rbp),%rdi
lea    0xe8b(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x28(%rbp),%rcx
lea    -0x38(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11de <main+0x8e>
jmp    121e <main+0xce>
mov    -0x38(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x28(%rbp),%rcx
lea    -0x38(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x38(%rbp),%eax
jle    1219 <main+0xc9>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    11c0 <main+0x70>
mov    -0x2c(%rbp),%esi
sub    $0x1,%esi
mov    -0x30(%rbp),%edx
lea    0xde8(%rip),%rdi
call   1050 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
movaps 0xe9b(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movl   $0x6e6962,0x20(%rsp)
lea    0xe9b(%rip),%rsi
lea    0x10(%rsp),%rdi
call   1070 <fopen@plt>
mov    %rax,%r14
lea    0xc(%rsp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1030 <fread@plt>
mov    %r14,%rdi
call   1060 <feof@plt>
xor    %ebx,%ebx
mov    $0x0,%ebp
test   %eax,%eax
jne    11f6 <main+0xa6>
xor    %ebp,%ebp
mov    0xc(%rsp),%r12d
lea    0xc(%rsp),%r15
xor    %ebx,%ebx
xchg   %ax,%ax
mov    %r15,%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1030 <fread@plt>
mov    0xc(%rsp),%r13d
xor    %eax,%eax
cmp    %r13d,%r12d
setg   %al
add    %eax,%ebx
mov    %r14,%rdi
call   1060 <feof@plt>
add    $0x1,%ebp
mov    %r13d,%r12d
test   %eax,%eax
je     11c0 <main+0x70>
lea    0xe19(%rip),%rdi
mov    %ebp,%esi
mov    %ebx,%edx
call   1050 <printf@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.path = [20 x i8] c"arquivos/output.bin\00"
@.str = [2 x i8] c"r\00"
@.str.1 = [50 x i8] c"Foram %d Inteiros e deste %d est\C3\A3o desordenados\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [20 x i8]
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
%8 = bitcast [20 x i8]* %2 to i8*
%9 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %3
store i32 0, i32* %4
store i32 0, i32* %5
%11 = load i32*, i32** %3
%12 = call i32 @fread(i32* %7, i32 4, i32 1, i32* %11)
%13 = load i32, i32* %4
%14 = add nsw i32 %13, 1
store i32 %14, i32* %4
br label %15
15: ; preds = %32, %0
%16 = load i32*, i32** %3
%17 = call i32 @feof(i32* %16)
%18 = icmp ne i32 %17, 0
%19 = xor i1 %18, true
br i1 %19, label %20, label %33
20: ; preds = %15
%21 = load i32, i32* %7
store i32 %21, i32* %6
%22 = load i32*, i32** %3
%23 = call i32 @fread(i32* %7, i32 4, i32 1, i32* %22)
%24 = load i32, i32* %4
%25 = add nsw i32 %24, 1
store i32 %25, i32* %4
%26 = load i32, i32* %6
%27 = load i32, i32* %7
%28 = icmp sgt i32 %26, %27
br i1 %28, label %29, label %32
29: ; preds = %20
%30 = load i32, i32* %5
%31 = add nsw i32 %30, 1
store i32 %31, i32* %5
br label %32
32: ; preds = %29, %20
br label %15
33: ; preds = %15
%34 = load i32, i32* %4
%35 = sub nsw i32 %34, 1
%36 = load i32, i32* %5
%37 = call i32 @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.1, i64 0, i64 0), i32 %35, i32 %36)
%38 = load i32*, i32** %3
%39 = call i32 @fclose(i32* %38)
ret i32 0
}

LLVM IR (-O2):
@__const.main.path = [20 x i8] c"arquivos/output.bin\00"
@.str = [2 x i8] c"r\00"
@.str.1 = [50 x i8] c"Foram %d Inteiros e deste %d est\C3\A3o desordenados\0A\00"
define i32 @main() {
%1 = alloca [20 x i8]
%2 = alloca i32
%3 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 0
%4 = call i32* @fopen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = bitcast i32* %2 to i8*
%6 = call i32 @fread(i32* %2, i32 4, i32 1, i32* %4)
%7 = tail call i32 @feof(i32* %4)
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %23
9: ; preds = %0
%10 = load i32, i32* %2
br label %11
11: ; preds = %9, %11
%12 = phi i32 [ %17, %11 ], [ %10, %9 ]
%13 = phi i32 [ %16, %11 ], [ 1, %9 ]
%14 = phi i32 [ %20, %11 ], [ 0, %9 ]
%15 = call i32 @fread(i32* %2, i32 4, i32 1, i32* %4)
%16 = add nuw nsw i32 %13, 1
%17 = load i32, i32* %2
%18 = icmp sgt i32 %12, %17
%19 = zext i1 %18 to i32
%20 = add nuw nsw i32 %14, %19
%21 = tail call i32 @feof(i32* %4)
%22 = icmp eq i32 %21, 0
br i1 %22, label %11, label %23
23: ; preds = %11, %0
%24 = phi i32 [ 0, %0 ], [ %20, %11 ]
%25 = phi i32 [ 0, %0 ], [ %13, %11 ]
%26 = tail call i32 @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.1, i64 0, i64 0), i32 %25, i32 %24)
%27 = tail call i32 @fclose(i32* %4)
ret i32 0
}