#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 */
struct gor_t {
  int dummy;
};

/* Variables and functions */
double M_PI;
int /*<<< orphan*/ free(double *);
double *make_h(struct gor_t *, int, double, double, double, double);
int /*<<< orphan*/ printf(char *, double, double);
scalar_t__ rint(double);
double sin(double);
void structure_factor(struct gor_t *gor, int num_gor, double density,
                      double extrapolation_point, double A, double r0,
                      double r1) {
  int i, j;
  double *h;
  int sk_lower_bound, sk_upper_bound;
  int h_lower_bound, h_upper_bound;
  double integral, k, r;
  double resolution = 0.001;
  sk_lower_bound = (int)rint(((double)0) / resolution);
  ++sk_lower_bound;
  sk_upper_bound = (int)rint(((double)10) / resolution);
  h_lower_bound = (int)rint(((double)0) / resolution);
  ++h_lower_bound;
  h_upper_bound = (int)rint(((double)100) / resolution);
  h = make_h(gor, num_gor, extrapolation_point, A, r0, r1);
  for (i = sk_lower_bound; i < sk_upper_bound; i++) {
    k = ((double)i) * resolution;
    integral = 0.0;
    for (j = h_lower_bound; j < h_upper_bound; j++) {
      r = ((double)j) * resolution;
      integral += h[j] * r * sin(k * r);
    }
    integral -= 0.5 * (h[h_lower_bound] + h[h_upper_bound - 1]);
    integral *= resolution;
    integral *= (4.0 * M_PI * density / k);
    integral += 1.0;
    printf("%f %f\n", k, integral);
  }
  free(h);
}


x86 assembly (clang, -O0):
<structure_factor>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movsd  %xmm0,-0x18(%rbp)
movsd  %xmm1,-0x20(%rbp)
movsd  %xmm2,-0x28(%rbp)
movsd  %xmm3,-0x30(%rbp)
movsd  %xmm4,-0x38(%rbp)
movsd  0xe8d(%rip),%xmm0
movsd  %xmm0,-0x78(%rbp)
xorps  %xmm0,%xmm0
divsd  -0x78(%rbp),%xmm0
call   1070 <rint@plt>
mov    %eax,-0x4c(%rbp)
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4c(%rbp)
movsd  0xe5f(%rip),%xmm0
divsd  -0x78(%rbp),%xmm0
call   1070 <rint@plt>
mov    %eax,-0x50(%rbp)
xorps  %xmm0,%xmm0
divsd  -0x78(%rbp),%xmm0
call   1070 <rint@plt>
mov    %eax,-0x54(%rbp)
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
movsd  0xe29(%rip),%xmm0
divsd  -0x78(%rbp),%xmm0
call   1070 <rint@plt>
mov    %eax,-0x58(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
movsd  -0x20(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
movsd  -0x30(%rbp),%xmm2
movsd  -0x38(%rbp),%xmm3
call   1040 <make_h@plt>
mov    %rax,-0x48(%rbp)
mov    -0x4c(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x50(%rbp),%eax
jge    1345 <structure_factor+0x1f5>
cvtsi2sdl -0x3c(%rbp),%xmm0
mulsd  -0x78(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x60(%rbp)
mov    -0x54(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    -0x40(%rbp),%eax
cmp    -0x58(%rbp),%eax
jge    12a0 <structure_factor+0x150>
cvtsi2sdl -0x40(%rbp),%xmm0
mulsd  -0x78(%rbp),%xmm0
movsd  %xmm0,-0x70(%rbp)
mov    -0x48(%rbp),%rax
movslq -0x40(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mulsd  -0x70(%rbp),%xmm0
movsd  %xmm0,-0x80(%rbp)
movsd  -0x68(%rbp),%xmm0
mulsd  -0x70(%rbp),%xmm0
call   1060 <sin@plt>
movaps %xmm0,%xmm2
movsd  -0x80(%rbp),%xmm0
movsd  -0x60(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x60(%rbp)
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    1237 <structure_factor+0xe7>
mov    -0x48(%rbp),%rax
movslq -0x54(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x48(%rbp),%rax
mov    -0x58(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
addsd  (%rax,%rcx,8),%xmm0
movsd  -0x60(%rbp),%xmm1
movsd  0xd5c(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x78(%rbp),%xmm0
mulsd  -0x60(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  0xd30(%rip),%xmm0
mov    0x2cf1(%rip),%rax
mulsd  (%rax),%xmm0
mulsd  -0x18(%rbp),%xmm0
divsd  -0x68(%rbp),%xmm0
mulsd  -0x60(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  0xd01(%rip),%xmm0
addsd  -0x60(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x68(%rbp),%xmm0
movsd  -0x60(%rbp),%xmm1
lea    0xcfe(%rip),%rdi
call   1050 <printf@plt>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    120e <structure_factor+0xbe>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<structure_factor>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
movsd  %xmm4,0x18(%rsp)
movsd  %xmm3,0x8(%rsp)
movsd  %xmm2,0x10(%rsp)
movsd  %xmm1,0x20(%rsp)
movsd  %xmm0,0x50(%rsp)
mov    %esi,%r14d
mov    %rdi,%rbx
xorps  %xmm0,%xmm0
call   1070 <rint@plt>
mov    %rax,%r12
movsd  0xe6b(%rip),%xmm0
call   1070 <rint@plt>
mov    %rax,%rbp
xorps  %xmm0,%xmm0
call   1070 <rint@plt>
mov    %rax,0x38(%rsp)
movsd  0xe56(%rip),%xmm0
call   1070 <rint@plt>
mov    %rax,%r13
mov    %rbx,%rdi
mov    %r14d,%esi
movsd  0x20(%rsp),%xmm0
movsd  0x10(%rsp),%xmm1
movsd  0x8(%rsp),%xmm2
movsd  0x18(%rsp),%xmm3
call   1040 <make_h@plt>
mov    %rax,%rbx
add    $0x1,%r12d
mov    %rbp,0x20(%rsp)
cmp    %ebp,%r12d
jge    13d4 <structure_factor+0x284>
mov    0x38(%rsp),%rcx
lea    0x1(%rcx),%eax
mov    %eax,0x34(%rsp)
movslq %eax,%r15
lea    -0x1(%r13),%eax
movslq %eax,%r14
mov    %ecx,%eax
not    %eax
add    %r13d,%eax
mov    %eax,0x30(%rsp)
xorps  %xmm0,%xmm0
cvtsi2sd %r15d,%xmm0
mulsd  0xded(%rip),%xmm0
movsd  %xmm0,0x48(%rsp)
lea    -0x2(%r13),%eax
mov    %eax,0x2c(%rsp)
lea    0x1(%r15),%rax
mov    %rax,0x40(%rsp)
movsd  0xdce(%rip),%xmm1
jmp    12bc <structure_factor+0x16c>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsd  (%rbx,%r15,8),%xmm3
addsd  (%rbx,%r14,8),%xmm3
mulsd  0xdb4(%rip),%xmm3
addsd  %xmm0,%xmm3
mulsd  %xmm1,%xmm3
mov    0x2d75(%rip),%rax
movsd  (%rax),%xmm1
mulsd  0xda1(%rip),%xmm1
mulsd  0x50(%rsp),%xmm1
divsd  %xmm2,%xmm1
mulsd  %xmm3,%xmm1
addsd  0xd93(%rip),%xmm1
lea    0xd9c(%rip),%rdi
movapd %xmm2,%xmm0
call   1050 <printf@plt>
movsd  0xd63(%rip),%xmm1
add    $0x1,%r12d
cmp    0x20(%rsp),%r12d
je     13d4 <structure_factor+0x284>
xorps  %xmm2,%xmm2
cvtsi2sd %r12d,%xmm2
mulsd  %xmm1,%xmm2
xorpd  %xmm0,%xmm0
cmp    %r13d,0x34(%rsp)
jge    1250 <structure_factor+0x100>
xorpd  %xmm0,%xmm0
mov    %r15,%rbp
testb  $0x1,0x30(%rsp)
movsd  %xmm2,0x18(%rsp)
je     132f <structure_factor+0x1df>
movsd  (%rbx,%r15,8),%xmm0
movsd  0x48(%rsp),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,0x8(%rsp)
mulsd  %xmm1,%xmm2
movapd %xmm2,%xmm0
call   1060 <sin@plt>
movsd  0x18(%rsp),%xmm2
movsd  0xcf4(%rip),%xmm1
mulsd  0x8(%rsp),%xmm0
addsd  0xd06(%rip),%xmm0
mov    0x40(%rsp),%rbp
mov    0x2c(%rsp),%eax
cmp    0x38(%rsp),%eax
je     1250 <structure_factor+0x100>
nopl   (%rax)
movsd  %xmm0,0x10(%rsp)
xorps  %xmm4,%xmm4
cvtsi2sd %ebp,%xmm4
mulsd  %xmm1,%xmm4
mulsd  %xmm4,%xmm2
mulsd  (%rbx,%rbp,8),%xmm4
movsd  %xmm4,0x8(%rsp)
movapd %xmm2,%xmm0
call   1060 <sin@plt>
mulsd  0x8(%rsp),%xmm0
addsd  0x10(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
lea    0x1(%rbp),%eax
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
mulsd  0xc83(%rip),%xmm1
movsd  0x18(%rsp),%xmm0
mulsd  %xmm1,%xmm0
mulsd  0x8(%rbx,%rbp,8),%xmm1
movsd  %xmm1,0x10(%rsp)
call   1060 <sin@plt>
movsd  0x18(%rsp),%xmm2
movsd  0xc5a(%rip),%xmm1
mulsd  0x10(%rsp),%xmm0
addsd  0x8(%rsp),%xmm0
add    $0x2,%rbp
cmp    %r13d,%ebp
jne    1340 <structure_factor+0x1f0>
jmp    1250 <structure_factor+0x100>
mov    %rbx,%rdi
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
%struct.gor_t = type { i32 }
@M_PI = global double 0.000000e+00
@.str = [7 x i8] c"%f %f\0A\00"
define void @structure_factor(%struct.gor_t* %0, i32 %1, double %2, double %3, double %4, double %5, double %6) {
%8 = alloca %struct.gor_t*
%9 = alloca i32
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca double
%14 = alloca double
%15 = alloca i32
%16 = alloca i32
%17 = alloca double*
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
%21 = alloca i32
%22 = alloca double
%23 = alloca double
%24 = alloca double
%25 = alloca double
store %struct.gor_t* %0, %struct.gor_t** %8
store i32 %1, i32* %9
store double %2, double* %10
store double %3, double* %11
store double %4, double* %12
store double %5, double* %13
store double %6, double* %14
store double 1.000000e-03, double* %25
%26 = load double, double* %25
%27 = fdiv double 0.000000e+00, %26
%28 = call i64 @rint(double %27)
%29 = trunc i64 %28 to i32
store i32 %29, i32* %18
%30 = load i32, i32* %18
%31 = add nsw i32 %30, 1
store i32 %31, i32* %18
%32 = load double, double* %25
%33 = fdiv double 1.000000e+01, %32
%34 = call i64 @rint(double %33)
%35 = trunc i64 %34 to i32
store i32 %35, i32* %19
%36 = load double, double* %25
%37 = fdiv double 0.000000e+00, %36
%38 = call i64 @rint(double %37)
%39 = trunc i64 %38 to i32
store i32 %39, i32* %20
%40 = load i32, i32* %20
%41 = add nsw i32 %40, 1
store i32 %41, i32* %20
%42 = load double, double* %25
%43 = fdiv double 1.000000e+02, %42
%44 = call i64 @rint(double %43)
%45 = trunc i64 %44 to i32
store i32 %45, i32* %21
%46 = load %struct.gor_t*, %struct.gor_t** %8
%47 = load i32, i32* %9
%48 = load double, double* %11
%49 = load double, double* %12
%50 = load double, double* %13
%51 = load double, double* %14
%52 = call double* @make_h(%struct.gor_t* %46, i32 %47, double %48, double %49, double %50, double %51)
store double* %52, double** %17
%53 = load i32, i32* %18
store i32 %53, i32* %15
br label %54
54: ; preds = %120, %7
%55 = load i32, i32* %15
%56 = load i32, i32* %19
%57 = icmp slt i32 %55, %56
br i1 %57, label %58, label %123
58: ; preds = %54
%59 = load i32, i32* %15
%60 = sitofp i32 %59 to double
%61 = load double, double* %25
%62 = fmul double %60, %61
store double %62, double* %23
store double 0.000000e+00, double* %22
%63 = load i32, i32* %20
store i32 %63, i32* %16
br label %64
64: ; preds = %86, %58
%65 = load i32, i32* %16
%66 = load i32, i32* %21
%67 = icmp slt i32 %65, %66
br i1 %67, label %68, label %89
68: ; preds = %64
%69 = load i32, i32* %16
%70 = sitofp i32 %69 to double
%71 = load double, double* %25
%72 = fmul double %70, %71
store double %72, double* %24
%73 = load double*, double** %17
%74 = load i32, i32* %16
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds double, double* %73, i64 %75
%77 = load double, double* %76
%78 = load double, double* %24
%79 = fmul double %77, %78
%80 = load double, double* %23
%81 = load double, double* %24
%82 = fmul double %80, %81
%83 = call double @sin(double %82)
%84 = load double, double* %22
%85 = call double @llvm.fmuladd.f64(double %79, double %83, double %84)
store double %85, double* %22
br label %86
86: ; preds = %68
%87 = load i32, i32* %16
%88 = add nsw i32 %87, 1
store i32 %88, i32* %16
br label %64
89: ; preds = %64
%90 = load double*, double** %17
%91 = load i32, i32* %20
%92 = sext i32 %91 to i64
%93 = getelementptr inbounds double, double* %90, i64 %92
%94 = load double, double* %93
%95 = load double*, double** %17
%96 = load i32, i32* %21
%97 = sub nsw i32 %96, 1
%98 = sext i32 %97 to i64
%99 = getelementptr inbounds double, double* %95, i64 %98
%100 = load double, double* %99
%101 = fadd double %94, %100
%102 = load double, double* %22
%103 = call double @llvm.fmuladd.f64(double -5.000000e-01, double %101, double %102)
store double %103, double* %22
%104 = load double, double* %25
%105 = load double, double* %22
%106 = fmul double %105, %104
store double %106, double* %22
%107 = load double, double* @M_PI
%108 = fmul double 4.000000e+00, %107
%109 = load double, double* %10
%110 = fmul double %108, %109
%111 = load double, double* %23
%112 = fdiv double %110, %111
%113 = load double, double* %22
%114 = fmul double %113, %112
store double %114, double* %22
%115 = load double, double* %22
%116 = fadd double %115, 1.000000e+00
store double %116, double* %22
%117 = load double, double* %23
%118 = load double, double* %22
%119 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), double %117, double %118)
br label %120
120: ; preds = %89
%121 = load i32, i32* %15
%122 = add nsw i32 %121, 1
store i32 %122, i32* %15
br label %54
123: ; preds = %54
%124 = load double*, double** %17
%125 = call i32 @free(double* %124)
ret void
}

LLVM IR (-O2):
%struct.gor_t = type { i32 }
@M_PI = global double 0.000000e+00
@.str = [7 x i8] c"%f %f\0A\00"
define void @structure_factor(%struct.gor_t* %0, i32 %1, double %2, double %3, double %4, double %5, double %6) {
%8 = tail call i64 @rint(double 0.000000e+00)
%9 = trunc i64 %8 to i32
%10 = tail call i64 @rint(double 1.000000e+04)
%11 = trunc i64 %10 to i32
%12 = tail call i64 @rint(double 0.000000e+00)
%13 = trunc i64 %12 to i32
%14 = add i32 %13, 1
%15 = tail call i64 @rint(double 1.000000e+05)
%16 = trunc i64 %15 to i32
%17 = tail call double* @make_h(%struct.gor_t* %0, i32 %1, double %3, double %4, double %5, double %6)
%18 = add nsw i32 %9, 1
%19 = icmp slt i32 %18, %11
br i1 %19, label %20, label %94
20: ; preds = %7
%21 = icmp slt i32 %14, %16
%22 = sext i32 %14 to i64
%23 = getelementptr inbounds double, double* %17, i64 %22
%24 = shl i64 %15, 32
%25 = add i64 %24, -4294967296
%26 = ashr exact i64 %25, 32
%27 = getelementptr inbounds double, double* %17, i64 %26
%28 = xor i32 %13, -1
%29 = add i32 %28, %16
%30 = add i32 %16, -2
%31 = and i32 %29, 1
%32 = icmp eq i32 %31, 0
%33 = sitofp i32 %14 to double
%34 = fmul double %33, 1.000000e-03
%35 = getelementptr inbounds double, double* %17, i64 %22
%36 = add nsw i64 %22, 1
%37 = icmp eq i32 %30, %13
br label %38
38: ; preds = %20, %78
%39 = phi i32 [ %18, %20 ], [ %92, %78 ]
%40 = sitofp i32 %39 to double
%41 = fmul double %40, 1.000000e-03
br i1 %21, label %42, label %78
42: ; preds = %38
br i1 %32, label %49, label %43
43: ; preds = %42
%44 = load double, double* %35
%45 = fmul double %34, %44
%46 = fmul double %41, %34
%47 = tail call double @sin(double %46)
%48 = tail call double @llvm.fmuladd.f64(double %45, double %47, double 0.000000e+00)
br label %49
49: ; preds = %43, %42
%50 = phi double [ undef, %42 ], [ %48, %43 ]
%51 = phi i64 [ %22, %42 ], [ %36, %43 ]
%52 = phi double [ 0.000000e+00, %42 ], [ %48, %43 ]
br i1 %37, label %78, label %53
53: ; preds = %49, %53
%54 = phi i64 [ %75, %53 ], [ %51, %49 ]
%55 = phi double [ %74, %53 ], [ %52, %49 ]
%56 = trunc i64 %54 to i32
%57 = sitofp i32 %56 to double
%58 = fmul double %57, 1.000000e-03
%59 = getelementptr inbounds double, double* %17, i64 %54
%60 = load double, double* %59
%61 = fmul double %58, %60
%62 = fmul double %41, %58
%63 = tail call double @sin(double %62)
%64 = tail call double @llvm.fmuladd.f64(double %61, double %63, double %55)
%65 = add nsw i64 %54, 1
%66 = trunc i64 %65 to i32
%67 = sitofp i32 %66 to double
%68 = fmul double %67, 1.000000e-03
%69 = getelementptr inbounds double, double* %17, i64 %65
%70 = load double, double* %69
%71 = fmul double %68, %70
%72 = fmul double %41, %68
%73 = tail call double @sin(double %72)
%74 = tail call double @llvm.fmuladd.f64(double %71, double %73, double %64)
%75 = add nsw i64 %54, 2
%76 = trunc i64 %75 to i32
%77 = icmp eq i32 %76, %16
br i1 %77, label %78, label %53
78: ; preds = %49, %53, %38
%79 = phi double [ 0.000000e+00, %38 ], [ %50, %49 ], [ %74, %53 ]
%80 = load double, double* %23
%81 = load double, double* %27
%82 = fadd double %80, %81
%83 = tail call double @llvm.fmuladd.f64(double %82, double -5.000000e-01, double %79)
%84 = fmul double %83, 1.000000e-03
%85 = load double, double* @M_PI
%86 = fmul double %85, 4.000000e+00
%87 = fmul double %86, %2
%88 = fdiv double %87, %41
%89 = fmul double %84, %88
%90 = fadd double %89, 1.000000e+00
%91 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), double %41, double %90)
%92 = add i32 %39, 1
%93 = icmp eq i32 %92, %11
br i1 %93, label %94, label %38
94: ; preds = %78, %7
%95 = tail call i32 @free(double* %17)
ret void
}