#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 EXIT_SUCCESS;
int atoi(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fwrite(char *, int, int /*<<< orphan*/,
                          int /*<<< orphan*/ *);
scalar_t__ sin(int);
int /*<<< orphan*/ sprintf(char *, char *, double);
int /*<<< orphan*/ strlen(char *);
int main(int argc, char *argv[]) {
  FILE *f = fopen("data-sinus.data", "w+");
  int pi = 3.14159265358979323846264338327950288419716939937510;
  int echan = 44100;
  double tab[echan * 2];
  int freq;
  char tmp[64];
  for (int i = 0; i < echan; i++) {
    for (int j = 1; j < argc; j++) {
      freq = atoi(argv[j]);
      tab[i] += sin((2 * pi * freq * i) / (1. * echan));
    }
    sprintf(tmp, "%lf\n", tab[i]);
    fwrite(tmp, sizeof(char), strlen(tmp), f);
  }
  fclose(f);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe78(%rip),%rdi
lea    0xe81(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
movl   $0x3,-0x1c(%rbp)
movl   $0xac44,-0x20(%rbp)
mov    -0x20(%rbp),%eax
add    %eax,%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rdx
shl    $0x3,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x90(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x84(%rbp)
mov    -0x84(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    12e7 <main+0x177>
movl   $0x1,-0x88(%rbp)
mov    -0x88(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1285 <main+0x115>
mov    -0x10(%rbp),%rax
movslq -0x88(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x34(%rbp)
mov    -0x1c(%rbp),%eax
shl    $0x1,%eax
imul   -0x34(%rbp),%eax
imul   -0x84(%rbp),%eax
cvtsi2sd %eax,%xmm0
cvtsi2sdl -0x20(%rbp),%xmm2
movsd  0xdc0(%rip),%xmm1
mulsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1050 <sin@plt>
mov    %rax,%rcx
mov    -0x90(%rbp),%rax
cvtsi2sd %rcx,%xmm0
movslq -0x84(%rbp),%rcx
addsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x88(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x88(%rbp)
jmp    11f8 <main+0x88>
mov    -0x90(%rbp),%rax
lea    -0x80(%rbp),%rdi
movslq -0x84(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xd78(%rip),%rsi
call   1080 <sprintf@plt>
lea    -0x80(%rbp),%rax
mov    %rax,-0x98(%rbp)
lea    -0x80(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x98(%rbp),%rdi
mov    %eax,%edx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   1090 <fwrite@plt>
mov    -0x84(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x84(%rbp)
jmp    11df <main+0x6f>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    0x2ce9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xac498,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xe7b(%rip),%rdi
lea    0xe84(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,0x8(%rsp)
mov    %ebp,0x4(%rsp)
mov    %ebp,%ebp
xor    %r15d,%r15d
lea    0x10(%rsp),%r13
jmp    11ef <main+0x7f>
xchg   %ax,%ax
movsd  0x50(%rsp,%r15,8),%xmm0
mov    %r13,%rdi
lea    0xe5a(%rip),%rsi
call   1080 <sprintf@plt>
mov    %r13,%rdi
call   1040 <strlen@plt>
mov    %r13,%rdi
mov    $0x1,%esi
mov    %eax,%edx
mov    0x8(%rsp),%rcx
call   1090 <fwrite@plt>
add    $0x1,%r15
cmp    $0xac44,%r15
je     1259 <main+0xe9>
cmpl   $0x1,0x4(%rsp)
jle    11b0 <main+0x40>
lea    (%r15,%r15,1),%eax
lea    (%rax,%rax,2),%r14d
mov    $0x1,%r12d
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    (%rbx,%r12,8),%rdi
call   1070 <atoi@plt>
imul   %r14d,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
divsd  0xdd4(%rip),%xmm0
cvttsd2si %xmm0,%edi
call   1050 <sin@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
addsd  0x50(%rsp,%r15,8),%xmm0
movsd  %xmm0,0x50(%rsp,%r15,8)
add    $0x1,%r12
cmp    %r12,%rbp
jne    1210 <main+0xa0>
jmp    11b7 <main+0x47>
mov    0x8(%rsp),%rdi
call   1030 <fclose@plt>
mov    0x2d76(%rip),%rax
mov    (%rax),%eax
add    $0xac498,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [16 x i8] c"data-sinus.data\00"
@.str.1 = [3 x i8] c"w+\00"
@.str.2 = [5 x i8] c"%lf\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i32
%12 = alloca [64 x i8]
%13 = alloca i32
%14 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%15 = call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %15, i32** %6
store i32 3, i32* %7
store i32 44100, i32* %8
%16 = load i32, i32* %8
%17 = mul nsw i32 %16, 2
%18 = zext i32 %17 to i64
%19 = call i8* @llvm.stacksave()
store i8* %19, i8** %9
%20 = alloca double, i64 %18
store i64 %18, i64* %10
store i32 0, i32* %13
br label %21
21: ; preds = %71, %2
%22 = load i32, i32* %13
%23 = load i32, i32* %8
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %74
25: ; preds = %21
store i32 1, i32* %14
br label %26
26: ; preds = %56, %25
%27 = load i32, i32* %14
%28 = load i32, i32* %4
%29 = icmp slt i32 %27, %28
br i1 %29, label %30, label %59
30: ; preds = %26
%31 = load i8**, i8*** %5
%32 = load i32, i32* %14
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8*, i8** %31, i64 %33
%35 = load i8*, i8** %34
%36 = call i32 @atoi(i8* %35)
store i32 %36, i32* %11
%37 = load i32, i32* %7
%38 = mul nsw i32 2, %37
%39 = load i32, i32* %11
%40 = mul nsw i32 %38, %39
%41 = load i32, i32* %13
%42 = mul nsw i32 %40, %41
%43 = sitofp i32 %42 to double
%44 = load i32, i32* %8
%45 = sitofp i32 %44 to double
%46 = fmul double 1.000000e+00, %45
%47 = fdiv double %43, %46
%48 = fptosi double %47 to i32
%49 = call i64 @sin(i32 %48)
%50 = sitofp i64 %49 to double
%51 = load i32, i32* %13
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds double, double* %20, i64 %52
%54 = load double, double* %53
%55 = fadd double %54, %50
store double %55, double* %53
br label %56
56: ; preds = %30
%57 = load i32, i32* %14
%58 = add nsw i32 %57, 1
store i32 %58, i32* %14
br label %26
59: ; preds = %26
%60 = getelementptr inbounds [64 x i8], [64 x i8]* %12, i64 0, i64 0
%61 = load i32, i32* %13
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds double, double* %20, i64 %62
%64 = load double, double* %63
%65 = call i32 @sprintf(i8* %60, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), double %64)
%66 = getelementptr inbounds [64 x i8], [64 x i8]* %12, i64 0, i64 0
%67 = getelementptr inbounds [64 x i8], [64 x i8]* %12, i64 0, i64 0
%68 = call i32 @strlen(i8* %67)
%69 = load i32*, i32** %6
%70 = call i32 @fwrite(i8* %66, i32 1, i32 %68, i32* %69)
br label %71
71: ; preds = %59
%72 = load i32, i32* %13
%73 = add nsw i32 %72, 1
store i32 %73, i32* %13
br label %21
74: ; preds = %21
%75 = load i32*, i32** %6
%76 = call i32 @fclose(i32* %75)
%77 = load i32, i32* @EXIT_SUCCESS
store i32 %77, i32* %3
%78 = load i8*, i8** %9
%79 = load i32, i32* %3
ret i32 %79
}

LLVM IR (-O2):
@.str = [16 x i8] c"data-sinus.data\00"
@.str.1 = [3 x i8] c"w+\00"
@.str.2 = [5 x i8] c"%lf\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [64 x i8]
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%5 = alloca [88200 x double]
%6 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%7 = icmp sgt i32 %0, 1
%8 = zext i32 %0 to i64
br label %9
9: ; preds = %2, %20
%10 = phi i64 [ 0, %2 ], [ %25, %20 ]
%11 = getelementptr inbounds [88200 x double], [88200 x double]* %5, i64 0, i64 %10
br i1 %7, label %14, label %12
12: ; preds = %9
%13 = load double, double* %11
br label %20
14: ; preds = %9
%15 = trunc i64 %10 to i32
%16 = mul i32 %15, 6
br label %27
17: ; preds = %20
%18 = call i32 @fclose(i32* %4)
%19 = load i32, i32* @EXIT_SUCCESS
ret i32 %19
20: ; preds = %27, %12
%21 = phi double [ %13, %12 ], [ %39, %27 ]
%22 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), double %21)
%23 = call i32 @strlen(i8* %6)
%24 = call i32 @fwrite(i8* %6, i32 1, i32 %23, i32* %4)
%25 = add nuw nsw i64 %10, 1
%26 = icmp eq i64 %25, 44100
br i1 %26, label %17, label %9
27: ; preds = %14, %27
%28 = phi i64 [ 1, %14 ], [ %40, %27 ]
%29 = getelementptr inbounds i8*, i8** %1, i64 %28
%30 = load i8*, i8** %29
%31 = call i32 @atoi(i8* %30)
%32 = mul i32 %16, %31
%33 = sitofp i32 %32 to double
%34 = fdiv double %33, 4.410000e+04
%35 = fptosi double %34 to i32
%36 = call i64 @sin(i32 %35)
%37 = sitofp i64 %36 to double
%38 = load double, double* %11
%39 = fadd double %38, %37
store double %39, double* %11
%40 = add nuw nsw i64 %28, 1
%41 = icmp eq i64 %40, %8
br i1 %41, label %20, label %27
}