#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*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int, double);
double sin(int);
int /*<<< orphan*/ snprintf(char *, int, char *, double);
int /*<<< orphan*/ strncat(char *, char *, int);
int /*<<< orphan*/ strncpy(char *, char *, int);
int main(void) {
  double SinHertz = 22000, distanceFromPinger = 10.1, pulseTime = 0.0013,
         timeBetweenPulses = 2;
  int arrayLength = 7383;
  double c[arrayLength];
  int i = 0;
  int n = 0;
  char title[27];
  char distance[11];
  char try[1] = "2";
  strncpy(title, "MatLabInput", 11);
  snprintf(distance, 11, "%g", distanceFromPinger);
  strncat(title, distance, 11);
  strncat(title, "Try", 3);
  strncat(title, try, 1);
  strncat(title, ".csv", 4);
  title[27] = '/0';
  FILE *OutputToMatLab = fopen(title, "w");
  double timeDelay = distanceFromPinger / 1500 * 1000000;
  for (; i < arrayLength; i++) {
    double masterShift = (timeDelay + n * timeBetweenPulses * 1000000);
    if (i < (int)masterShift) {
      c[i] = 0.0;
    } else if ((i - (int)masterShift) <= (int)(pulseTime * 1000000)) {
      c[i] = (sin(2 * 3.141592 * SinHertz * (i - (int)masterShift)) /
              (distanceFromPinger * distanceFromPinger));
    } else {
      n++;
      i--;
    }
    fprintf(OutputToMatLab, "%d, %g\n", i, c[i]);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
movabs $0x40d57c0000000000,%rax
7c d5 40
mov    %rax,-0x10(%rbp)
movabs $0x4024333333333333,%rax
33 24 40
mov    %rax,-0x18(%rbp)
movabs $0x3f554c985f06f694,%rax
4c 55 3f
mov    %rax,-0x20(%rbp)
movabs $0x4000000000000000,%rax
mov    %rax,-0x28(%rbp)
movl   $0x1cd7,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x38(%rbp)
lea    0xf(,%rax,8),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0xa0(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x40(%rbp)
movl   $0x0,-0x44(%rbp)
movl   $0x0,-0x48(%rbp)
mov    0xe29(%rip),%al
mov    %al,-0x7c(%rbp)
lea    -0x70(%rbp),%rdi
lea    0xe1c(%rip),%rsi
mov    $0xb,%edx
call   1030 <strncpy@plt>
lea    -0x7b(%rbp),%rdi
movsd  -0x18(%rbp),%xmm0
mov    $0xb,%esi
lea    0xe09(%rip),%rdx
call   1040 <snprintf@plt>
lea    -0x70(%rbp),%rdi
lea    -0x7b(%rbp),%rsi
mov    $0xb,%edx
call   1050 <strncat@plt>
lea    -0x70(%rbp),%rdi
lea    0xdea(%rip),%rsi
mov    $0x3,%edx
call   1050 <strncat@plt>
lea    -0x70(%rbp),%rdi
lea    -0x7c(%rbp),%rsi
mov    $0x1,%edx
call   1050 <strncat@plt>
lea    -0x70(%rbp),%rdi
lea    0xdc7(%rip),%rsi
mov    $0x4,%edx
call   1050 <strncat@plt>
movb   $0x30,-0x55(%rbp)
lea    -0x70(%rbp),%rdi
lea    0xdb3(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x88(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  0xd71(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  0xd5d(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x90(%rbp)
ff
mov    -0x44(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    13cf <main+0x26f>
movsd  -0x90(%rbp),%xmm1
ff
cvtsi2sdl -0x48(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  0xd2b(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x98(%rbp)
ff
mov    -0x44(%rbp),%eax
cvttsd2si -0x98(%rbp),%ecx
ff
cmp    %ecx,%eax
jge    1310 <main+0x1b0>
mov    -0xa0(%rbp),%rax
movslq -0x44(%rbp),%rcx
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
jmp    139b <main+0x23b>
mov    -0x44(%rbp),%eax
cvttsd2si -0x98(%rbp),%ecx
ff
sub    %ecx,%eax
movsd  0xcdb(%rip),%xmm0
mulsd  -0x20(%rbp),%xmm0
cvttsd2si %xmm0,%ecx
cmp    %ecx,%eax
jg     1384 <main+0x224>
movsd  0xcd2(%rip),%xmm0
mulsd  -0x10(%rbp),%xmm0
mov    -0x44(%rbp),%eax
cvttsd2si -0x98(%rbp),%ecx
ff
sub    %ecx,%eax
cvtsi2sd %eax,%xmm1
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1070 <sin@plt>
mov    -0xa0(%rbp),%rax
movsd  -0x18(%rbp),%xmm1
mulsd  -0x18(%rbp),%xmm1
divsd  %xmm1,%xmm0
movslq -0x44(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
jmp    1396 <main+0x236>
mov    -0x48(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x48(%rbp)
mov    -0x44(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x44(%rbp)
jmp    139b <main+0x23b>
mov    -0xa0(%rbp),%rax
mov    -0x88(%rbp),%rdi
mov    -0x44(%rbp),%edx
movslq -0x44(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xc77(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    12af <main+0x14f>
movl   $0x0,-0x4(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x30,%rsp
movb   $0x32,0x4(%rsp)
lea    0xea3(%rip),%rsi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0xb,%edx
call   1030 <strncpy@plt>
lea    0xe96(%rip),%rdx
lea    0x5(%rsp),%r14
movsd  0xe65(%rip),%xmm0
mov    %r14,%rdi
mov    $0xb,%esi
call   1040 <snprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0xb,%edx
call   1050 <strncat@plt>
lea    0xe68(%rip),%rsi
mov    %rbx,%rdi
mov    $0x3,%edx
call   1050 <strncat@plt>
lea    0x4(%rsp),%rsi
mov    %rbx,%rdi
mov    $0x1,%edx
call   1050 <strncat@plt>
lea    0xe46(%rip),%rsi
mov    %rbx,%rdi
mov    $0x4,%edx
call   1050 <strncat@plt>
movb   $0x30,0x2b(%rsp)
lea    0xe32(%rip),%rsi
mov    %rbx,%rdi
call   1080 <fopen@plt>
mov    %rax,%r14
xor    %ebx,%ebx
lea    0xe20(%rip),%r15
jmp    123a <main+0xda>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r14,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1060 <fprintf@plt>
add    $0x1,%rbx
cmp    $0x1cd7,%rbx
je     126f <main+0x10f>
xorpd  %xmm0,%xmm0
cmp    $0x1a4d,%rbx
jb     1220 <main+0xc0>
lea    -0x1a4d(%rbx),%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  0xdac(%rip),%xmm0
cvttsd2si %xmm0,%edi
call   1070 <sin@plt>
divsd  0xda3(%rip),%xmm0
jmp    1220 <main+0xc0>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.main.try = [1 x i8] c"2"
@.str = [12 x i8] c"MatLabInput\00"
@.str.1 = [3 x i8] c"%g\00"
@.str.2 = [4 x i8] c"Try\00"
@.str.3 = [5 x i8] c".csv\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [8 x i8] c"%d, %g\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32
%10 = alloca i32
%11 = alloca [27 x i8]
%12 = alloca [11 x i8]
%13 = alloca [1 x i8]
%14 = alloca i32*
%15 = alloca double
%16 = alloca double
store i32 0, i32* %1
store double 2.200000e+04, double* %2
store double 1.010000e+01, double* %3
store double 1.300000e-03, double* %4
store double 2.000000e+00, double* %5
store i32 7383, i32* %6
%17 = load i32, i32* %6
%18 = zext i32 %17 to i64
%19 = call i8* @llvm.stacksave()
store i8* %19, i8** %7
%20 = alloca double, i64 %18
store i64 %18, i64* %8
store i32 0, i32* %9
store i32 0, i32* %10
%21 = bitcast [1 x i8]* %13 to i8*
%22 = getelementptr inbounds [27 x i8], [27 x i8]* %11, i64 0, i64 0
%23 = call i32 @strncpy(i8* %22, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 11)
%24 = getelementptr inbounds [11 x i8], [11 x i8]* %12, i64 0, i64 0
%25 = load double, double* %3
%26 = call i32 @snprintf(i8* %24, i32 11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), double %25)
%27 = getelementptr inbounds [27 x i8], [27 x i8]* %11, i64 0, i64 0
%28 = getelementptr inbounds [11 x i8], [11 x i8]* %12, i64 0, i64 0
%29 = call i32 @strncat(i8* %27, i8* %28, i32 11)
%30 = getelementptr inbounds [27 x i8], [27 x i8]* %11, i64 0, i64 0
%31 = call i32 @strncat(i8* %30, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 3)
%32 = getelementptr inbounds [27 x i8], [27 x i8]* %11, i64 0, i64 0
%33 = getelementptr inbounds [1 x i8], [1 x i8]* %13, i64 0, i64 0
%34 = call i32 @strncat(i8* %32, i8* %33, i32 1)
%35 = getelementptr inbounds [27 x i8], [27 x i8]* %11, i64 0, i64 0
%36 = call i32 @strncat(i8* %35, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 4)
%37 = getelementptr inbounds [27 x i8], [27 x i8]* %11, i64 0, i64 27
store i8 48, i8* %37
%38 = getelementptr inbounds [27 x i8], [27 x i8]* %11, i64 0, i64 0
%39 = call i32* @fopen(i8* %38, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %39, i32** %14
%40 = load double, double* %3
%41 = fdiv double %40, 1.500000e+03
%42 = fmul double %41, 1.000000e+06
store double %42, double* %15
br label %43
43: ; preds = %103, %0
%44 = load i32, i32* %9
%45 = load i32, i32* %6
%46 = icmp slt i32 %44, %45
br i1 %46, label %47, label %106
47: ; preds = %43
%48 = load double, double* %15
%49 = load i32, i32* %10
%50 = sitofp i32 %49 to double
%51 = load double, double* %5
%52 = fmul double %50, %51
%53 = call double @llvm.fmuladd.f64(double %52, double 1.000000e+06, double %48)
store double %53, double* %16
%54 = load i32, i32* %9
%55 = load double, double* %16
%56 = fptosi double %55 to i32
%57 = icmp slt i32 %54, %56
br i1 %57, label %58, label %62
58: ; preds = %47
%59 = load i32, i32* %9
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds double, double* %20, i64 %60
store double 0.000000e+00, double* %61
br label %95
62: ; preds = %47
%63 = load i32, i32* %9
%64 = load double, double* %16
%65 = fptosi double %64 to i32
%66 = sub nsw i32 %63, %65
%67 = load double, double* %4
%68 = fmul double %67, 1.000000e+06
%69 = fptosi double %68 to i32
%70 = icmp sle i32 %66, %69
br i1 %70, label %71, label %89
71: ; preds = %62
%72 = load double, double* %2
%73 = fmul double 0x401921FAFC8B007A, %72
%74 = load i32, i32* %9
%75 = load double, double* %16
%76 = fptosi double %75 to i32
%77 = sub nsw i32 %74, %76
%78 = sitofp i32 %77 to double
%79 = fmul double %73, %78
%80 = fptosi double %79 to i32
%81 = call double @sin(i32 %80)
%82 = load double, double* %3
%83 = load double, double* %3
%84 = fmul double %82, %83
%85 = fdiv double %81, %84
%86 = load i32, i32* %9
%87 = sext i32 %86 to i64
%88 = getelementptr inbounds double, double* %20, i64 %87
store double %85, double* %88
br label %94
89: ; preds = %62
%90 = load i32, i32* %10
%91 = add nsw i32 %90, 1
store i32 %91, i32* %10
%92 = load i32, i32* %9
%93 = add nsw i32 %92, -1
store i32 %93, i32* %9
br label %94
94: ; preds = %89, %71
br label %95
95: ; preds = %94, %58
%96 = load i32*, i32** %14
%97 = load i32, i32* %9
%98 = load i32, i32* %9
%99 = sext i32 %98 to i64
%100 = getelementptr inbounds double, double* %20, i64 %99
%101 = load double, double* %100
%102 = call i32 @fprintf(i32* %96, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i32 %97, double %101)
br label %103
103: ; preds = %95
%104 = load i32, i32* %9
%105 = add nsw i32 %104, 1
store i32 %105, i32* %9
br label %43
106: ; preds = %43
store i32 0, i32* %1
%107 = load i8*, i8** %7
%108 = load i32, i32* %1
ret i32 %108
}

LLVM IR (-O2):
@.str = [12 x i8] c"MatLabInput\00"
@.str.1 = [3 x i8] c"%g\00"
@.str.2 = [4 x i8] c"Try\00"
@.str.3 = [5 x i8] c".csv\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [8 x i8] c"%d, %g\0A\00"
define i32 @main() {
%1 = alloca [27 x i8]
%2 = alloca [11 x i8]
%3 = alloca [1 x i8]
%4 = getelementptr inbounds [27 x i8], [27 x i8]* %1, i64 0, i64 0
%5 = getelementptr inbounds [11 x i8], [11 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [1 x i8], [1 x i8]* %3, i64 0, i64 0
store i8 50, i8* %6
%7 = call i32 @strncpy(i8* %4, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 11)
%8 = call i32 @snprintf(i8* %5, i32 11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), double 1.010000e+01)
%9 = call i32 @strncat(i8* %4, i8* %5, i32 11)
%10 = call i32 @strncat(i8* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 3)
%11 = call i32 @strncat(i8* %4, i8* %6, i32 1)
%12 = call i32 @strncat(i8* %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 4)
%13 = getelementptr inbounds [27 x i8], [27 x i8]* %1, i64 0, i64 27
store i8 48, i8* %13
%14 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %15
15: ; preds = %0, %26
%16 = phi i64 [ 0, %0 ], [ %30, %26 ]
%17 = icmp ult i64 %16, 6733
br i1 %17, label %26, label %18
18: ; preds = %15
%19 = trunc i64 %16 to i32
%20 = add i32 %19, -6733
%21 = sitofp i32 %20 to double
%22 = fmul double %21, 0x4100DFB0624DD2F2
%23 = fptosi double %22 to i32
%24 = call double @sin(i32 %23)
%25 = fdiv double %24, 0x405980A3D70A3D70
br label %26
26: ; preds = %15, %18
%27 = phi double [ %25, %18 ], [ 0.000000e+00, %15 ]
%28 = trunc i64 %16 to i32
%29 = call i32 @fprintf(i32* %14, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i32 %28, double %27)
%30 = add nuw nsw i64 %16, 1
%31 = icmp eq i64 %30, 7383
br i1 %31, label %32, label %15
32: ; preds = %26
ret i32 0
}