#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 */
double exp(double);
double fabs(double);
int /*<<< orphan*/ printf(char *, double, double);
int check_result(double *result, size_t n, double threshold, double timestep) {
  int is_approx = 1;
  for (size_t i = 0; i < n; ++i) {
    double solution = exp(-3.0 * i * timestep);
    if (fabs(result[i] - solution) > threshold) {
      printf("%f    %f\n", result[i], solution);
      is_approx = 0;
    }
  }
  return is_approx;
}


x86 assembly (clang, -O0):
<check_result>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
movsd  %xmm1,-0x20(%rbp)
movl   $0x1,-0x24(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    11fc <check_result+0xdc>
movaps 0xeb2(%rip),%xmm0
movq   -0x30(%rbp),%xmm1
punpckldq %xmm0,%xmm1
movapd 0xeb1(%rip),%xmm0
subpd  %xmm0,%xmm1
movaps %xmm1,%xmm0
unpckhpd %xmm1,%xmm1
addsd  %xmm0,%xmm1
movsd  0xeaa(%rip),%xmm0
mulsd  %xmm1,%xmm0
mulsd  -0x20(%rbp),%xmm0
call   1040 <exp@plt>
movsd  %xmm0,-0x38(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x30(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
subsd  -0x38(%rbp),%xmm0
movaps 0xe4e(%rip),%xmm1
pand   %xmm1,%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    11e6 <check_result+0xc6>
mov    -0x8(%rbp),%rax
mov    -0x30(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  -0x38(%rbp),%xmm1
lea    0xe5e(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x24(%rbp)
jmp    11eb <check_result+0xcb>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    1149 <check_result+0x29>
mov    -0x24(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_result>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
movsd  %xmm1,0x8(%rsp)
movsd  %xmm0,(%rsp)
test   %rsi,%rsi
je     11cb <check_result+0xab>
mov    %rsi,%rbx
mov    %rdi,%r14
mov    $0x1,%r12d
xor    %ebp,%ebp
lea    0xee3(%rip),%r15
jmp    1169 <check_result+0x49>
nopw   0x0(%rax,%rax,1)
add    $0x1,%rbp
cmp    %rbp,%rbx
je     11d1 <check_result+0xb1>
movq   %rbp,%xmm1
punpckldq 0xe8a(%rip),%xmm1
subpd  0xe92(%rip),%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
addsd  %xmm1,%xmm0
mulsd  0xe9e(%rip),%xmm0
mulsd  0x8(%rsp),%xmm0
call   1040 <exp@plt>
movapd %xmm0,%xmm1
movsd  (%r14,%rbp,8),%xmm0
movapd %xmm0,%xmm2
subsd  %xmm1,%xmm2
andpd  0xe69(%rip),%xmm2
ucomisd (%rsp),%xmm2
jbe    1160 <check_result+0x40>
mov    %r15,%rdi
call   1030 <printf@plt>
xor    %r12d,%r12d
jmp    1160 <check_result+0x40>
mov    $0x1,%r12d
mov    %r12d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"%f %f\0A\00"
define i32 @check_result(double* %0, i64 %1, double %2, double %3) {
%5 = alloca double*
%6 = alloca i64
%7 = alloca double
%8 = alloca double
%9 = alloca i32
%10 = alloca i64
%11 = alloca double
store double* %0, double** %5
store i64 %1, i64* %6
store double %2, double* %7
store double %3, double* %8
store i32 1, i32* %9
store i64 0, i64* %10
br label %12
12: ; preds = %40, %4
%13 = load i64, i64* %10
%14 = load i64, i64* %6
%15 = icmp ult i64 %13, %14
br i1 %15, label %16, label %43
16: ; preds = %12
%17 = load i64, i64* %10
%18 = uitofp i64 %17 to double
%19 = fmul double -3.000000e+00, %18
%20 = load double, double* %8
%21 = fmul double %19, %20
%22 = call double @exp(double %21)
store double %22, double* %11
%23 = load double*, double** %5
%24 = load i64, i64* %10
%25 = getelementptr inbounds double, double* %23, i64 %24
%26 = load double, double* %25
%27 = load double, double* %11
%28 = fsub double %26, %27
%29 = call double @llvm.fabs.f64(double %28)
%30 = load double, double* %7
%31 = fcmp ogt double %29, %30
br i1 %31, label %32, label %39
32: ; preds = %16
%33 = load double*, double** %5
%34 = load i64, i64* %10
%35 = getelementptr inbounds double, double* %33, i64 %34
%36 = load double, double* %35
%37 = load double, double* %11
%38 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), double %36, double %37)
store i32 0, i32* %9
br label %39
39: ; preds = %32, %16
br label %40
40: ; preds = %39
%41 = load i64, i64* %10
%42 = add i64 %41, 1
store i64 %42, i64* %10
br label %12
43: ; preds = %12
%44 = load i32, i32* %9
ret i32 %44
}

LLVM IR (-O2):
@.str = [10 x i8] c"%f %f\0A\00"
define i32 @check_result(double* nocapture %0, i64 %1, double %2, double %3) {
%5 = icmp eq i64 %1, 0
br i1 %5, label %6, label %8
6: ; preds = %22, %4
%7 = phi i32 [ 1, %4 ], [ %23, %22 ]
ret i32 %7
8: ; preds = %4, %22
%9 = phi i32 [ %23, %22 ], [ 1, %4 ]
%10 = phi i64 [ %24, %22 ], [ 0, %4 ]
%11 = uitofp i64 %10 to double
%12 = fmul double %11, -3.000000e+00
%13 = fmul double %12, %3
%14 = tail call double @exp(double %13)
%15 = getelementptr inbounds double, double* %0, i64 %10
%16 = load double, double* %15
%17 = fsub double %16, %14
%18 = tail call double @llvm.fabs.f64(double %17)
%19 = fcmp ogt double %18, %2
br i1 %19, label %20, label %22
20: ; preds = %8
%21 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), double %16, double %14)
br label %22
22: ; preds = %20, %8
%23 = phi i32 [ 0, %20 ], [ %9, %8 ]
%24 = add nuw i64 %10, 1
%25 = icmp eq i64 %24, %1
br i1 %25, label %6, label %8
}