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


x86 assembly (clang, -O0):
<gauss>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x2c(%rbp)
cmpl   $0x4,-0x4(%rbp)
je     11ca <gauss+0x4a>
mov    0x2e31(%rip),%rax
movslq (%rax),%rdi
lea    0xe4f(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe98(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1205 <gauss+0x85>
lea    0xe7f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%edx
lea    0xe6f(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    12c9 <gauss+0x149>
mov    $0x0,%al
call   10a0 <rand_gasdev@plt>
movsd  %xmm0,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
movsd  -0x38(%rbp),%xmm0
lea    0xe3e(%rip),%rsi
mov    $0x1,%al
call   1050 <fprintf@plt>
cvtsi2sdl -0x20(%rbp),%xmm1
cvtsi2sdl -0x1c(%rbp),%xmm0
xorps  %xmm2,%xmm2
addsd  %xmm2,%xmm0
divsd  %xmm0,%xmm1
movsd  0xd83(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
cmp    -0x2c(%rbp),%eax
jne    12b6 <gauss+0x136>
mov    -0x2c(%rbp),%esi
lea    0xe03(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2d32(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    12bb <gauss+0x13b>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1231 <gauss+0xb1>
lea    0xdd4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gauss>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
cmp    $0x4,%edi
jne    12b9 <gauss+0x119>
mov    %rsi,%rbx
mov    0x10(%rsi),%rdi
lea    0xeb4(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     12e3 <gauss+0x143>
mov    %rax,%r12
mov    0x18(%rbx),%rdi
call   1090 <atoi@plt>
mov    %eax,%ebp
lea    0xe93(%rip),%rsi
mov    %r12,%rdi
mov    %eax,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
test   %ebp,%ebp
jle    1297 <gauss+0xf7>
cvtsi2sd %ebp,%xmm0
movsd  %xmm0,0x10(%rsp)
xorpd  %xmm1,%xmm1
lea    0xe6f(%rip),%r14
lea    0xe6c(%rip),%r15
mov    0x2db9(%rip),%r13
xor    %ebx,%ebx
jmp    123d <gauss+0x9d>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
addsd  0xdd0(%rip),%xmm1
add    $0xffffffff,%ebp
je     1297 <gauss+0xf7>
movsd  %xmm1,0x8(%rsp)
xor    %eax,%eax
call   10c0 <rand_gasdev@plt>
mov    %r12,%rdi
mov    %r14,%rsi
mov    $0x1,%al
call   1060 <fprintf@plt>
movsd  0x8(%rsp),%xmm1
movapd %xmm1,%xmm0
divsd  0x10(%rsp),%xmm0
mulsd  0xd91(%rip),%xmm0
cvttsd2si %xmm0,%eax
cmp    %eax,%ebx
jne    1230 <gauss+0x90>
mov    %r15,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x0(%r13),%edi
call   1070 <fflush@plt>
movsd  0x8(%rsp),%xmm1
add    $0x1,%ebx
jmp    1230 <gauss+0x90>
lea    0xdef(%rip),%rdi
call   1030 <puts@plt>
mov    %r12,%rdi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <fclose@plt>
mov    0x2d20(%rip),%rax
movslq (%rax),%rcx
lea    0xd46(%rip),%rdi
mov    $0x68,%esi
mov    $0x1,%edx
call   10b0 <fwrite@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
lea    0xdad(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [105 x i8] c"Error: missing output file name and points number.\0AFormat: simulate_data <file_name> <number_of_point> \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"
@.str.5 = [9 x i8] c"\0D\0D\0D\0D%d%%\00"
@stdout = global i32 0
@.str.6 = [11 x i8] c"\0D\0D\0D\0DDone!\0A\00"
define void @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
store i32 0, i32* %10
%12 = load i32, i32* %3
%13 = icmp ne i32 %12, 4
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 ([105 x i8], [105 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 (i8*, ...) @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 i32*, i32** %5
%36 = load i32, i32* %6
%37 = call i32 (i32*, i8*, ...) @fprintf(i32* %35, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %36)
store i32 0, i32* %7
br label %38
38: ; preds = %65, %30
%39 = load i32, i32* %7
%40 = load i32, i32* %6
%41 = icmp slt i32 %39, %40
br i1 %41, label %42, label %68
42: ; preds = %38
%43 = call double (...) @rand_gasdev()
store double %43, double* %11
%44 = load i32*, i32** %5
%45 = load double, double* %11
%46 = call i32 (i32*, i8*, ...) @fprintf(i32* %44, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), double %45)
%47 = load i32, i32* %7
%48 = sitofp i32 %47 to double
%49 = load i32, i32* %6
%50 = sitofp i32 %49 to double
%51 = fadd double %50, 0.000000e+00
%52 = fdiv double %48, %51
%53 = fmul double 1.000000e+02, %52
%54 = fptosi double %53 to i32
%55 = load i32, i32* %10
%56 = icmp eq i32 %54, %55
br i1 %56, label %57, label %64
57: ; preds = %42
%58 = load i32, i32* %10
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32 %58)
%60 = load i32, i32* @stdout
%61 = call i32 @fflush(i32 %60)
%62 = load i32, i32* %10
%63 = add nsw i32 %62, 1
store i32 %63, i32* %10
br label %64
64: ; preds = %57, %42
br label %65
65: ; preds = %64
%66 = load i32, i32* %7
%67 = add nsw i32 %66, 1
store i32 %67, i32* %7
br label %38
68: ; preds = %38
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0))
%70 = load i32*, i32** %5
%71 = call i32 @fclose(i32* %70)
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [105 x i8] c"Error: missing output file name and points number.\0AFormat: simulate_data <file_name> <number_of_point> \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.5 = [9 x i8] c"\0D\0D\0D\0D%d%%\00"
@stdout = global i32 0
@str = [10 x i8] c"\0D\0D\0D\0DDone!\00"
@str.7 = [30 x i8] c"Error opening file for write!\00"
define void @gauss(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 4
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 ([105 x i8], [105 x i8]* @.str, i64 0, i64 0), i64 104, 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.7, 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 = 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)
%23 = icmp sgt i32 %21, 0
br i1 %23, label %24, label %45
24: ; preds = %18
%25 = sitofp i32 %21 to double
br label %26
26: ; preds = %24, %41
%27 = phi i32 [ 0, %24 ], [ %42, %41 ]
%28 = phi i32 [ 0, %24 ], [ %43, %41 ]
%29 = tail call double (...) @rand_gasdev()
%30 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %13, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), double %29)
%31 = sitofp i32 %28 to double
%32 = fdiv double %31, %25
%33 = fmul double %32, 1.000000e+02
%34 = fptosi double %33 to i32
%35 = icmp eq i32 %27, %34
br i1 %35, label %36, label %41
36: ; preds = %26
%37 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32 %27)
%38 = load i32, i32* @stdout
%39 = tail call i32 @fflush(i32 %38)
%40 = add nsw i32 %27, 1
br label %41
41: ; preds = %26, %36
%42 = phi i32 [ %40, %36 ], [ %27, %26 ]
%43 = add nuw nsw i32 %28, 1
%44 = icmp eq i32 %43, %21
br i1 %44, label %45, label %26
45: ; preds = %41, %18
%46 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str, i64 0, i64 0))
%47 = tail call i32 @fclose(i32* %13)
ret void
}