#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*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(int *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(int *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int main() {
  int vetor1[500];
  int vetor2[500];
  int i;
  FILE *p;
  for (i = 0; i < 500; i++)
    vetor1[i] = i;
  p = fopen("teste.dat", "w+");
  rewind(p);
  fwrite(vetor1, sizeof(int), 500, p);
  rewind(p);
  fread(vetor2, sizeof(int), 500, p);
  fclose(p);
  for (i = 0; i < 500; i++) {
    if (vetor1[i] != vetor2[i]) {
      printf("Algo deu errado!\n");
      break;
    }
  }
  if (i == 500) {
    printf("Teste de leitura e escrita foi bem sucedido!\nVeja o que há no "
           "teste.dat!\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xfc0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xfb4(%rbp)
cmpl   $0x1f4,-0xfb4(%rbp)
jge    11b4 <main+0x54>
mov    -0xfb4(%rbp),%ecx
movslq -0xfb4(%rbp),%rax
mov    %ecx,-0x7e0(%rbp,%rax,4)
mov    -0xfb4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xfb4(%rbp)
jmp    117c <main+0x1c>
lea    0xe45(%rip),%rdi
lea    0xe48(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0xfc0(%rbp)
mov    -0xfc0(%rbp),%rdi
call   1060 <rewind@plt>
lea    -0x7e0(%rbp),%rdi
mov    -0xfc0(%rbp),%rcx
mov    $0x4,%esi
mov    $0x1f4,%edx
call   1080 <fwrite@plt>
mov    -0xfc0(%rbp),%rdi
call   1060 <rewind@plt>
lea    -0xfb0(%rbp),%rdi
mov    -0xfc0(%rbp),%rcx
mov    $0x4,%esi
mov    $0x1f4,%edx
call   1030 <fread@plt>
mov    -0xfc0(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0xfb4(%rbp)
cmpl   $0x1f4,-0xfb4(%rbp)
jge    1292 <main+0x132>
movslq -0xfb4(%rbp),%rax
mov    -0x7e0(%rbp,%rax,4),%eax
movslq -0xfb4(%rbp),%rcx
cmp    -0xfb0(%rbp,%rcx,4),%eax
je     1279 <main+0x119>
lea    0xd9e(%rip),%rdi
call   1050 <printf@plt>
jmp    1292 <main+0x132>
jmp    127e <main+0x11e>
mov    -0xfb4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xfb4(%rbp)
jmp    1236 <main+0xd6>
cmpl   $0x1f4,-0xfb4(%rbp)
jne    12ae <main+0x14e>
lea    0xd76(%rip),%rdi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0xfc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0xfa0,%rsp
movdqa 0xe90(%rip),%xmm0
mov    $0xc,%eax
movdqa 0xe93(%rip),%xmm1
movdqa 0xe9b(%rip),%xmm2
movdqa 0xea3(%rip),%xmm3
movdqa 0xeab(%rip),%xmm4
cs nopw 0x0(%rax,%rax,1)
nop
movdqa %xmm0,%xmm5
paddd  %xmm1,%xmm5
movdqa %xmm0,-0x30(%rsp,%rax,4)
movdqa %xmm5,-0x20(%rsp,%rax,4)
movdqa %xmm0,%xmm5
paddd  %xmm2,%xmm5
movdqa %xmm0,%xmm6
paddd  %xmm3,%xmm6
movdqa %xmm5,-0x10(%rsp,%rax,4)
movdqa %xmm6,(%rsp,%rax,4)
paddd  %xmm4,%xmm0
add    $0x10,%rax
cmp    $0x1fc,%rax
jne    11a0 <main+0x40>
movaps 0xe6a(%rip),%xmm0
movaps %xmm0,0x7c0(%rsp)
lea    0xe6b(%rip),%rdi
lea    0xe6e(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <rewind@plt>
mov    %rsp,%rdi
mov    $0x4,%esi
mov    $0x1f4,%edx
mov    %rbx,%rcx
call   1080 <fwrite@plt>
mov    %rbx,%rdi
call   1060 <rewind@plt>
lea    0x7d0(%rsp),%rdi
mov    $0x4,%esi
mov    $0x1f4,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    $0x4,%eax
lea    0xe60(%rip),%rdi
lea    0xe0f(%rip),%rcx
xchg   %ax,%ax
mov    -0x10(%rsp,%rax,4),%edx
cmp    0x7c0(%rsp,%rax,4),%edx
jne    12af <main+0x14f>
mov    -0xc(%rsp,%rax,4),%edx
cmp    0x7c4(%rsp,%rax,4),%edx
jne    12af <main+0x14f>
mov    -0x8(%rsp,%rax,4),%edx
cmp    0x7c8(%rsp,%rax,4),%edx
jne    12af <main+0x14f>
mov    -0x4(%rsp,%rax,4),%edx
cmp    0x7cc(%rsp,%rax,4),%edx
jne    12af <main+0x14f>
mov    (%rsp,%rax,4),%edx
cmp    0x7d0(%rsp,%rax,4),%edx
jne    12af <main+0x14f>
add    $0x5,%rax
cmp    $0x1f8,%rax
jne    1260 <main+0x100>
mov    %rcx,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0xfa0,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [10 x i8] c"teste.dat\00"
@.str.1 = [3 x i8] c"w+\00"
@.str.2 = [18 x i8] c"Algo deu errado!\0A\00"
@.str.3 = [75 x i8] c"Teste de leitura e escrita foi bem sucedido!\0AVeja o que h\C3\A1 no teste.dat!\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [500 x i32]
%3 = alloca [500 x i32]
%4 = alloca i32
%5 = alloca i32*
store i32 0, i32* %1
store i32 0, i32* %4
br label %6
6: ; preds = %14, %0
%7 = load i32, i32* %4
%8 = icmp slt i32 %7, 500
br i1 %8, label %9, label %17
9: ; preds = %6
%10 = load i32, i32* %4
%11 = load i32, i32* %4
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds [500 x i32], [500 x i32]* %2, i64 0, i64 %12
store i32 %10, i32* %13
br label %14
14: ; preds = %9
%15 = load i32, i32* %4
%16 = add nsw i32 %15, 1
store i32 %16, i32* %4
br label %6
17: ; preds = %6
%18 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %18, i32** %5
%19 = load i32*, i32** %5
%20 = call i32 @rewind(i32* %19)
%21 = getelementptr inbounds [500 x i32], [500 x i32]* %2, i64 0, i64 0
%22 = load i32*, i32** %5
%23 = call i32 @fwrite(i32* %21, i32 4, i32 500, i32* %22)
%24 = load i32*, i32** %5
%25 = call i32 @rewind(i32* %24)
%26 = getelementptr inbounds [500 x i32], [500 x i32]* %3, i64 0, i64 0
%27 = load i32*, i32** %5
%28 = call i32 @fread(i32* %26, i32 4, i32 500, i32* %27)
%29 = load i32*, i32** %5
%30 = call i32 @fclose(i32* %29)
store i32 0, i32* %4
br label %31
31: ; preds = %47, %17
%32 = load i32, i32* %4
%33 = icmp slt i32 %32, 500
br i1 %33, label %34, label %50
34: ; preds = %31
%35 = load i32, i32* %4
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [500 x i32], [500 x i32]* %2, i64 0, i64 %36
%38 = load i32, i32* %37
%39 = load i32, i32* %4
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [500 x i32], [500 x i32]* %3, i64 0, i64 %40
%42 = load i32, i32* %41
%43 = icmp ne i32 %38, %42
br i1 %43, label %44, label %46
44: ; preds = %34
%45 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
br label %50
46: ; preds = %34
br label %47
47: ; preds = %46
%48 = load i32, i32* %4
%49 = add nsw i32 %48, 1
store i32 %49, i32* %4
br label %31
50: ; preds = %44, %31
%51 = load i32, i32* %4
%52 = icmp eq i32 %51, 500
br i1 %52, label %53, label %55
53: ; preds = %50
%54 = call i32 @printf(i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str.3, i64 0, i64 0))
br label %55
55: ; preds = %53, %50
ret i32 0
}

LLVM IR (-O2):
@.str = [10 x i8] c"teste.dat\00"
@.str.1 = [3 x i8] c"w+\00"
@str = [74 x i8] c"Teste de leitura e escrita foi bem sucedido!\0AVeja o que h\C3\A1 no teste.dat!\00"
@str.4 = [17 x i8] c"Algo deu errado!\00"
define i32 @main() {
%1 = alloca [500 x i32]
%2 = alloca [500 x i32]
%3 = bitcast [500 x i32]* %1 to i8*
%4 = bitcast [500 x i32]* %2 to i8*
br label %5
5: ; preds = %5, %0
%6 = phi i64 [ 0, %0 ], [ %20, %5 ]
%7 = phi <4 x i32> [ <i32 0, i32 1, i32 2, i32 3>, %0 ], [ %21, %5 ]
%8 = add <4 x i32> %7, <i32 4, i32 4, i32 4, i32 4>
%9 = getelementptr inbounds [500 x i32], [500 x i32]* %1, i64 0, i64 %6
%10 = bitcast i32* %9 to <4 x i32>*
store <4 x i32> %7, <4 x i32>* %10
%11 = getelementptr inbounds i32, i32* %9, i64 4
%12 = bitcast i32* %11 to <4 x i32>*
store <4 x i32> %8, <4 x i32>* %12
%13 = or i64 %6, 8
%14 = add <4 x i32> %7, <i32 8, i32 8, i32 8, i32 8>
%15 = add <4 x i32> %7, <i32 12, i32 12, i32 12, i32 12>
%16 = getelementptr inbounds [500 x i32], [500 x i32]* %1, i64 0, i64 %13
%17 = bitcast i32* %16 to <4 x i32>*
store <4 x i32> %14, <4 x i32>* %17
%18 = getelementptr inbounds i32, i32* %16, i64 4
%19 = bitcast i32* %18 to <4 x i32>*
store <4 x i32> %15, <4 x i32>* %19
%20 = add nuw nsw i64 %6, 16
%21 = add <4 x i32> %7, <i32 16, i32 16, i32 16, i32 16>
%22 = icmp eq i64 %20, 496
br i1 %22, label %23, label %5
23: ; preds = %5
%24 = getelementptr inbounds [500 x i32], [500 x i32]* %1, i64 0, i64 496
store i32 496, i32* %24
%25 = getelementptr inbounds [500 x i32], [500 x i32]* %1, i64 0, i64 497
store i32 497, i32* %25
%26 = getelementptr inbounds [500 x i32], [500 x i32]* %1, i64 0, i64 498
store i32 498, i32* %26
%27 = getelementptr inbounds [500 x i32], [500 x i32]* %1, i64 0, i64 499
store i32 499, i32* %27
%28 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%29 = tail call i32 @rewind(i32* %28)
%30 = getelementptr inbounds [500 x i32], [500 x i32]* %1, i64 0, i64 0
%31 = call i32 @fwrite(i32* %30, i32 4, i32 500, i32* %28)
%32 = tail call i32 @rewind(i32* %28)
%33 = getelementptr inbounds [500 x i32], [500 x i32]* %2, i64 0, i64 0
%34 = call i32 @fread(i32* %33, i32 4, i32 500, i32* %28)
%35 = tail call i32 @fclose(i32* %28)
br label %36
36: ; preds = %71, %23
%37 = phi i64 [ 0, %23 ], [ %72, %71 ]
%38 = getelementptr inbounds [500 x i32], [500 x i32]* %1, i64 0, i64 %37
%39 = load i32, i32* %38
%40 = getelementptr inbounds [500 x i32], [500 x i32]* %2, i64 0, i64 %37
%41 = load i32, i32* %40
%42 = icmp eq i32 %39, %41
br i1 %42, label %43, label %74
43: ; preds = %36
%44 = add nuw nsw i64 %37, 1
%45 = getelementptr inbounds [500 x i32], [500 x i32]* %1, i64 0, i64 %44
%46 = load i32, i32* %45
%47 = getelementptr inbounds [500 x i32], [500 x i32]* %2, i64 0, i64 %44
%48 = load i32, i32* %47
%49 = icmp eq i32 %46, %48
br i1 %49, label %50, label %74
50: ; preds = %43
%51 = add nuw nsw i64 %37, 2
%52 = getelementptr inbounds [500 x i32], [500 x i32]* %1, i64 0, i64 %51
%53 = load i32, i32* %52
%54 = getelementptr inbounds [500 x i32], [500 x i32]* %2, i64 0, i64 %51
%55 = load i32, i32* %54
%56 = icmp eq i32 %53, %55
br i1 %56, label %57, label %74
57: ; preds = %50
%58 = add nuw nsw i64 %37, 3
%59 = getelementptr inbounds [500 x i32], [500 x i32]* %1, i64 0, i64 %58
%60 = load i32, i32* %59
%61 = getelementptr inbounds [500 x i32], [500 x i32]* %2, i64 0, i64 %58
%62 = load i32, i32* %61
%63 = icmp eq i32 %60, %62
br i1 %63, label %64, label %74
64: ; preds = %57
%65 = add nuw nsw i64 %37, 4
%66 = getelementptr inbounds [500 x i32], [500 x i32]* %1, i64 0, i64 %65
%67 = load i32, i32* %66
%68 = getelementptr inbounds [500 x i32], [500 x i32]* %2, i64 0, i64 %65
%69 = load i32, i32* %68
%70 = icmp eq i32 %67, %69
br i1 %70, label %71, label %74
71: ; preds = %64
%72 = add nuw nsw i64 %37, 5
%73 = icmp eq i64 %72, 500
br i1 %73, label %74, label %36
74: ; preds = %71, %64, %57, %50, %43, %36
%75 = phi i8* [ getelementptr inbounds ([17 x i8], [17 x i8]* @str.4, i64 0, i64 0), %36 ], [ getelementptr inbounds ([17 x i8], [17 x i8]* @str.4, i64 0, i64 0), %43 ], [ getelementptr inbounds ([17 x i8], [17 x i8]* @str.4, i64 0, i64 0), %50 ], [ getelementptr inbounds ([17 x i8], [17 x i8]* @str.4, i64 0, i64 0), %57 ], [ getelementptr inbounds ([17 x i8], [17 x i8]* @str.4, i64 0, i64 0), %64 ], [ getelementptr inbounds ([74 x i8], [74 x i8]* @str, i64 0, i64 0), %71 ]
%76 = tail call i32 @puts(i8* dereferenceable(1) %75)
ret i32 0
}