#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 */
double RAND_MAX;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, double, double);
scalar_t__ rand();
double sin(double);
int main() {
  int i, N = 512;
  FILE *fd;
  fd = fopen("36sin_with_noise.dat", "w");
  for (i = 0; i < N; i++) {
    double x = i * 2 * 3.14159265 / N;
    fprintf(fd, "%f %f\n", x, sin(x) + ((double)rand() / RAND_MAX - 0.5) / 3);
  }
  fclose(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x200,-0xc(%rbp)
lea    0xeab(%rip),%rdi
lea    0xeb9(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1230 <main+0xe0>
mov    -0x8(%rbp),%eax
shl    $0x1,%eax
cvtsi2sd %eax,%xmm0
movsd  0xe6e(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvtsi2sdl -0xc(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1050 <sin@plt>
movsd  %xmm0,-0x38(%rbp)
mov    $0x0,%al
call   1070 <rand@plt>
movsd  -0x38(%rbp),%xmm1
mov    -0x30(%rbp),%rdi
movsd  -0x28(%rbp),%xmm0
cvtsi2sd %rax,%xmm2
mov    0x2df2(%rip),%rax
divsd  (%rax),%xmm2
movsd  0xe06(%rip),%xmm3
subsd  %xmm3,%xmm2
movsd  0xdf2(%rip),%xmm3
divsd  %xmm3,%xmm2
addsd  %xmm2,%xmm1
lea    0xe12(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1184 <main+0x34>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
lea    0xebf(%rip),%rdi
lea    0xecd(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
mov    0x2e71(%rip),%r15
lea    0xeb9(%rip),%r14
xor    %ebp,%ebp
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
mulsd  0xe71(%rip),%xmm0
mulsd  0xe71(%rip),%xmm0
movsd  %xmm0,0x10(%rsp)
call   1050 <sin@plt>
movsd  %xmm0,0x8(%rsp)
xor    %eax,%eax
call   1070 <rand@plt>
xorps  %xmm1,%xmm1
cvtsi2sd %rax,%xmm1
divsd  (%r15),%xmm1
addsd  0xe4c(%rip),%xmm1
divsd  0xe4c(%rip),%xmm1
addsd  0x8(%rsp),%xmm1
mov    %rbx,%rdi
mov    %r14,%rsi
movsd  0x10(%rsp),%xmm0
call   1040 <fprintf@plt>
add    $0x2,%ebp
cmp    $0x400,%ebp
jne    1180 <main+0x30>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [21 x i8] c"36sin_with_noise.dat\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [7 x i8] c"%f %f\0A\00"
@RAND_MAX = global double 0.000000e+00
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32*
%5 = alloca double
store i32 0, i32* %1
store i32 512, i32* %3
%6 = call i32* @fopen(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %6, i32** %4
store i32 0, i32* %2
br label %7
7: ; preds = %31, %0
%8 = load i32, i32* %2
%9 = load i32, i32* %3
%10 = icmp slt i32 %8, %9
br i1 %10, label %11, label %34
11: ; preds = %7
%12 = load i32, i32* %2
%13 = mul nsw i32 %12, 2
%14 = sitofp i32 %13 to double
%15 = fmul double %14, 0x400921FB53C8D4F1
%16 = load i32, i32* %3
%17 = sitofp i32 %16 to double
%18 = fdiv double %15, %17
store double %18, double* %5
%19 = load i32*, i32** %4
%20 = load double, double* %5
%21 = load double, double* %5
%22 = call double @sin(double %21)
%23 = call i64 (...) @rand()
%24 = sitofp i64 %23 to double
%25 = load double, double* @RAND_MAX
%26 = fdiv double %24, %25
%27 = fsub double %26, 5.000000e-01
%28 = fdiv double %27, 3.000000e+00
%29 = fadd double %22, %28
%30 = call i32 @fprintf(i32* %19, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), double %20, double %29)
br label %31
31: ; preds = %11
%32 = load i32, i32* %2
%33 = add nsw i32 %32, 1
store i32 %33, i32* %2
br label %7
34: ; preds = %7
%35 = load i32*, i32** %4
%36 = call i32 @fclose(i32* %35)
ret i32 0
}

LLVM IR (-O2):
@.str = [21 x i8] c"36sin_with_noise.dat\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [7 x i8] c"%f %f\0A\00"
@RAND_MAX = global double 0.000000e+00
define i32 @main() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %2
2: ; preds = %0, %2
%3 = phi i32 [ 0, %0 ], [ %17, %2 ]
%4 = shl nuw nsw i32 %3, 1
%5 = sitofp i32 %4 to double
%6 = fmul double %5, 0x400921FB53C8D4F1
%7 = fmul double %6, 0x3F60000000000000
%8 = tail call double @sin(double %7)
%9 = tail call i64 (...) @rand()
%10 = sitofp i64 %9 to double
%11 = load double, double* @RAND_MAX
%12 = fdiv double %10, %11
%13 = fadd double %12, -5.000000e-01
%14 = fdiv double %13, 3.000000e+00
%15 = fadd double %8, %14
%16 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), double %7, double %15)
%17 = add nuw nsw i32 %3, 1
%18 = icmp eq i32 %17, 512
br i1 %18, label %19, label %2
19: ; preds = %2
%20 = tail call i32 @fclose(i32* %1)
ret i32 0
}