#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 scalar_t__ int16_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int EXIT_SUCCESS;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fread(scalar_t__ *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(scalar_t__ *, int, int, int /*<<< orphan*/ *);
scalar_t__ *malloc(int);
int main() {
  int16_t *signal = malloc(100000000);
  int16_t *envelop = malloc(100000000);
  int16_t *sral = malloc(100000000);
  FILE *in = fopen("signal.raw", "rb");
  FILE *in2 = fopen("mod.raw", "rb");
  FILE *out = fopen("out.raw", "wb");
  int size_sig = fread(signal, 2, 50000000, in);
  int size_env = fread(envelop, 2, 50000000, in2);
  int q;
  double pos = 0;
  for (q = 0; q < size_env; q++) {
    pos += (double)envelop[q] / 10000.0;
    if (pos < 0) {
      pos = 0;
    }
    if (pos >= size_sig) {
      pos = size_sig;
    }
    sral[q] = signal[(int)pos];
  }
  fwrite(sral, 2, size_env, out);
  fclose(out);
  fclose(in);
  fclose(in2);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x5f5e100,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    $0x5f5e100,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    $0x5f5e100,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
lea    0xe78(%rip),%rdi
lea    0xe7c(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
lea    0xe6f(%rip),%rdi
lea    0xe65(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x30(%rbp)
lea    0xe60(%rip),%rdi
lea    0xe61(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rcx
mov    $0x2,%esi
mov    $0x2faf080,%edx
call   1030 <fread@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x30(%rbp),%rcx
mov    $0x2,%esi
mov    $0x2faf080,%edx
call   1030 <fread@plt>
mov    %eax,-0x40(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x50(%rbp)
movl   $0x0,-0x44(%rbp)
mov    -0x44(%rbp),%eax
cmp    -0x40(%rbp),%eax
jge    129f <main+0x14f>
mov    -0x18(%rbp),%rax
movslq -0x44(%rbp),%rcx
cvtsi2sdq (%rax,%rcx,8),%xmm0
movsd  0xdcd(%rip),%xmm1
divsd  %xmm1,%xmm0
addsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x50(%rbp),%xmm0
jbe    1257 <main+0x107>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x50(%rbp),%xmm0
cvtsi2sdl -0x3c(%rbp),%xmm1
ucomisd %xmm1,%xmm0
jb     1275 <main+0x125>
cvtsi2sdl -0x3c(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    -0x10(%rbp),%rax
cvttsd2si -0x50(%rbp),%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdx
mov    -0x20(%rbp),%rax
movslq -0x44(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    1211 <main+0xc1>
mov    -0x20(%rbp),%rdi
mov    -0x40(%rbp),%edx
mov    -0x38(%rbp),%rcx
mov    $0x2,%esi
call   1070 <fwrite@plt>
mov    -0x38(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x30(%rbp),%rdi
call   1040 <fclose@plt>
mov    0x2d0a(%rip),%rax
mov    (%rax),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0x5f5e100,%edi
call   1050 <malloc@plt>
mov    %rax,%r15
mov    $0x5f5e100,%edi
call   1050 <malloc@plt>
mov    %rax,%r12
mov    $0x5f5e100,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
lea    0xe7f(%rip),%rdi
lea    0xe83(%rip),%r14
mov    %r14,%rsi
call   1060 <fopen@plt>
mov    %rax,%rbp
lea    0xe74(%rip),%rdi
mov    %r14,%rsi
call   1060 <fopen@plt>
mov    %rax,%r14
lea    0xe6a(%rip),%rdi
lea    0xe6b(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%r13
mov    %r15,%rdi
mov    $0x2,%esi
mov    $0x2faf080,%edx
mov    %rbp,(%rsp)
mov    %rbp,%rcx
mov    %r14,%rbp
call   1030 <fread@plt>
mov    %eax,%r14d
mov    %r12,%rdi
mov    $0x2,%esi
mov    $0x2faf080,%edx
mov    %rbp,%rcx
call   1030 <fread@plt>
test   %eax,%eax
jle    125a <main+0x10a>
cvtsi2sd %r14d,%xmm0
mov    %eax,%ecx
xorpd  %xmm1,%xmm1
xor    %edx,%edx
movsd  0xdf0(%rip),%xmm2
xorps  %xmm3,%xmm3
cvtsi2sdq (%r12,%rdx,8),%xmm3
divsd  %xmm2,%xmm3
addsd  %xmm1,%xmm3
xorpd  %xmm4,%xmm4
maxsd  %xmm3,%xmm4
movapd %xmm0,%xmm1
cmplesd %xmm4,%xmm1
movapd %xmm1,%xmm3
andnpd %xmm4,%xmm3
andpd  %xmm0,%xmm1
orpd   %xmm3,%xmm1
cvttsd2si %xmm1,%esi
movslq %esi,%rsi
mov    (%r15,%rsi,8),%rsi
mov    %rsi,(%rbx,%rdx,8)
add    $0x1,%rdx
cmp    %rdx,%rcx
jne    1210 <main+0xc0>
mov    %rbx,%rdi
mov    $0x2,%esi
mov    %eax,%edx
mov    %r13,%rcx
call   1070 <fwrite@plt>
mov    %r13,%rdi
call   1040 <fclose@plt>
mov    (%rsp),%rdi
call   1040 <fclose@plt>
mov    %rbp,%rdi
call   1040 <fclose@plt>
mov    0x2d54(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"signal.raw\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [8 x i8] c"mod.raw\00"
@.str.3 = [8 x i8] c"out.raw\00"
@.str.4 = [3 x i8] c"wb\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i64*
%3 = alloca i64*
%4 = alloca i64*
%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* %1
%12 = call i64* @malloc(i32 100000000)
store i64* %12, i64** %2
%13 = call i64* @malloc(i32 100000000)
store i64* %13, i64** %3
%14 = call i64* @malloc(i32 100000000)
store i64* %14, i64** %4
%15 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 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** %5
%16 = call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %16, i32** %6
%17 = call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32* %17, i32** %7
%18 = load i64*, i64** %2
%19 = load i32*, i32** %5
%20 = call i32 @fread(i64* %18, i32 2, i32 50000000, i32* %19)
store i32 %20, i32* %8
%21 = load i64*, i64** %3
%22 = load i32*, i32** %6
%23 = call i32 @fread(i64* %21, i32 2, i32 50000000, i32* %22)
store i32 %23, i32* %9
store double 0.000000e+00, double* %11
store i32 0, i32* %10
br label %24
24: ; preds = %60, %0
%25 = load i32, i32* %10
%26 = load i32, i32* %9
%27 = icmp slt i32 %25, %26
br i1 %27, label %28, label %63
28: ; preds = %24
%29 = load i64*, i64** %3
%30 = load i32, i32* %10
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i64, i64* %29, i64 %31
%33 = load i64, i64* %32
%34 = sitofp i64 %33 to double
%35 = fdiv double %34, 1.000000e+04
%36 = load double, double* %11
%37 = fadd double %36, %35
store double %37, double* %11
%38 = load double, double* %11
%39 = fcmp olt double %38, 0.000000e+00
br i1 %39, label %40, label %41
40: ; preds = %28
store double 0.000000e+00, double* %11
br label %41
41: ; preds = %40, %28
%42 = load double, double* %11
%43 = load i32, i32* %8
%44 = sitofp i32 %43 to double
%45 = fcmp oge double %42, %44
br i1 %45, label %46, label %49
46: ; preds = %41
%47 = load i32, i32* %8
%48 = sitofp i32 %47 to double
store double %48, double* %11
br label %49
49: ; preds = %46, %41
%50 = load i64*, i64** %2
%51 = load double, double* %11
%52 = fptosi double %51 to i32
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i64, i64* %50, i64 %53
%55 = load i64, i64* %54
%56 = load i64*, i64** %4
%57 = load i32, i32* %10
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i64, i64* %56, i64 %58
store i64 %55, i64* %59
br label %60
60: ; preds = %49
%61 = load i32, i32* %10
%62 = add nsw i32 %61, 1
store i32 %62, i32* %10
br label %24
63: ; preds = %24
%64 = load i64*, i64** %4
%65 = load i32, i32* %9
%66 = load i32*, i32** %7
%67 = call i32 @fwrite(i64* %64, i32 2, i32 %65, i32* %66)
%68 = load i32*, i32** %7
%69 = call i32 @fclose(i32* %68)
%70 = load i32*, i32** %5
%71 = call i32 @fclose(i32* %70)
%72 = load i32*, i32** %6
%73 = call i32 @fclose(i32* %72)
%74 = load i32, i32* @EXIT_SUCCESS
ret i32 %74
}

LLVM IR (-O2):
@.str = [11 x i8] c"signal.raw\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [8 x i8] c"mod.raw\00"
@.str.3 = [8 x i8] c"out.raw\00"
@.str.4 = [3 x i8] c"wb\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = tail call i64* @malloc(i32 100000000)
%2 = tail call i64* @malloc(i32 100000000)
%3 = tail call i64* @malloc(i32 100000000)
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%6 = tail call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%7 = tail call i32 @fread(i64* %1, i32 2, i32 50000000, i32* %4)
%8 = tail call i32 @fread(i64* %2, i32 2, i32 50000000, i32* %5)
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %32
10: ; preds = %0
%11 = sitofp i32 %7 to double
%12 = zext i32 %8 to i64
br label %13
13: ; preds = %10, %13
%14 = phi i64 [ 0, %10 ], [ %30, %13 ]
%15 = phi double [ 0.000000e+00, %10 ], [ %24, %13 ]
%16 = getelementptr inbounds i64, i64* %2, i64 %14
%17 = load i64, i64* %16
%18 = sitofp i64 %17 to double
%19 = fdiv double %18, 1.000000e+04
%20 = fadd double %15, %19
%21 = fcmp olt double %20, 0.000000e+00
%22 = select i1 %21, double 0.000000e+00, double %20
%23 = fcmp oge double %22, %11
%24 = select i1 %23, double %11, double %22
%25 = fptosi double %24 to i32
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i64, i64* %1, i64 %26
%28 = load i64, i64* %27
%29 = getelementptr inbounds i64, i64* %3, i64 %14
store i64 %28, i64* %29
%30 = add nuw nsw i64 %14, 1
%31 = icmp eq i64 %30, %12
br i1 %31, label %32, label %13
32: ; preds = %13, %0
%33 = tail call i32 @fwrite(i64* %3, i32 2, i32 %8, i32* %6)
%34 = tail call i32 @fclose(i32* %6)
%35 = tail call i32 @fclose(i32* %4)
%36 = tail call i32 @fclose(i32* %5)
%37 = load i32, i32* @EXIT_SUCCESS
ret i32 %37
}