#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 */

/* Variables and functions */
double M_PI;
scalar_t__ RAND_MAX;
double cos(int);
double pow(int, int);
scalar_t__ rand();
double sin(int);
void calculate_snapshot(double snapshot_real[1000][1000],
                        double snapshot_img[1000][1000]) {
  double strengh, w;
  int i, j;
  strengh = pow(10, (100 / 10));
  for (i = 0; i < 1000; i++) {
    double theta = (((double)rand() / (double)RAND_MAX)) * M_PI - M_PI / 2;
    w = (2 * M_PI * 0.02 * sin(theta)) / 0.04;
    for (j = 0; j < 1000; j++) {
      snapshot_real[i][j] = cos(j * w) * strengh;
      snapshot_img[i][j] = sin(j * w) * strengh;
    }
  }
}


x86 assembly (clang, -O0):
<calculate_snapshot>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0xa,%esi
mov    %esi,%edi
call   1050 <pow@plt>
movsd  %xmm0,-0x18(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x3e8,-0x24(%rbp)
jge    12bd <calculate_snapshot+0x17d>
mov    $0x0,%al
call   1060 <rand@plt>
cvtsi2sd %rax,%xmm0
mov    0x2e58(%rip),%rax
cvtsi2sdq (%rax),%xmm1
divsd  %xmm1,%xmm0
mov    0x2e50(%rip),%rax
movsd  (%rax),%xmm2
mov    0x2e45(%rip),%rax
movsd  (%rax),%xmm1
movsd  0xe61(%rip),%xmm3
divsd  %xmm3,%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  0xe31(%rip),%xmm0
mov    0x2e02(%rip),%rax
mulsd  (%rax),%xmm0
movsd  0xe16(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
cvttsd2si -0x30(%rbp),%edi
call   1030 <sin@plt>
movaps %xmm0,%xmm1
movsd  -0x38(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  0xde7(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x0,-0x28(%rbp)
cmpl   $0x3e8,-0x28(%rbp)
jge    12aa <calculate_snapshot+0x16a>
cvtsi2sdl -0x28(%rbp),%xmm0
mulsd  -0x20(%rbp),%xmm0
cvttsd2si %xmm0,%edi
call   1040 <cos@plt>
mulsd  -0x18(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
imul   $0x1f40,%rcx,%rcx
add    %rcx,%rax
movslq -0x28(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
cvtsi2sdl -0x28(%rbp),%xmm0
mulsd  -0x20(%rbp),%xmm0
cvttsd2si %xmm0,%edi
call   1030 <sin@plt>
mulsd  -0x18(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
imul   $0x1f40,%rcx,%rcx
add    %rcx,%rax
movslq -0x28(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1229 <calculate_snapshot+0xe9>
jmp    12af <calculate_snapshot+0x16f>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1168 <calculate_snapshot+0x28>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calculate_snapshot>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
mov    $0xa,%edi
mov    $0xa,%esi
call   1050 <pow@plt>
movsd  %xmm0,0x10(%rsp)
mov    0x2e78(%rip),%r12
xor    %r13d,%r13d
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
call   1060 <rand@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
mov    0x2e4a(%rip),%rax
xorps  %xmm1,%xmm1
cvtsi2sdq (%rax),%xmm1
divsd  %xmm1,%xmm0
movsd  (%r12),%xmm2
movapd %xmm2,%xmm1
mulsd  0xe4c(%rip),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
addsd  %xmm2,%xmm2
mulsd  0xe40(%rip),%xmm2
movsd  %xmm2,0x8(%rsp)
cvttsd2si %xmm0,%edi
call   1030 <sin@plt>
mulsd  0x8(%rsp),%xmm0
divsd  0xe2b(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
xor    %r15d,%r15d
xchg   %ax,%ax
xorps  %xmm0,%xmm0
cvtsi2sd %r15d,%xmm0
mulsd  0x8(%rsp),%xmm0
cvttsd2si %xmm0,%ebp
mov    %ebp,%edi
call   1040 <cos@plt>
mulsd  0x10(%rsp),%xmm0
movsd  %xmm0,(%rbx,%r15,8)
mov    %ebp,%edi
call   1030 <sin@plt>
mulsd  0x10(%rsp),%xmm0
movsd  %xmm0,(%r14,%r15,8)
add    $0x1,%r15
cmp    $0x3e8,%r15
jne    11f0 <calculate_snapshot+0xb0>
add    $0x1,%r13
add    $0x1f40,%r14
add    $0x1f40,%rbx
cmp    $0x3e8,%r13
jne    1180 <calculate_snapshot+0x40>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@RAND_MAX = global i64 0
@M_PI = global double 0.000000e+00
define void @calculate_snapshot([1000 x double]* %0, [1000 x double]* %1) {
%3 = alloca [1000 x double]*
%4 = alloca [1000 x double]*
%5 = alloca double
%6 = alloca double
%7 = alloca i32
%8 = alloca i32
%9 = alloca double
store [1000 x double]* %0, [1000 x double]** %3
store [1000 x double]* %1, [1000 x double]** %4
%10 = call double @pow(i32 10, i32 10)
store double %10, double* %5
store i32 0, i32* %7
br label %11
11: ; preds = %71, %2
%12 = load i32, i32* %7
%13 = icmp slt i32 %12, 1000
br i1 %13, label %14, label %74
14: ; preds = %11
%15 = call i64 (...) @rand()
%16 = sitofp i64 %15 to double
%17 = load i64, i64* @RAND_MAX
%18 = sitofp i64 %17 to double
%19 = fdiv double %16, %18
%20 = load double, double* @M_PI
%21 = load double, double* @M_PI
%22 = fdiv double %21, 2.000000e+00
%23 = fneg double %22
%24 = call double @llvm.fmuladd.f64(double %19, double %20, double %23)
store double %24, double* %9
%25 = load double, double* @M_PI
%26 = fmul double 2.000000e+00, %25
%27 = fmul double %26, 2.000000e-02
%28 = load double, double* %9
%29 = fptosi double %28 to i32
%30 = call double @sin(i32 %29)
%31 = fmul double %27, %30
%32 = fdiv double %31, 4.000000e-02
store double %32, double* %6
store i32 0, i32* %8
br label %33
33: ; preds = %67, %14
%34 = load i32, i32* %8
%35 = icmp slt i32 %34, 1000
br i1 %35, label %36, label %70
36: ; preds = %33
%37 = load i32, i32* %8
%38 = sitofp i32 %37 to double
%39 = load double, double* %6
%40 = fmul double %38, %39
%41 = fptosi double %40 to i32
%42 = call double @cos(i32 %41)
%43 = load double, double* %5
%44 = fmul double %42, %43
%45 = load [1000 x double]*, [1000 x double]** %3
%46 = load i32, i32* %7
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds [1000 x double], [1000 x double]* %45, i64 %47
%49 = load i32, i32* %8
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds [1000 x double], [1000 x double]* %48, i64 0, i64 %50
store double %44, double* %51
%52 = load i32, i32* %8
%53 = sitofp i32 %52 to double
%54 = load double, double* %6
%55 = fmul double %53, %54
%56 = fptosi double %55 to i32
%57 = call double @sin(i32 %56)
%58 = load double, double* %5
%59 = fmul double %57, %58
%60 = load [1000 x double]*, [1000 x double]** %4
%61 = load i32, i32* %7
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds [1000 x double], [1000 x double]* %60, i64 %62
%64 = load i32, i32* %8
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds [1000 x double], [1000 x double]* %63, i64 0, i64 %65
store double %59, double* %66
br label %67
67: ; preds = %36
%68 = load i32, i32* %8
%69 = add nsw i32 %68, 1
store i32 %69, i32* %8
br label %33
70: ; preds = %33
br label %71
71: ; preds = %70
%72 = load i32, i32* %7
%73 = add nsw i32 %72, 1
store i32 %73, i32* %7
br label %11
74: ; preds = %11
ret void
}

LLVM IR (-O2):
@RAND_MAX = global i64 0
@M_PI = global double 0.000000e+00
define void @calculate_snapshot([1000 x double]* nocapture writeonly %0, [1000 x double]* nocapture writeonly %1) {
%3 = tail call double @pow(i32 10, i32 10)
br label %4
4: ; preds = %2, %34
%5 = phi i64 [ 0, %2 ], [ %35, %34 ]
%6 = tail call i64 (...) @rand()
%7 = sitofp i64 %6 to double
%8 = load i64, i64* @RAND_MAX
%9 = sitofp i64 %8 to double
%10 = fdiv double %7, %9
%11 = load double, double* @M_PI
%12 = fmul double %11, -5.000000e-01
%13 = tail call double @llvm.fmuladd.f64(double %10, double %11, double %12)
%14 = fmul double %11, 2.000000e+00
%15 = fmul double %14, 2.000000e-02
%16 = fptosi double %13 to i32
%17 = tail call double @sin(i32 %16)
%18 = fmul double %17, %15
%19 = fdiv double %18, 4.000000e-02
br label %20
20: ; preds = %4, %20
%21 = phi i64 [ 0, %4 ], [ %32, %20 ]
%22 = trunc i64 %21 to i32
%23 = sitofp i32 %22 to double
%24 = fmul double %19, %23
%25 = fptosi double %24 to i32
%26 = tail call double @cos(i32 %25)
%27 = fmul double %3, %26
%28 = getelementptr inbounds [1000 x double], [1000 x double]* %0, i64 %5, i64 %21
store double %27, double* %28
%29 = tail call double @sin(i32 %25)
%30 = fmul double %3, %29
%31 = getelementptr inbounds [1000 x double], [1000 x double]* %1, i64 %5, i64 %21
store double %30, double* %31
%32 = add nuw nsw i64 %21, 1
%33 = icmp eq i64 %32, 1000
br i1 %33, label %34, label %20
34: ; preds = %20
%35 = add nuw nsw i64 %5, 1
%36 = icmp eq i64 %35, 1000
br i1 %36, label %37, label %4
37: ; preds = %34
ret void
}