#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*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, double);
double gerarNA(double, double, double, double);
scalar_t__ malloc(int);
int pow(int, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, ...);
int main() {
  int quantidade, i;
  char salvar = 'N';
  double multiplicador, semente, incremento, mod;
  double *resultados;
  multiplicador = 7727;
  semente = 5099;
  incremento = 4759;
  mod = pow(2, 31) - 1;
  printf("/nMetodo da Congruencia:");
  printf("\nDigite a quantidade de numeros a serem gerados: ");
  scanf(" %d", &quantidade);
  resultados = (double *)malloc(quantidade * sizeof(double));
  for (i = 0; i < quantidade; i++) {
    semente = gerarNA(multiplicador, semente, incremento, mod);
    resultados[i] = semente / (mod - 1.0);
    if (resultados[i] < 0)
      resultados[i] = -1 * resultados[i];
    printf("\n%7d: %.60f", i + 1, resultados[i]);
  }
  do {
    printf("\nDeseja gerar um arquivo? (S/N): ");
    scanf(" %c", &salvar);
  } while (salvar != 'S' && salvar != 'N');
  if (salvar == 'S') {
    FILE *arquivo = fopen("numerosaleatorios.csv", "w");
    if (arquivo == NULL) {
      printf("Erro ao abrir arquivo!\n");
      exit(1);
    }
    for (i = 0; i < quantidade; i++)
      fprintf(arquivo, "%.60f\n", resultados[i]);
    fclose(arquivo);
    printf("\nArquivo gerado com sucesso");
  }
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
movb   $0x4e,-0xd(%rbp)
movsd  0xe65(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xe50(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xe3b(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    $0x2,%edi
mov    $0x1f,%esi
call   10a0 <pow@plt>
sub    $0x1,%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x30(%rbp)
lea    0xe3c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe47(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe6b(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1080 <scanf@plt>
movslq -0x8(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x38(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    12e5 <main+0x155>
movsd  -0x18(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm2
movsd  -0x30(%rbp),%xmm3
call   1060 <gerarNA@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm1
movsd  0xdaf(%rip),%xmm2
subsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
mov    -0x38(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x38(%rbp),%rax
movslq -0xc(%rbp),%rcx
xorps  %xmm0,%xmm0
ucomisd (%rax,%rcx,8),%xmm0
jbe    12b6 <main+0x126>
mov    -0x38(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsd  0xd7c(%rip),%xmm0
mulsd  (%rax,%rcx,8),%xmm0
mov    -0x38(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0xc(%rbp),%esi
add    $0x1,%esi
mov    -0x38(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xda7(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    122d <main+0x9d>
jmp    12ea <main+0x15a>
lea    0xd92(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xda6(%rip),%rdi
lea    -0xd(%rbp),%rsi
mov    $0x0,%al
call   1080 <scanf@plt>
movsbl -0xd(%rbp),%ecx
xor    %eax,%eax
cmp    $0x53,%ecx
mov    %al,-0x41(%rbp)
je     1329 <main+0x199>
movsbl -0xd(%rbp),%eax
cmp    $0x4e,%eax
setne  %al
mov    %al,-0x41(%rbp)
mov    -0x41(%rbp),%al
test   $0x1,%al
jne    12ea <main+0x15a>
movsbl -0xd(%rbp),%eax
cmp    $0x53,%eax
jne    13d0 <main+0x240>
lea    0xd61(%rip),%rdi
lea    0xd70(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    137b <main+0x1eb>
lea    0xd57(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    13b9 <main+0x229>
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xd33(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1382 <main+0x1f2>
mov    -0x40(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xd17(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xd00(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x28,%rsp
movb   $0x4e,0xb(%rsp)
mov    $0x2,%edi
mov    $0x1f,%esi
call   10c0 <pow@plt>
mov    %eax,%ebx
lea    0xe68(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe73(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe97(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   10a0 <scanf@plt>
mov    0xc(%rsp),%edi
shl    $0x3,%edi
call   1090 <malloc@plt>
mov    %rax,%r14
cmpl   $0x0,0xc(%rsp)
jle    12c6 <main+0x116>
add    $0xffffffff,%ebx
cvtsi2sd %ebx,%xmm0
movsd  0xdd7(%rip),%xmm1
movsd  %xmm0,0x18(%rsp)
addsd  %xmm0,%xmm1
movsd  %xmm1,0x10(%rsp)
movsd  0xdc7(%rip),%xmm1
xor    %ebx,%ebx
lea    0xe45(%rip),%r15
nopw   0x0(%rax,%rax,1)
movsd  0xdb8(%rip),%xmm0
movsd  0xdb8(%rip),%xmm2
movsd  0x18(%rsp),%xmm3
call   1080 <gerarNA@plt>
movsd  %xmm0,0x20(%rsp)
movapd %xmm0,%xmm1
divsd  0x10(%rsp),%xmm1
movapd %xmm1,%xmm2
xorpd  0xda9(%rip),%xmm2
movapd %xmm1,%xmm0
cmpltsd 0xd8c(%rip),%xmm0
andpd  %xmm0,%xmm2
andnpd %xmm1,%xmm0
orpd   %xmm2,%xmm0
movlpd %xmm0,(%r14,%rbx,8)
add    $0x1,%rbx
mov    %r15,%rdi
mov    %ebx,%esi
mov    $0x1,%al
call   1060 <printf@plt>
movsd  0x20(%rsp),%xmm1
movslq 0xc(%rsp),%rax
cmp    %rax,%rbx
jl     1250 <main+0xa0>
lea    0xdce(%rip),%r15
lea    0xde9(%rip),%r12
lea    0xb(%rsp),%rbx
nopl   0x0(%rax)
mov    %r15,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   10a0 <scanf@plt>
movzbl 0xb(%rsp),%eax
cmp    $0x4e,%al
je     1365 <main+0x1b5>
cmp    $0x53,%al
jne    12e0 <main+0x130>
lea    0xdb6(%rip),%rdi
lea    0xdc5(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     137d <main+0x1cd>
mov    %rax,%r12
cmpl   $0x0,0xc(%rsp)
jle    134f <main+0x19f>
xor    %ebx,%ebx
lea    0xdaa(%rip),%r15
nop
movsd  (%r14,%rbx,8),%xmm0
mov    %r12,%rdi
mov    %r15,%rsi
call   1070 <fprintf@plt>
add    $0x1,%rbx
movslq 0xc(%rsp),%rax
cmp    %rax,%rbx
jl     1330 <main+0x180>
mov    %r12,%rdi
call   1050 <fclose@plt>
lea    0xd82(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xd78(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
@.str = [25 x i8] c"/nMetodo da Congruencia:\00"
@.str.1 = [50 x i8] c"\0ADigite a quantidade de numeros a serem gerados: \00"
@.str.2 = [4 x i8] c" %d\00"
@.str.3 = [12 x i8] c"\0A%7d: %.60f\00"
@.str.4 = [34 x i8] c"\0ADeseja gerar um arquivo? (S/N): \00"
@.str.5 = [4 x i8] c" %c\00"
@.str.6 = [22 x i8] c"numerosaleatorios.csv\00"
@.str.7 = [2 x i8] c"w\00"
@.str.8 = [24 x i8] c"Erro ao abrir arquivo!\0A\00"
@.str.9 = [7 x i8] c"%.60f\0A\00"
@.str.10 = [28 x i8] c"\0AArquivo gerado com sucesso\00"
@.str.11 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double*
%10 = alloca i32*
store i32 0, i32* %1
store i8 78, i8* %4
store double 7.727000e+03, double* %5
store double 5.099000e+03, double* %6
store double 4.759000e+03, double* %7
%11 = call i32 @pow(i32 2, i32 31)
%12 = sub nsw i32 %11, 1
%13 = sitofp i32 %12 to double
store double %13, double* %8
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.1, i64 0, i64 0))
%16 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%17 = load i32, i32* %2
%18 = sext i32 %17 to i64
%19 = mul i64 %18, 8
%20 = trunc i64 %19 to i32
%21 = call i64 @malloc(i32 %20)
%22 = inttoptr i64 %21 to double*
store double* %22, double** %9
store i32 0, i32* %3
br label %23
23: ; preds = %67, %0
%24 = load i32, i32* %3
%25 = load i32, i32* %2
%26 = icmp slt i32 %24, %25
br i1 %26, label %27, label %70
27: ; preds = %23
%28 = load double, double* %5
%29 = load double, double* %6
%30 = load double, double* %7
%31 = load double, double* %8
%32 = call double @gerarNA(double %28, double %29, double %30, double %31)
store double %32, double* %6
%33 = load double, double* %6
%34 = load double, double* %8
%35 = fsub double %34, 1.000000e+00
%36 = fdiv double %33, %35
%37 = load double*, double** %9
%38 = load i32, i32* %3
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds double, double* %37, i64 %39
store double %36, double* %40
%41 = load double*, double** %9
%42 = load i32, i32* %3
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds double, double* %41, i64 %43
%45 = load double, double* %44
%46 = fcmp olt double %45, 0.000000e+00
br i1 %46, label %47, label %58
47: ; preds = %27
%48 = load double*, double** %9
%49 = load i32, i32* %3
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds double, double* %48, i64 %50
%52 = load double, double* %51
%53 = fmul double -1.000000e+00, %52
%54 = load double*, double** %9
%55 = load i32, i32* %3
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds double, double* %54, i64 %56
store double %53, double* %57
br label %58
58: ; preds = %47, %27
%59 = load i32, i32* %3
%60 = add nsw i32 %59, 1
%61 = load double*, double** %9
%62 = load i32, i32* %3
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds double, double* %61, i64 %63
%65 = load double, double* %64
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 %60, double %65)
br label %67
67: ; preds = %58
%68 = load i32, i32* %3
%69 = add nsw i32 %68, 1
store i32 %69, i32* %3
br label %23
70: ; preds = %23
br label %71
71: ; preds = %82, %70
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0))
%73 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %4)
br label %74
74: ; preds = %71
%75 = load i8, i8* %4
%76 = sext i8 %75 to i32
%77 = icmp ne i32 %76, 83
br i1 %77, label %78, label %82
78: ; preds = %74
%79 = load i8, i8* %4
%80 = sext i8 %79 to i32
%81 = icmp ne i32 %80, 78
br label %82
82: ; preds = %78, %74
%83 = phi i1 [ false, %74 ], [ %81, %78 ]
br i1 %83, label %71, label %84
84: ; preds = %82
%85 = load i8, i8* %4
%86 = sext i8 %85 to i32
%87 = icmp eq i32 %86, 83
br i1 %87, label %88, label %115
88: ; preds = %84
%89 = call i32* @fopen(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
store i32* %89, i32** %10
%90 = load i32*, i32** %10
%91 = icmp eq i32* %90, null
br i1 %91, label %92, label %95
92: ; preds = %88
%93 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.8, i64 0, i64 0))
%94 = call i32 @exit(i32 1)
unreachable
95: ; preds = %88
store i32 0, i32* %3
br label %96
96: ; preds = %108, %95
%97 = load i32, i32* %3
%98 = load i32, i32* %2
%99 = icmp slt i32 %97, %98
br i1 %99, label %100, label %111
100: ; preds = %96
%101 = load i32*, i32** %10
%102 = load double*, double** %9
%103 = load i32, i32* %3
%104 = sext i32 %103 to i64
%105 = getelementptr inbounds double, double* %102, i64 %104
%106 = load double, double* %105
%107 = call i32 @fprintf(i32* %101, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0), double %106)
br label %108
108: ; preds = %100
%109 = load i32, i32* %3
%110 = add nsw i32 %109, 1
store i32 %110, i32* %3
br label %96
111: ; preds = %96
%112 = load i32*, i32** %10
%113 = call i32 @fclose(i32* %112)
%114 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.10, i64 0, i64 0))
br label %115
115: ; preds = %111, %84
%116 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.11, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [25 x i8] c"/nMetodo da Congruencia:\00"
@.str.1 = [50 x i8] c"\0ADigite a quantidade de numeros a serem gerados: \00"
@.str.2 = [4 x i8] c" %d\00"
@.str.3 = [12 x i8] c"\0A%7d: %.60f\00"
@.str.4 = [34 x i8] c"\0ADeseja gerar um arquivo? (S/N): \00"
@.str.5 = [4 x i8] c" %c\00"
@.str.6 = [22 x i8] c"numerosaleatorios.csv\00"
@.str.7 = [2 x i8] c"w\00"
@.str.9 = [7 x i8] c"%.60f\0A\00"
@.str.10 = [28 x i8] c"\0AArquivo gerado com sucesso\00"
@str = [23 x i8] c"Erro ao abrir arquivo!\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8
%3 = bitcast i32* %1 to i8*
store i8 78, i8* %2
%4 = tail call i32 @pow(i32 2, i32 31)
%5 = add nsw i32 %4, -1
%6 = sitofp i32 %5 to double
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @.str.1, i64 0, i64 0))
%9 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%10 = load i32, i32* %1
%11 = shl i32 %10, 3
%12 = call i64 @malloc(i32 %11)
%13 = inttoptr i64 %12 to double*
%14 = load i32, i32* %1
%15 = icmp sgt i32 %14, 0
br i1 %15, label %16, label %33
16: ; preds = %0
%17 = fadd double %6, -1.000000e+00
br label %18
18: ; preds = %16, %18
%19 = phi i64 [ 0, %16 ], [ %27, %18 ]
%20 = phi double [ 5.099000e+03, %16 ], [ %21, %18 ]
%21 = call double @gerarNA(double 7.727000e+03, double %20, double 4.759000e+03, double %6)
%22 = fdiv double %21, %17
%23 = getelementptr inbounds double, double* %13, i64 %19
%24 = fcmp olt double %22, 0.000000e+00
%25 = fneg double %22
%26 = select i1 %24, double %25, double %22
store double %26, double* %23
%27 = add nuw nsw i64 %19, 1
%28 = trunc i64 %27 to i32
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 %28, double %26)
%30 = load i32, i32* %1
%31 = sext i32 %30 to i64
%32 = icmp slt i64 %27, %31
br i1 %32, label %18, label %33
33: ; preds = %18, %0
br label %34
34: ; preds = %33, %34
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0))
%36 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %2)
%37 = load i8, i8* %2
switch i8 %37, label %34 [
i8 83, label %38
i8 78, label %59
]
38: ; preds = %34
%39 = call i32* @fopen(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%40 = icmp eq i32* %39, null
br i1 %40, label %44, label %41
41: ; preds = %38
%42 = load i32, i32* %1
%43 = icmp sgt i32 %42, 0
br i1 %43, label %47, label %56
44: ; preds = %38
%45 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
%46 = call i32 @exit(i32 1)
unreachable
47: ; preds = %41, %47
%48 = phi i64 [ %52, %47 ], [ 0, %41 ]
%49 = getelementptr inbounds double, double* %13, i64 %48
%50 = load double, double* %49
%51 = call i32 @fprintf(i32* %39, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0), double %50)
%52 = add nuw nsw i64 %48, 1
%53 = load i32, i32* %1
%54 = sext i32 %53 to i64
%55 = icmp slt i64 %52, %54
br i1 %55, label %47, label %56
56: ; preds = %47, %41
%57 = call i32 @fclose(i32* %39)
%58 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.10, i64 0, i64 0))
br label %59
59: ; preds = %34, %56
%60 = call i32 @putchar(i32 10)
ret i32 0
}