#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 *, double);
int sqrt(int);
void trapezoid() {
  int k;
  double a, b, n, h, x, s, sum;
  a = 0;
  b = 2;
  n = 50;
  h = (b - a) / n;
  x = a;
  s = 0;
  for (k = 1; k <= n - 1; k++) {
    x = x + h;
    s = s + (sqrt(4 - x * x));
  }
  sum = h * (((sqrt(4 - a * a)) + (sqrt(4 - b * b))) / 2 + s);
  printf("    /%f\n", b);
  printf("    sqrt(4 - x * x) = %f\n", sum);
  printf("    /%f\n", a);
}


x86 assembly (clang, -O0):
<trapezoid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  0xed0(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xebb(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
divsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
movl   $0x1,-0x4(%rbp)
cvtsi2sdl -0x4(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm0
movsd  0xe87(%rip),%xmm2
subsd  %xmm2,%xmm0
ucomisd %xmm1,%xmm0
jb     120a <trapezoid+0xea>
movsd  -0x30(%rbp),%xmm0
addsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm1
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm1,%xmm0
movsd  0xe3b(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1040 <sqrt@plt>
movsd  -0x48(%rbp),%xmm0
cvtsi2sd %eax,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1177 <trapezoid+0x57>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm1,%xmm0
movsd  0xdd7(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1040 <sqrt@plt>
mov    %eax,-0x4c(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm1,%xmm0
movsd  0xd9a(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1040 <sqrt@plt>
movsd  -0x58(%rbp),%xmm0
mov    %eax,%ecx
mov    -0x4c(%rbp),%eax
add    %ecx,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cvtsi2sd %eax,%xmm1
addsd  -0x38(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x18(%rbp),%xmm0
lea    0xd63(%rip),%rdi
call   1030 <printf@plt>
movsd  -0x40(%rbp),%xmm0
lea    0xd5b(%rip),%rdi
call   1030 <printf@plt>
movsd  -0x10(%rbp),%xmm0
lea    0xd41(%rip),%rdi
call   1030 <printf@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<trapezoid>:
push   %rbx
sub    $0x10,%rsp
xorpd  %xmm0,%xmm0
movsd  %xmm0,(%rsp)
mov    $0x30,%ebx
xorpd  %xmm0,%xmm0
nopw   0x0(%rax,%rax,1)
addsd  0xeb8(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
mulsd  %xmm0,%xmm0
movsd  0xeae(%rip),%xmm1
subsd  %xmm0,%xmm1
cvttsd2si %xmm1,%edi
call   1040 <sqrt@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
addsd  (%rsp),%xmm0
movsd  %xmm0,(%rsp)
test   %ebx,%ebx
je     11cc <trapezoid+0xac>
movsd  0x8(%rsp),%xmm0
addsd  0xe76(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
mulsd  %xmm0,%xmm0
movsd  0xe6c(%rip),%xmm1
subsd  %xmm0,%xmm1
cvttsd2si %xmm1,%edi
call   1040 <sqrt@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  (%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  0x8(%rsp),%xmm0
add    $0xfffffffe,%ebx
movsd  %xmm1,(%rsp)
jmp    1140 <trapezoid+0x20>
mov    $0x4,%edi
call   1040 <sqrt@plt>
mov    %eax,%ebx
xor    %edi,%edi
call   1040 <sqrt@plt>
add    %ebx,%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
add    %eax,%ecx
sar    %ecx
xorps  %xmm0,%xmm0
cvtsi2sd %ecx,%xmm0
movsd  (%rsp),%xmm1
addsd  %xmm0,%xmm1
mulsd  0xdfe(%rip),%xmm1
movsd  %xmm1,(%rsp)
lea    0xe0a(%rip),%rbx
movsd  0xdfa(%rip),%xmm0
mov    %rbx,%rdi
call   1030 <printf@plt>
lea    0xdfc(%rip),%rdi
movsd  (%rsp),%xmm0
call   1030 <printf@plt>
xorps  %xmm0,%xmm0
mov    %rbx,%rdi
add    $0x10,%rsp
pop    %rbx
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [9 x i8] c" /%f\0A\00"
@.str.1 = [26 x i8] c" sqrt(4 - x * x) = %f\0A\00"
define void @trapezoid() {
%1 = alloca i32
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
store double 0.000000e+00, double* %2
store double 2.000000e+00, double* %3
store double 5.000000e+01, double* %4
%9 = load double, double* %3
%10 = load double, double* %2
%11 = fsub double %9, %10
%12 = load double, double* %4
%13 = fdiv double %11, %12
store double %13, double* %5
%14 = load double, double* %2
store double %14, double* %6
store double 0.000000e+00, double* %7
store i32 1, i32* %1
br label %15
15: ; preds = %34, %0
%16 = load i32, i32* %1
%17 = sitofp i32 %16 to double
%18 = load double, double* %4
%19 = fsub double %18, 1.000000e+00
%20 = fcmp ole double %17, %19
br i1 %20, label %21, label %37
21: ; preds = %15
%22 = load double, double* %6
%23 = load double, double* %5
%24 = fadd double %22, %23
store double %24, double* %6
%25 = load double, double* %7
%26 = load double, double* %6
%27 = load double, double* %6
%28 = fneg double %26
%29 = call double @llvm.fmuladd.f64(double %28, double %27, double 4.000000e+00)
%30 = fptosi double %29 to i32
%31 = call i32 @sqrt(i32 %30)
%32 = sitofp i32 %31 to double
%33 = fadd double %25, %32
store double %33, double* %7
br label %34
34: ; preds = %21
%35 = load i32, i32* %1
%36 = add nsw i32 %35, 1
store i32 %36, i32* %1
br label %15
37: ; preds = %15
%38 = load double, double* %5
%39 = load double, double* %2
%40 = load double, double* %2
%41 = fneg double %39
%42 = call double @llvm.fmuladd.f64(double %41, double %40, double 4.000000e+00)
%43 = fptosi double %42 to i32
%44 = call i32 @sqrt(i32 %43)
%45 = load double, double* %3
%46 = load double, double* %3
%47 = fneg double %45
%48 = call double @llvm.fmuladd.f64(double %47, double %46, double 4.000000e+00)
%49 = fptosi double %48 to i32
%50 = call i32 @sqrt(i32 %49)
%51 = add nsw i32 %44, %50
%52 = sdiv i32 %51, 2
%53 = sitofp i32 %52 to double
%54 = load double, double* %7
%55 = fadd double %53, %54
%56 = fmul double %38, %55
store double %56, double* %8
%57 = load double, double* %3
%58 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), double %57)
%59 = load double, double* %8
%60 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), double %59)
%61 = load double, double* %2
%62 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), double %61)
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c" /%f\0A\00"
@.str.1 = [26 x i8] c" sqrt(4 - x * x) = %f\0A\00"
define void @trapezoid() {
br label %1
1: ; preds = %13, %0
%2 = phi i32 [ 1, %0 ], [ %21, %13 ]
%3 = phi double [ 0.000000e+00, %0 ], [ %20, %13 ]
%4 = phi double [ 0.000000e+00, %0 ], [ %14, %13 ]
%5 = fadd double %4, 4.000000e-02
%6 = fneg double %5
%7 = tail call double @llvm.fmuladd.f64(double %6, double %5, double 4.000000e+00)
%8 = fptosi double %7 to i32
%9 = tail call i32 @sqrt(i32 %8)
%10 = sitofp i32 %9 to double
%11 = fadd double %3, %10
%12 = icmp eq i32 %2, 49
br i1 %12, label %22, label %13
13: ; preds = %1
%14 = fadd double %5, 4.000000e-02
%15 = fneg double %14
%16 = tail call double @llvm.fmuladd.f64(double %15, double %14, double 4.000000e+00)
%17 = fptosi double %16 to i32
%18 = tail call i32 @sqrt(i32 %17)
%19 = sitofp i32 %18 to double
%20 = fadd double %11, %19
%21 = add nuw nsw i32 %2, 2
br label %1
22: ; preds = %1
%23 = tail call i32 @sqrt(i32 4)
%24 = tail call i32 @sqrt(i32 0)
%25 = add nsw i32 %24, %23
%26 = sdiv i32 %25, 2
%27 = sitofp i32 %26 to double
%28 = fadd double %11, %27
%29 = fmul double %28, 4.000000e-02
%30 = tail call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), double 2.000000e+00)
%31 = tail call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), double %29)
%32 = tail call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), double 0.000000e+00)
ret void
}