#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int);
scalar_t__ fscanf(int /*<<< orphan*/ *, char *, int *);
int /*<<< orphan*/ printf(char *, ...);
int rand();
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
void ex1() {
  srand(time(NULL));
  FILE *aula;
  aula = fopen("aula.txt", "w+");
  for (int k = 0; k < 10; k++)
    fprintf(aula, "I like %d peannuts.\n", rand() % 6000);
  rewind(aula);
  char teste[10][25];
  for (int k = 0; k < 10; k++) {
    fgets(teste[k], 25, aula);
    printf("%s\n", teste[k]);
  }
  rewind(aula);
  int a;
  while (fscanf(aula, "%*s %*s %d %*s\n", &a) != EOF)
    printf("%d\n", a);
  fclose(aula);
}


x86 assembly (clang, -O0):
<ex1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
xor    %eax,%eax
mov    %eax,%edi
call   10a0 <time@plt>
mov    %eax,%edi
call   1070 <srand@plt>
lea    0xe3e(%rip),%rdi
lea    0xe40(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0xa,-0xc(%rbp)
jge    121e <ex1+0x7e>
mov    -0x8(%rbp),%rax
mov    %rax,-0x120(%rbp)
mov    $0x0,%al
call   10c0 <rand@plt>
mov    -0x120(%rbp),%rdi
mov    $0x1770,%ecx
cltd
idiv   %ecx
lea    0xe01(%rip),%rsi
call   1090 <fprintf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11d9 <ex1+0x39>
mov    -0x8(%rbp),%rdi
call   1050 <rewind@plt>
movl   $0x0,-0x114(%rbp)
cmpl   $0xa,-0x114(%rbp)
jge    1298 <ex1+0xf8>
movslq -0x114(%rbp),%rax
lea    -0x110(%rbp),%rdi
imul   $0x19,%rax,%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rdx
mov    $0x19,%esi
call   1080 <fgets@plt>
movslq -0x114(%rbp),%rax
lea    -0x110(%rbp),%rsi
imul   $0x19,%rax,%rax
add    %rax,%rsi
lea    0xda4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x114(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x114(%rbp)
jmp    1231 <ex1+0x91>
mov    -0x8(%rbp),%rdi
call   1050 <rewind@plt>
mov    -0x8(%rbp),%rdi
lea    0xd79(%rip),%rsi
lea    -0x118(%rbp),%rdx
call   1060 <fscanf@plt>
mov    0x2d29(%rip),%rcx
cmp    (%rcx),%rax
je     12e1 <ex1+0x141>
mov    -0x118(%rbp),%esi
lea    0xd60(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12a1 <ex1+0x101>
mov    -0x8(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ex1>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x110,%rsp
xor    %edi,%edi
call   10b0 <time@plt>
mov    %eax,%edi
call   1080 <srand@plt>
lea    0xe2b(%rip),%rdi
lea    0xe2d(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,%r15
xor    %eax,%eax
call   10d0 <rand@plt>
movslq %eax,%rdx
imul   $0x57619f1,%rdx,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x27,%rax
add    %ecx,%eax
imul   $0x1770,%eax,%eax
sub    %eax,%edx
lea    0xdfb(%rip),%r14
mov    %r15,%rdi
mov    %r14,%rsi
call   10a0 <fprintf@plt>
xor    %eax,%eax
call   10d0 <rand@plt>
movslq %eax,%rdx
imul   $0x57619f1,%rdx,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x27,%rax
add    %ecx,%eax
imul   $0x1770,%eax,%eax
sub    %eax,%edx
mov    %r15,%rdi
mov    %r14,%rsi
call   10a0 <fprintf@plt>
xor    %eax,%eax
call   10d0 <rand@plt>
movslq %eax,%rdx
imul   $0x57619f1,%rdx,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x27,%rax
add    %ecx,%eax
imul   $0x1770,%eax,%eax
sub    %eax,%edx
mov    %r15,%rdi
mov    %r14,%rsi
call   10a0 <fprintf@plt>
xor    %eax,%eax
call   10d0 <rand@plt>
movslq %eax,%rdx
imul   $0x57619f1,%rdx,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x27,%rax
add    %ecx,%eax
imul   $0x1770,%eax,%eax
sub    %eax,%edx
mov    %r15,%rdi
mov    %r14,%rsi
call   10a0 <fprintf@plt>
xor    %eax,%eax
call   10d0 <rand@plt>
movslq %eax,%rdx
imul   $0x57619f1,%rdx,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x27,%rax
add    %ecx,%eax
imul   $0x1770,%eax,%eax
sub    %eax,%edx
mov    %r15,%rdi
mov    %r14,%rsi
call   10a0 <fprintf@plt>
xor    %eax,%eax
call   10d0 <rand@plt>
movslq %eax,%rdx
imul   $0x57619f1,%rdx,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x27,%rax
add    %ecx,%eax
imul   $0x1770,%eax,%eax
sub    %eax,%edx
mov    %r15,%rdi
mov    %r14,%rsi
call   10a0 <fprintf@plt>
xor    %eax,%eax
call   10d0 <rand@plt>
movslq %eax,%rdx
imul   $0x57619f1,%rdx,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x27,%rax
add    %ecx,%eax
imul   $0x1770,%eax,%eax
sub    %eax,%edx
mov    %r15,%rdi
mov    %r14,%rsi
call   10a0 <fprintf@plt>
xor    %eax,%eax
call   10d0 <rand@plt>
movslq %eax,%rdx
imul   $0x57619f1,%rdx,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x27,%rax
add    %ecx,%eax
imul   $0x1770,%eax,%eax
sub    %eax,%edx
mov    %r15,%rdi
mov    %r14,%rsi
call   10a0 <fprintf@plt>
xor    %eax,%eax
call   10d0 <rand@plt>
movslq %eax,%rdx
imul   $0x57619f1,%rdx,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x27,%rax
add    %ecx,%eax
imul   $0x1770,%eax,%eax
sub    %eax,%edx
mov    %r15,%rdi
mov    %r14,%rsi
call   10a0 <fprintf@plt>
xor    %eax,%eax
call   10d0 <rand@plt>
movslq %eax,%rdx
imul   $0x57619f1,%rdx,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x27,%rax
add    %ecx,%eax
imul   $0x1770,%eax,%eax
sub    %eax,%edx
mov    %r15,%rdi
mov    %r14,%rsi
call   10a0 <fprintf@plt>
mov    %r15,%rdi
call   1060 <rewind@plt>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x19,%esi
mov    %r15,%rdx
call   1090 <fgets@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
lea    0x29(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x19,%esi
mov    %r15,%rdx
call   1090 <fgets@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
lea    0x42(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x19,%esi
mov    %r15,%rdx
call   1090 <fgets@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
lea    0x5b(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x19,%esi
mov    %r15,%rdx
call   1090 <fgets@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
lea    0x74(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x19,%esi
mov    %r15,%rdx
call   1090 <fgets@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
lea    0x8d(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x19,%esi
mov    %r15,%rdx
call   1090 <fgets@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
lea    0xa6(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x19,%esi
mov    %r15,%rdx
call   1090 <fgets@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
lea    0xbf(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x19,%esi
mov    %r15,%rdx
call   1090 <fgets@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
lea    0xd8(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x19,%esi
mov    %r15,%rdx
call   1090 <fgets@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
lea    0xf1(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x19,%esi
mov    %r15,%rdx
call   1090 <fgets@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    %r15,%rdi
call   1060 <rewind@plt>
lea    0xb04(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %r15,%rdi
call   1070 <fscanf@plt>
mov    0x2ab7(%rip),%r13
cmp    0x0(%r13),%rax
je     1572 <ex1+0x3c2>
lea    0xaf3(%rip),%r14
lea    0xadc(%rip),%r12
lea    0xc(%rsp),%rbx
nopw   0x0(%rax,%rax,1)
mov    0xc(%rsp),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1070 <fscanf@plt>
cmp    0x0(%r13),%rax
jne    1550 <ex1+0x3a0>
mov    %r15,%rdi
call   1040 <fclose@plt>
add    $0x110,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [9 x i8] c"aula.txt\00"
@.str.1 = [3 x i8] c"w+\00"
@.str.2 = [21 x i8] c"I like %d peannuts.\0A\00"
@.str.3 = [4 x i8] c"%s\0A\00"
@.str.4 = [16 x i8] c"%*s %*s %d %*s\0A\00"
@EOF = global i64 0
@.str.5 = [4 x i8] c"%d\0A\00"
define void @ex1() {
%1 = alloca i32*
%2 = alloca i32
%3 = alloca [10 x [25 x i8]]
%4 = alloca i32
%5 = alloca i32
%6 = call i32 @time(i32* null)
%7 = call i32 @srand(i32 %6)
%8 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %8, i32** %1
store i32 0, i32* %2
br label %9
9: ; preds = %17, %0
%10 = load i32, i32* %2
%11 = icmp slt i32 %10, 10
br i1 %11, label %12, label %20
12: ; preds = %9
%13 = load i32*, i32** %1
%14 = call i32 (...) @rand()
%15 = srem i32 %14, 6000
%16 = call i32 @fprintf(i32* %13, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %15)
br label %17
17: ; preds = %12
%18 = load i32, i32* %2
%19 = add nsw i32 %18, 1
store i32 %19, i32* %2
br label %9
20: ; preds = %9
%21 = load i32*, i32** %1
%22 = call i32 @rewind(i32* %21)
store i32 0, i32* %4
br label %23
23: ; preds = %38, %20
%24 = load i32, i32* %4
%25 = icmp slt i32 %24, 10
br i1 %25, label %26, label %41
26: ; preds = %23
%27 = load i32, i32* %4
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [10 x [25 x i8]], [10 x [25 x i8]]* %3, i64 0, i64 %28
%30 = getelementptr inbounds [25 x i8], [25 x i8]* %29, i64 0, i64 0
%31 = load i32*, i32** %1
%32 = call i32 @fgets(i8* %30, i32 25, i32* %31)
%33 = load i32, i32* %4
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [10 x [25 x i8]], [10 x [25 x i8]]* %3, i64 0, i64 %34
%36 = getelementptr inbounds [25 x i8], [25 x i8]* %35, i64 0, i64 0
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %36)
br label %38
38: ; preds = %26
%39 = load i32, i32* %4
%40 = add nsw i32 %39, 1
store i32 %40, i32* %4
br label %23
41: ; preds = %23
%42 = load i32*, i32** %1
%43 = call i32 @rewind(i32* %42)
br label %44
44: ; preds = %49, %41
%45 = load i32*, i32** %1
%46 = call i64 @fscanf(i32* %45, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i32* %5)
%47 = load i64, i64* @EOF
%48 = icmp ne i64 %46, %47
br i1 %48, label %49, label %52
49: ; preds = %44
%50 = load i32, i32* %5
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %50)
br label %44
52: ; preds = %44
%53 = load i32*, i32** %1
%54 = call i32 @fclose(i32* %53)
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c"aula.txt\00"
@.str.1 = [3 x i8] c"w+\00"
@.str.2 = [21 x i8] c"I like %d peannuts.\0A\00"
@.str.4 = [16 x i8] c"%*s %*s %d %*s\0A\00"
@EOF = global i64 0
@.str.5 = [4 x i8] c"%d\0A\00"
define void @ex1() {
%1 = alloca [10 x [25 x i8]]
%2 = alloca i32
%3 = tail call i32 @time(i32* null)
%4 = tail call i32 @srand(i32 %3)
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%6 = tail call i32 (...) @rand()
%7 = srem i32 %6, 6000
%8 = tail call i32 @fprintf(i32* %5, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %7)
%9 = tail call i32 (...) @rand()
%10 = srem i32 %9, 6000
%11 = tail call i32 @fprintf(i32* %5, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %10)
%12 = tail call i32 (...) @rand()
%13 = srem i32 %12, 6000
%14 = tail call i32 @fprintf(i32* %5, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %13)
%15 = tail call i32 (...) @rand()
%16 = srem i32 %15, 6000
%17 = tail call i32 @fprintf(i32* %5, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %16)
%18 = tail call i32 (...) @rand()
%19 = srem i32 %18, 6000
%20 = tail call i32 @fprintf(i32* %5, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %19)
%21 = tail call i32 (...) @rand()
%22 = srem i32 %21, 6000
%23 = tail call i32 @fprintf(i32* %5, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %22)
%24 = tail call i32 (...) @rand()
%25 = srem i32 %24, 6000
%26 = tail call i32 @fprintf(i32* %5, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %25)
%27 = tail call i32 (...) @rand()
%28 = srem i32 %27, 6000
%29 = tail call i32 @fprintf(i32* %5, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %28)
%30 = tail call i32 (...) @rand()
%31 = srem i32 %30, 6000
%32 = tail call i32 @fprintf(i32* %5, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %31)
%33 = tail call i32 (...) @rand()
%34 = srem i32 %33, 6000
%35 = tail call i32 @fprintf(i32* %5, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %34)
%36 = tail call i32 @rewind(i32* %5)
%37 = getelementptr inbounds [10 x [25 x i8]], [10 x [25 x i8]]* %1, i64 0, i64 0, i64 0
%38 = call i32 @fgets(i8* %37, i32 25, i32* %5)
%39 = call i32 @puts(i8* %37)
%40 = getelementptr inbounds [10 x [25 x i8]], [10 x [25 x i8]]* %1, i64 0, i64 1, i64 0
%41 = call i32 @fgets(i8* %40, i32 25, i32* %5)
%42 = call i32 @puts(i8* %40)
%43 = getelementptr inbounds [10 x [25 x i8]], [10 x [25 x i8]]* %1, i64 0, i64 2, i64 0
%44 = call i32 @fgets(i8* %43, i32 25, i32* %5)
%45 = call i32 @puts(i8* %43)
%46 = getelementptr inbounds [10 x [25 x i8]], [10 x [25 x i8]]* %1, i64 0, i64 3, i64 0
%47 = call i32 @fgets(i8* %46, i32 25, i32* %5)
%48 = call i32 @puts(i8* %46)
%49 = getelementptr inbounds [10 x [25 x i8]], [10 x [25 x i8]]* %1, i64 0, i64 4, i64 0
%50 = call i32 @fgets(i8* %49, i32 25, i32* %5)
%51 = call i32 @puts(i8* %49)
%52 = getelementptr inbounds [10 x [25 x i8]], [10 x [25 x i8]]* %1, i64 0, i64 5, i64 0
%53 = call i32 @fgets(i8* %52, i32 25, i32* %5)
%54 = call i32 @puts(i8* %52)
%55 = getelementptr inbounds [10 x [25 x i8]], [10 x [25 x i8]]* %1, i64 0, i64 6, i64 0
%56 = call i32 @fgets(i8* %55, i32 25, i32* %5)
%57 = call i32 @puts(i8* %55)
%58 = getelementptr inbounds [10 x [25 x i8]], [10 x [25 x i8]]* %1, i64 0, i64 7, i64 0
%59 = call i32 @fgets(i8* %58, i32 25, i32* %5)
%60 = call i32 @puts(i8* %58)
%61 = getelementptr inbounds [10 x [25 x i8]], [10 x [25 x i8]]* %1, i64 0, i64 8, i64 0
%62 = call i32 @fgets(i8* %61, i32 25, i32* %5)
%63 = call i32 @puts(i8* %61)
%64 = getelementptr inbounds [10 x [25 x i8]], [10 x [25 x i8]]* %1, i64 0, i64 9, i64 0
%65 = call i32 @fgets(i8* %64, i32 25, i32* %5)
%66 = call i32 @puts(i8* %64)
%67 = call i32 @rewind(i32* %5)
%68 = bitcast i32* %2 to i8*
%69 = call i64 @fscanf(i32* %5, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i32* %2)
%70 = load i64, i64* @EOF
%71 = icmp eq i64 %69, %70
br i1 %71, label %78, label %72
72: ; preds = %0, %72
%73 = load i32, i32* %2
%74 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %73)
%75 = call i64 @fscanf(i32* %5, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i32* %2)
%76 = load i64, i64* @EOF
%77 = icmp eq i64 %75, %76
br i1 %77, label %78, label %72
78: ; preds = %72, %0
%79 = call i32 @fclose(i32* %5)
ret void
}