#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*/ pause();
int /*<<< orphan*/ printf(char *, double, double);
int /*<<< orphan*/ system(char *);
void prob2(void) {
  system("clear");
  int loop;
  double centroidx = 0;
  double centroidy = 0;
  double intensitytotal = 0;
  double pixel[][2] = {5.0, -4.0, 4.0, 3.0, -1.0, 6.0, -9.0, 5.0};
  double intensity[] = {.25, .57, .63, .1};
  for (loop = 0; loop <= 3; loop++) {
    centroidx += (pixel[loop][0] * intensity[loop]);
    centroidy += (pixel[loop][1] * intensity[loop]);
  }
  for (loop = 0; loop <= 3; loop++) {
    intensitytotal += intensity[loop];
  }
  centroidx /= intensitytotal;
  centroidy /= intensitytotal;
  printf("Centroid = %.2lf, %.2lf", centroidx, centroidy);
  pause();
}


x86 assembly (clang, -O0):
<prob2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
lea    0xeae(%rip),%rdi
call   1030 <system@plt>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
lea    -0x60(%rbp),%rdi
lea    0xea6(%rip),%rsi
mov    $0x40,%edx
call   1050 <memcpy@plt>
mov    0xed5(%rip),%rax
mov    %rax,-0x80(%rbp)
mov    0xed2(%rip),%rax
mov    %rax,-0x78(%rbp)
mov    0xecf(%rip),%rax
mov    %rax,-0x70(%rbp)
mov    0xecc(%rip),%rax
mov    %rax,-0x68(%rbp)
movl   $0x0,-0x4(%rbp)
cmpl   $0x3,-0x4(%rbp)
jg     122e <prob2+0xee>
movslq -0x4(%rbp),%rcx
lea    -0x60(%rbp),%rax
shl    $0x4,%rcx
add    %rcx,%rax
movsd  (%rax),%xmm0
movslq -0x4(%rbp),%rax
movsd  -0x80(%rbp,%rax,8),%xmm2
movsd  -0x10(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
movslq -0x4(%rbp),%rcx
lea    -0x60(%rbp),%rax
shl    $0x4,%rcx
add    %rcx,%rax
movsd  0x8(%rax),%xmm0
movslq -0x4(%rbp),%rax
movsd  -0x80(%rbp,%rax,8),%xmm2
movsd  -0x18(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    11b7 <prob2+0x77>
movl   $0x0,-0x4(%rbp)
cmpl   $0x3,-0x4(%rbp)
jg     1261 <prob2+0x121>
movslq -0x4(%rbp),%rax
movsd  -0x80(%rbp,%rax,8),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1235 <prob2+0xf5>
movsd  -0x20(%rbp),%xmm1
movsd  -0x10(%rbp),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x20(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
lea    0xd6e(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1060 <pause@plt>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<prob2>:
push   %rax
lea    0xed8(%rip),%rdi
call   1030 <system@plt>
lea    0xed2(%rip),%rdi
movsd  0xeb4(%rip),%xmm0
movsd  0xeb4(%rip),%xmm1
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rcx
jmp    1050 <pause@plt>

LLVM IR (-O0):
@.str = [6 x i8] c"clear\00"
@__const.prob2.pixel = [4 x [2 x double]] [[2 x double] [double 5.000000e+00, double -4.000000e+00], [2 x double] [double 4.000000e+00, double 3.000000e+00], [2 x double] [double -1.000000e+00, double 6.000000e+00], [2 x double] [double -9.000000e+00, double 5.000000e+00]]
@__const.prob2.intensity = [4 x double] [double 2.500000e-01, double 5.700000e-01, double 6.300000e-01, double 1.000000e-01]
@.str.1 = [24 x i8] c"Centroid = %.2lf, %.2lf\00"
define void @prob2() {
%1 = alloca i32
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca [4 x [2 x double]]
%6 = alloca [4 x double]
%7 = call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store double 0.000000e+00, double* %2
store double 0.000000e+00, double* %3
store double 0.000000e+00, double* %4
%8 = bitcast [4 x [2 x double]]* %5 to i8*
%9 = bitcast [4 x double]* %6 to i8*
store i32 0, i32* %1
br label %10
10: ; preds = %36, %0
%11 = load i32, i32* %1
%12 = icmp sle i32 %11, 3
br i1 %12, label %13, label %39
13: ; preds = %10
%14 = load i32, i32* %1
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [4 x [2 x double]], [4 x [2 x double]]* %5, i64 0, i64 %15
%17 = getelementptr inbounds [2 x double], [2 x double]* %16, i64 0, i64 0
%18 = load double, double* %17
%19 = load i32, i32* %1
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [4 x double], [4 x double]* %6, i64 0, i64 %20
%22 = load double, double* %21
%23 = load double, double* %2
%24 = call double @llvm.fmuladd.f64(double %18, double %22, double %23)
store double %24, double* %2
%25 = load i32, i32* %1
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [4 x [2 x double]], [4 x [2 x double]]* %5, i64 0, i64 %26
%28 = getelementptr inbounds [2 x double], [2 x double]* %27, i64 0, i64 1
%29 = load double, double* %28
%30 = load i32, i32* %1
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [4 x double], [4 x double]* %6, i64 0, i64 %31
%33 = load double, double* %32
%34 = load double, double* %3
%35 = call double @llvm.fmuladd.f64(double %29, double %33, double %34)
store double %35, double* %3
br label %36
36: ; preds = %13
%37 = load i32, i32* %1
%38 = add nsw i32 %37, 1
store i32 %38, i32* %1
br label %10
39: ; preds = %10
store i32 0, i32* %1
br label %40
40: ; preds = %50, %39
%41 = load i32, i32* %1
%42 = icmp sle i32 %41, 3
br i1 %42, label %43, label %53
43: ; preds = %40
%44 = load i32, i32* %1
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds [4 x double], [4 x double]* %6, i64 0, i64 %45
%47 = load double, double* %46
%48 = load double, double* %4
%49 = fadd double %48, %47
store double %49, double* %4
br label %50
50: ; preds = %43
%51 = load i32, i32* %1
%52 = add nsw i32 %51, 1
store i32 %52, i32* %1
br label %40
53: ; preds = %40
%54 = load double, double* %4
%55 = load double, double* %2
%56 = fdiv double %55, %54
store double %56, double* %2
%57 = load double, double* %4
%58 = load double, double* %3
%59 = fdiv double %58, %57
store double %59, double* %3
%60 = load double, double* %2
%61 = load double, double* %3
%62 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), double %60, double %61)
%63 = call i32 (...) @pause()
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"clear\00"
@.str.1 = [24 x i8] c"Centroid = %.2lf, %.2lf\00"
define void @prob2() {
%1 = tail call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%2 = tail call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), double 0x3FF4A5294A5294A4, double 0x4009C13D1C13D1C1)
%3 = tail call i32 (...) @pause()
ret void
}