#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 */
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *, float *, float *);
int sin(float);
int main() {
  int N;
  float L, x, answer = 0;
  do {
    printf("Enter values for N, L and x: ");
    scanf("%d %f %f", &N, &L, &x);
  } while (N <= 0 || L <= 0 || x <= 0 || 0.05 * L > x || x > 0.95 * L);
  int i;
  for (i = 1; i <= N; i++) {
    float s = 2 * (i - 1) + 1;
    answer += 1 / s * sin((s * 3.1415926535897932385 * x) / L);
  }
  answer *= (float)(4 / 3.1415926535897932385);
  printf("%d-term Fourier series evaluates to %.4f at x=%.2f", N, answer, x);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x14(%rbp)
lea    0xed2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xee2(%rip),%rdi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
lea    -0x10(%rbp),%rcx
call   1050 <scanf@plt>
mov    $0x1,%al
cmpl   $0x0,-0x8(%rbp)
mov    %al,-0x1d(%rbp)
jle    11f5 <main+0xc5>
mov    $0x1,%al
xorps  %xmm0,%xmm0
ucomiss -0xc(%rbp),%xmm0
mov    %al,-0x1d(%rbp)
jae    11f5 <main+0xc5>
mov    $0x1,%al
xorps  %xmm0,%xmm0
ucomiss -0x10(%rbp),%xmm0
mov    %al,-0x1d(%rbp)
jae    11f5 <main+0xc5>
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xe4f(%rip),%xmm0
mulsd  %xmm1,%xmm0
movss  -0x10(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
mov    $0x1,%al
ucomisd %xmm1,%xmm0
mov    %al,-0x1d(%rbp)
ja     11f5 <main+0xc5>
movss  -0x10(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movss  -0xc(%rbp),%xmm1
cvtss2sd %xmm1,%xmm2
movsd  0xe21(%rip),%xmm1
mulsd  %xmm2,%xmm1
ucomisd %xmm1,%xmm0
seta   %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    1147 <main+0x17>
movl   $0x1,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     129b <main+0x16b>
mov    -0x18(%rbp),%eax
sub    $0x1,%eax
shl    $0x1,%eax
add    $0x1,%eax
cvtsi2ss %eax,%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  0xdec(%rip),%xmm0
divss  -0x1c(%rbp),%xmm0
movss  %xmm0,-0x24(%rbp)
movss  -0x1c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xdc5(%rip),%xmm1
mulsd  %xmm1,%xmm0
movss  -0x10(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
mulsd  %xmm1,%xmm0
movss  -0xc(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
call   1040 <sin@plt>
movss  -0x24(%rbp),%xmm0
cvtsi2ss %eax,%xmm2
movss  -0x14(%rbp),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x14(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1207 <main+0xd7>
movss  0xd75(%rip),%xmm0
mulss  -0x14(%rbp),%xmm0
movss  %xmm0,-0x14(%rbp)
mov    -0x8(%rbp),%esi
movss  -0x14(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movss  -0x10(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
lea    0xd7e(%rip),%rdi
mov    $0x2,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xedf(%rip),%r14
lea    0xef6(%rip),%r15
lea    0xc(%rsp),%r12
lea    0x8(%rsp),%r13
lea    0x4(%rsp),%rbx
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %r13,%rdx
mov    %rbx,%rcx
call   1050 <scanf@plt>
cmpl   $0x0,0xc(%rsp)
jle    1160 <main+0x30>
movss  0x8(%rsp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm0,%xmm1
jae    1160 <main+0x30>
movss  0x4(%rsp),%xmm1
xorps  %xmm2,%xmm2
ucomiss %xmm1,%xmm2
jae    1160 <main+0x30>
xorps  %xmm2,%xmm2
cvtss2sd %xmm0,%xmm2
movaps %xmm2,%xmm4
mulsd  0xe50(%rip),%xmm4
xorps  %xmm3,%xmm3
cvtss2sd %xmm1,%xmm3
ucomisd %xmm3,%xmm4
mulsd  0xe45(%rip),%xmm2
ja     1160 <main+0x30>
ucomisd %xmm2,%xmm3
ja     1160 <main+0x30>
xorps  %xmm2,%xmm2
mov    $0x1,%ebx
mov    $0x1,%ebp
nopl   0x0(%rax,%rax,1)
movss  %xmm2,0x14(%rsp)
xorps  %xmm2,%xmm2
cvtsi2ss %ebx,%xmm2
movss  0xe23(%rip),%xmm3
divss  %xmm2,%xmm3
movss  %xmm3,0x10(%rsp)
cvtss2sd %xmm2,%xmm2
mulsd  0xe05(%rip),%xmm2
cvtss2sd %xmm1,%xmm1
mulsd  %xmm2,%xmm1
cvtss2sd %xmm0,%xmm0
divsd  %xmm0,%xmm1
xorps  %xmm0,%xmm0
cvtsd2ss %xmm1,%xmm0
call   1040 <sin@plt>
xorps  %xmm2,%xmm2
cvtsi2ss %eax,%xmm2
mulss  0x10(%rsp),%xmm2
addss  0x14(%rsp),%xmm2
mov    0xc(%rsp),%esi
cmp    %esi,%ebp
jge    1256 <main+0x126>
add    $0x1,%ebp
movss  0x4(%rsp),%xmm1
movss  0x8(%rsp),%xmm0
add    $0x2,%ebx
jmp    11e0 <main+0xb0>
movss  0x4(%rsp),%xmm0
xorps  %xmm1,%xmm1
cvtss2sd %xmm0,%xmm1
mulss  0xdb1(%rip),%xmm2
xorps  %xmm0,%xmm0
cvtss2sd %xmm2,%xmm0
lea    0xdd2(%rip),%rdi
mov    $0x2,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [30 x i8] c"Enter values for N, L and x: \00"
@.str.1 = [9 x i8] c"%d %f %f\00"
@.str.2 = [51 x i8] c"%d-term Fourier series evaluates to %.4f at x=%.2f\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca float
%4 = alloca float
%5 = alloca float
%6 = alloca i32
%7 = alloca float
store i32 0, i32* %1
store float 0.000000e+00, float* %5
br label %8
8: ; preds = %34, %0
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32* %2, float* %3, float* %4)
br label %11
11: ; preds = %8
%12 = load i32, i32* %2
%13 = icmp sle i32 %12, 0
br i1 %13, label %34, label %14
14: ; preds = %11
%15 = load float, float* %3
%16 = fcmp ole float %15, 0.000000e+00
br i1 %16, label %34, label %17
17: ; preds = %14
%18 = load float, float* %4
%19 = fcmp ole float %18, 0.000000e+00
br i1 %19, label %34, label %20
20: ; preds = %17
%21 = load float, float* %3
%22 = fpext float %21 to double
%23 = fmul double 5.000000e-02, %22
%24 = load float, float* %4
%25 = fpext float %24 to double
%26 = fcmp ogt double %23, %25
br i1 %26, label %34, label %27
27: ; preds = %20
%28 = load float, float* %4
%29 = fpext float %28 to double
%30 = load float, float* %3
%31 = fpext float %30 to double
%32 = fmul double 0x3FEE666666666666, %31
%33 = fcmp ogt double %29, %32
br label %34
34: ; preds = %27, %20, %17, %14, %11
%35 = phi i1 [ true, %20 ], [ true, %17 ], [ true, %14 ], [ true, %11 ], [ %33, %27 ]
br i1 %35, label %8, label %36
36: ; preds = %34
store i32 1, i32* %6
br label %37
37: ; preds = %63, %36
%38 = load i32, i32* %6
%39 = load i32, i32* %2
%40 = icmp sle i32 %38, %39
br i1 %40, label %41, label %66
41: ; preds = %37
%42 = load i32, i32* %6
%43 = sub nsw i32 %42, 1
%44 = mul nsw i32 2, %43
%45 = add nsw i32 %44, 1
%46 = sitofp i32 %45 to float
store float %46, float* %7
%47 = load float, float* %7
%48 = fdiv float 1.000000e+00, %47
%49 = load float, float* %7
%50 = fpext float %49 to double
%51 = fmul double %50, 0x400921FB54442D18
%52 = load float, float* %4
%53 = fpext float %52 to double
%54 = fmul double %51, %53
%55 = load float, float* %3
%56 = fpext float %55 to double
%57 = fdiv double %54, %56
%58 = fptrunc double %57 to float
%59 = call i32 @sin(float %58)
%60 = sitofp i32 %59 to float
%61 = load float, float* %5
%62 = call float @llvm.fmuladd.f32(float %48, float %60, float %61)
store float %62, float* %5
br label %63
63: ; preds = %41
%64 = load i32, i32* %6
%65 = add nsw i32 %64, 1
store i32 %65, i32* %6
br label %37
66: ; preds = %37
%67 = load float, float* %5
%68 = fmul float %67, 0x3FF45F3060000000
store float %68, float* %5
%69 = load i32, i32* %2
%70 = load float, float* %5
%71 = fpext float %70 to double
%72 = load float, float* %4
%73 = fpext float %72 to double
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.2, i64 0, i64 0), i32 %69, double %71, double %73)
ret i32 0
}

LLVM IR (-O2):
@.str = [30 x i8] c"Enter values for N, L and x: \00"
@.str.1 = [9 x i8] c"%d %f %f\00"
@.str.2 = [51 x i8] c"%d-term Fourier series evaluates to %.4f at x=%.2f\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca float
%3 = alloca float
%4 = bitcast i32* %1 to i8*
%5 = bitcast float* %2 to i8*
%6 = bitcast float* %3 to i8*
br label %7
7: ; preds = %26, %0
%8 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32* %1, float* %2, float* %3)
%10 = load i32, i32* %1
%11 = icmp slt i32 %10, 1
%12 = load float, float* %2
%13 = fcmp ole float %12, 0.000000e+00
%14 = select i1 %11, i1 true, i1 %13
%15 = load float, float* %3
%16 = fcmp ole float %15, 0.000000e+00
%17 = select i1 %14, i1 true, i1 %16
br i1 %17, label %26, label %18
18: ; preds = %7
%19 = fpext float %12 to double
%20 = fmul double %19, 5.000000e-02
%21 = fpext float %15 to double
%22 = fcmp ogt double %20, %21
%23 = fmul double %19, 0x3FEE666666666666
%24 = fcmp olt double %23, %21
%25 = or i1 %22, %24
br i1 %25, label %26, label %27
26: ; preds = %18, %7
br label %7
27: ; preds = %18, %48
%28 = phi float [ %51, %48 ], [ %12, %18 ]
%29 = phi float [ %50, %48 ], [ %15, %18 ]
%30 = phi float [ %45, %48 ], [ 0.000000e+00, %18 ]
%31 = phi i32 [ %49, %48 ], [ 1, %18 ]
%32 = shl nuw i32 %31, 1
%33 = add i32 %32, -1
%34 = sitofp i32 %33 to float
%35 = fdiv float 1.000000e+00, %34
%36 = fpext float %34 to double
%37 = fmul double %36, 0x400921FB54442D18
%38 = fpext float %29 to double
%39 = fmul double %37, %38
%40 = fpext float %28 to double
%41 = fdiv double %39, %40
%42 = fptrunc double %41 to float
%43 = call i32 @sin(float %42)
%44 = sitofp i32 %43 to float
%45 = call float @llvm.fmuladd.f32(float %35, float %44, float %30)
%46 = load i32, i32* %1
%47 = icmp slt i32 %31, %46
br i1 %47, label %48, label %52
48: ; preds = %27
%49 = add nuw nsw i32 %31, 1
%50 = load float, float* %3
%51 = load float, float* %2
br label %27
52: ; preds = %27
%53 = load float, float* %3
%54 = fpext float %53 to double
%55 = fmul float %45, 0x3FF45F3060000000
%56 = fpext float %55 to double
%57 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @.str.2, i64 0, i64 0), i32 %46, double %56, double %54)
ret i32 0
}