#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 test {
  int dummy;
};

/* Variables and functions */
int fabs(double);
double mean(double *, int);
double sd(double *, int, double);
int /*<<< orphan*/ t_assert_msg(struct test *, int, char *);
int /*<<< orphan*/ t_set_msg(struct test *, char *);
void test_sd(struct test *t) {
  t_set_msg(t, "Testing the standard deviation function...");
  double test_list[] = {3.0, 5.0, 3.0, 6.0, 3.0, 2.0, 4.0, 6.0, 7.0, 4.0, 3.0};
  double test_mean = mean(test_list, 11);
  double result = sd(test_list, 11, test_mean);
  t_assert_msg(t, fabs(result - 1.601136) < 10e-4, "sd function incorrect");
}


x86 assembly (clang, -O0):
<test_sd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe96(%rip),%rsi
call   1060 <t_set_msg@plt>
lea    -0x60(%rbp),%rdi
lea    0xed6(%rip),%rsi
mov    $0x58,%edx
call   1050 <memcpy@plt>
lea    -0x60(%rbp),%rdi
mov    $0xb,%esi
call   1080 <mean@plt>
movsd  %xmm0,-0x68(%rbp)
lea    -0x60(%rbp),%rdi
movsd  -0x68(%rbp),%xmm0
mov    $0xb,%esi
call   1030 <sd@plt>
movsd  %xmm0,-0x70(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x78(%rbp)
movsd  -0x70(%rbp),%xmm0
movsd  0xe34(%rip),%xmm1
subsd  %xmm1,%xmm0
call   1040 <fabs@plt>
mov    -0x78(%rbp),%rdi
cvtsi2sd %eax,%xmm1
movsd  0xe13(%rip),%xmm0
ucomisd %xmm1,%xmm0
seta   %al
and    $0x1,%al
movzbl %al,%esi
lea    0xe3b(%rip),%rdx
call   1070 <t_assert_msg@plt>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_sd>:
push   %r14
push   %rbx
sub    $0x58,%rsp
mov    %rdi,%r14
lea    0xea7(%rip),%rsi
call   1050 <t_set_msg@plt>
mov    0xf33(%rip),%rax
mov    %rax,0x50(%rsp)
movaps 0xf17(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xefb(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xedf(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xec3(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movapd 0xea6(%rip),%xmm0
movapd %xmm0,(%rsp)
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0xb,%esi
call   1070 <mean@plt>
mov    %rbx,%rdi
mov    $0xb,%esi
call   1030 <sd@plt>
addsd  0xe2c(%rip),%xmm0
call   1040 <fabs@plt>
xor    %esi,%esi
test   %eax,%eax
setle  %sil
lea    0xe4b(%rip),%rdx
mov    %r14,%rdi
call   1060 <t_assert_msg@plt>
add    $0x58,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.test = type { i32 }
@.str = [43 x i8] c"Testing the standard deviation function...\00"
@__const.test_sd.test_list = [11 x double] [double 3.000000e+00, double 5.000000e+00, double 3.000000e+00, double 6.000000e+00, double 3.000000e+00, double 2.000000e+00, double 4.000000e+00, double 6.000000e+00, double 7.000000e+00, double 4.000000e+00, double 3.000000e+00]
@.str.1 = [22 x i8] c"sd function incorrect\00"
define void @test_sd(%struct.test* %0) {
%2 = alloca %struct.test*
%3 = alloca [11 x double]
%4 = alloca double
%5 = alloca double
store %struct.test* %0, %struct.test** %2
%6 = load %struct.test*, %struct.test** %2
%7 = call i32 @t_set_msg(%struct.test* %6, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0))
%8 = bitcast [11 x double]* %3 to i8*
%9 = getelementptr inbounds [11 x double], [11 x double]* %3, i64 0, i64 0
%10 = call double @mean(double* %9, i32 11)
store double %10, double* %4
%11 = getelementptr inbounds [11 x double], [11 x double]* %3, i64 0, i64 0
%12 = load double, double* %4
%13 = call double @sd(double* %11, i32 11, double %12)
store double %13, double* %5
%14 = load %struct.test*, %struct.test** %2
%15 = load double, double* %5
%16 = fsub double %15, 0x3FF99E40C8472C0E
%17 = call i32 @fabs(double %16)
%18 = sitofp i32 %17 to double
%19 = fcmp olt double %18, 1.000000e-03
%20 = zext i1 %19 to i32
%21 = call i32 @t_assert_msg(%struct.test* %14, i32 %20, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
%struct.test = type { i32 }
@.str = [43 x i8] c"Testing the standard deviation function...\00"
@__const.test_sd.test_list = [11 x double] [double 3.000000e+00, double 5.000000e+00, double 3.000000e+00, double 6.000000e+00, double 3.000000e+00, double 2.000000e+00, double 4.000000e+00, double 6.000000e+00, double 7.000000e+00, double 4.000000e+00, double 3.000000e+00]
@.str.1 = [22 x i8] c"sd function incorrect\00"
define void @test_sd(%struct.test* %0) {
%2 = alloca [11 x double]
%3 = tail call i32 @t_set_msg(%struct.test* %0, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0))
%4 = bitcast [11 x double]* %2 to i8*
%5 = getelementptr inbounds [11 x double], [11 x double]* %2, i64 0, i64 0
%6 = call double @mean(double* %5, i32 11)
%7 = call double @sd(double* %5, i32 11, double %6)
%8 = fadd double %7, 0xBFF99E40C8472C0E
%9 = call i32 @fabs(double %8)
%10 = icmp slt i32 %9, 1
%11 = zext i1 %10 to i32
%12 = call i32 @t_assert_msg(%struct.test* %0, i32 %11, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
ret void
}