#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 atoi(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ printf(char *);
scalar_t__ rand_double();
double sqrt(int);
int /*<<< orphan*/ stderr;
void pseudo_gauss(int argc, char *argv[]) {
  FILE *f = NULL;
  int count;
  int i, j, k, m;
  double rnd;
  if (argc != 5) {
    fprintf(stderr,
            "Error: missing output file name and points number.\nFormat: "
            "simulate_data <type - (gauss | ps_gauss> <file_name> "
            "<number_of_point> <number_of_rnd_components>\n");
    exit(-1);
  }
  f = fopen(argv[2], "w");
  if (f == NULL) {
    printf("Error opening file for write!\n");
    exit(1);
  }
  count = atoi(argv[3]);
  k = atoi(argv[4]);
  m = 2 * k;
  fprintf(f, "#%d\n", count);
  for (i = 0; i < count; i++) {
    rnd = 0;
    for (j = 0; j < m; j++) {
      rnd += rand_double();
    }
    rnd -= k;
    rnd /= sqrt(m / 12.);
    fprintf(f, "%f\n", rnd);
  }
  fclose(f);
}


x86 assembly (clang, -O0):
<pseudo_gauss>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
cmpl   $0x5,-0x4(%rbp)
je     11c3 <pseudo_gauss+0x43>
mov    0x2e38(%rip),%rax
movslq (%rax),%rdi
lea    0xe56(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xed4(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11fc <pseudo_gauss+0x7c>
lea    0xebb(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%edx
lea    0xe94(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    12ef <pseudo_gauss+0x16f>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    128c <pseudo_gauss+0x10c>
mov    $0x0,%al
call   1050 <rand_double@plt>
cvtsi2sd %rax,%xmm0
addsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    125c <pseudo_gauss+0xdc>
cvtsi2sdl -0x28(%rbp),%xmm1
movsd  -0x38(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
cvtsi2sdl -0x2c(%rbp),%xmm0
movsd  0xd54(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1090 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x38(%rbp),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
movsd  -0x38(%rbp),%xmm0
lea    0xdf2(%rip),%rsi
mov    $0x1,%al
call   1060 <fprintf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1241 <pseudo_gauss+0xc1>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pseudo_gauss>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
cmp    $0x5,%edi
jne    12c5 <pseudo_gauss+0x135>
mov    %rsi,%rbx
mov    0x10(%rsi),%rdi
lea    0xef1(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     12ef <pseudo_gauss+0x15f>
mov    %rax,%r14
mov    0x18(%rbx),%rdi
call   1080 <atoi@plt>
mov    %eax,%r15d
mov    0x20(%rbx),%rdi
call   1080 <atoi@plt>
mov    %eax,%ebx
lea    0xec4(%rip),%rsi
mov    %r14,%rdi
mov    %r15d,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
test   %r15d,%r15d
jle    12af <pseudo_gauss+0x11f>
lea    (%rbx,%rbx,1),%eax
cvtsi2sd %ebx,%xmm0
movsd  %xmm0,0x10(%rsp)
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
divsd  0xdea(%rip),%xmm0
cvttsd2si %xmm0,%ebp
cmp    $0x2,%eax
mov    $0x1,%ecx
cmovge %eax,%ecx
mov    %ecx,0xc(%rsp)
xor    %r12d,%r12d
jmp    1269 <pseudo_gauss+0xd9>
xchg   %ax,%ax
subsd  0x10(%rsp),%xmm0
movsd  %xmm0,(%rsp)
mov    %ebp,%edi
call   1090 <sqrt@plt>
movsd  (%rsp),%xmm1
divsd  %xmm0,%xmm1
mov    %r14,%rdi
lea    0xe58(%rip),%rsi
movapd %xmm1,%xmm0
mov    $0x1,%al
call   1060 <fprintf@plt>
add    $0x1,%r12d
cmp    %r15d,%r12d
je     12af <pseudo_gauss+0x11f>
xorpd  %xmm0,%xmm0
test   %ebx,%ebx
jle    1230 <pseudo_gauss+0xa0>
mov    0xc(%rsp),%r13d
cs nopw 0x0(%rax,%rax,1)
movsd  %xmm0,(%rsp)
xor    %eax,%eax
call   1050 <rand_double@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  (%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
movsd  (%rsp),%xmm0
add    $0xffffffff,%r13d
jne    1280 <pseudo_gauss+0xf0>
jmp    1230 <pseudo_gauss+0xa0>
mov    %r14,%rdi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <fclose@plt>
mov    0x2d14(%rip),%rax
movslq (%rax),%rcx
lea    0xd32(%rip),%rdi
mov    $0x9d,%esi
mov    $0x1,%edx
call   10b0 <fwrite@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
lea    0xdbb(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [158 x i8] c"Error: missing output file name and points number.\0AFormat: simulate_data <type - (gauss | ps_gauss> <file_name> <number_of_point> <number_of_rnd_components>\0A\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [31 x i8] c"Error opening file for write!\0A\00"
@.str.3 = [5 x i8] c"#%d\0A\00"
@.str.4 = [4 x i8] c"%f\0A\00"
define void @pseudo_gauss(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca double
store i32 %0, i32* %3
store i8** %1, i8*** %4
store i32* null, i32** %5
%12 = load i32, i32* %3
%13 = icmp ne i32 %12, 5
br i1 %13, label %14, label %20
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = sext i32 %15 to i64
%17 = inttoptr i64 %16 to i32*
%18 = call i32 (i32*, i8*, ...) @fprintf(i32* %17, i8* getelementptr inbounds ([158 x i8], [158 x i8]* @.str, i64 0, i64 0))
%19 = call i32 @exit(i32 -1)
unreachable
20: ; preds = %2
%21 = load i8**, i8*** %4
%22 = getelementptr inbounds i8*, i8** %21, i64 2
%23 = load i8*, i8** %22
%24 = call i32* @fopen(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %24, i32** %5
%25 = load i32*, i32** %5
%26 = icmp eq i32* %25, null
br i1 %26, label %27, label %30
27: ; preds = %20
%28 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %20
%31 = load i8**, i8*** %4
%32 = getelementptr inbounds i8*, i8** %31, i64 3
%33 = load i8*, i8** %32
%34 = call i32 @atoi(i8* %33)
store i32 %34, i32* %6
%35 = load i8**, i8*** %4
%36 = getelementptr inbounds i8*, i8** %35, i64 4
%37 = load i8*, i8** %36
%38 = call i32 @atoi(i8* %37)
store i32 %38, i32* %9
%39 = load i32, i32* %9
%40 = mul nsw i32 2, %39
store i32 %40, i32* %10
%41 = load i32*, i32** %5
%42 = load i32, i32* %6
%43 = call i32 (i32*, i8*, ...) @fprintf(i32* %41, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %42)
store i32 0, i32* %7
br label %44
44: ; preds = %76, %30
%45 = load i32, i32* %7
%46 = load i32, i32* %6
%47 = icmp slt i32 %45, %46
br i1 %47, label %48, label %79
48: ; preds = %44
store double 0.000000e+00, double* %11
store i32 0, i32* %8
br label %49
49: ; preds = %58, %48
%50 = load i32, i32* %8
%51 = load i32, i32* %10
%52 = icmp slt i32 %50, %51
br i1 %52, label %53, label %61
53: ; preds = %49
%54 = call i64 (...) @rand_double()
%55 = sitofp i64 %54 to double
%56 = load double, double* %11
%57 = fadd double %56, %55
store double %57, double* %11
br label %58
58: ; preds = %53
%59 = load i32, i32* %8
%60 = add nsw i32 %59, 1
store i32 %60, i32* %8
br label %49
61: ; preds = %49
%62 = load i32, i32* %9
%63 = sitofp i32 %62 to double
%64 = load double, double* %11
%65 = fsub double %64, %63
store double %65, double* %11
%66 = load i32, i32* %10
%67 = sitofp i32 %66 to double
%68 = fdiv double %67, 1.200000e+01
%69 = fptosi double %68 to i32
%70 = call double @sqrt(i32 %69)
%71 = load double, double* %11
%72 = fdiv double %71, %70
store double %72, double* %11
%73 = load i32*, i32** %5
%74 = load double, double* %11
%75 = call i32 (i32*, i8*, ...) @fprintf(i32* %73, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), double %74)
br label %76
76: ; preds = %61
%77 = load i32, i32* %7
%78 = add nsw i32 %77, 1
store i32 %78, i32* %7
br label %44
79: ; preds = %44
%80 = load i32*, i32** %5
%81 = call i32 @fclose(i32* %80)
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [158 x i8] c"Error: missing output file name and points number.\0AFormat: simulate_data <type - (gauss | ps_gauss> <file_name> <number_of_point> <number_of_rnd_components>\0A\00"
@.str.1 = [2 x i8] c"w\00"
@.str.3 = [5 x i8] c"#%d\0A\00"
@.str.4 = [4 x i8] c"%f\0A\00"
@str = [30 x i8] c"Error opening file for write!\00"
define void @pseudo_gauss(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 5
br i1 %3, label %10, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = sext i32 %5 to i64
%7 = inttoptr i64 %6 to i32*
%8 = tail call i64 @fwrite(i8* getelementptr inbounds ([158 x i8], [158 x i8]* @.str, i64 0, i64 0), i64 157, i64 1, i32* %7)
%9 = tail call i32 @exit(i32 -1)
unreachable
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 2
%12 = load i8*, i8** %11
%13 = tail call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %18
15: ; preds = %10
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str, i64 0, i64 0))
%17 = tail call i32 @exit(i32 1)
unreachable
18: ; preds = %10
%19 = getelementptr inbounds i8*, i8** %1, i64 3
%20 = load i8*, i8** %19
%21 = tail call i32 @atoi(i8* %20)
%22 = getelementptr inbounds i8*, i8** %1, i64 4
%23 = load i8*, i8** %22
%24 = tail call i32 @atoi(i8* %23)
%25 = shl i32 %24, 1
%26 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %13, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %21)
%27 = icmp sgt i32 %21, 0
br i1 %27, label %28, label %53
28: ; preds = %18
%29 = icmp sgt i32 %24, 0
%30 = sitofp i32 %24 to double
%31 = sitofp i32 %25 to double
%32 = fdiv double %31, 1.200000e+01
%33 = fptosi double %32 to i32
%34 = call i32 @llvm.smax.i32(i32 %25, i32 1)
br label %35
35: ; preds = %28, %45
%36 = phi i32 [ 0, %28 ], [ %51, %45 ]
br i1 %29, label %37, label %45
37: ; preds = %35, %37
%38 = phi double [ %42, %37 ], [ 0.000000e+00, %35 ]
%39 = phi i32 [ %43, %37 ], [ 0, %35 ]
%40 = tail call i64 (...) @rand_double()
%41 = sitofp i64 %40 to double
%42 = fadd double %38, %41
%43 = add nuw nsw i32 %39, 1
%44 = icmp eq i32 %43, %34
br i1 %44, label %45, label %37
45: ; preds = %37, %35
%46 = phi double [ 0.000000e+00, %35 ], [ %42, %37 ]
%47 = fsub double %46, %30
%48 = tail call double @sqrt(i32 %33)
%49 = fdiv double %47, %48
%50 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %13, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), double %49)
%51 = add nuw nsw i32 %36, 1
%52 = icmp eq i32 %51, %21
br i1 %52, label %53, label %35
53: ; preds = %45, %18
%54 = tail call i32 @fclose(i32* %13)
ret void
}