; LLVM IR from paroj/gltut :: glsdk/freeglut/progs/demos/Lorenz (lorenz)

; Unoptimized IR (clang -disable-llvm-passes):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

@time_step = external dso_local global double, align 8
@distance = external dso_local global double, align 8
@animate = external dso_local global i32, align 4
@red_position = external dso_local global [512 x [3 x double]], align 16
@grn_position = external dso_local global [512 x [3 x double]], align 16
@array_index = external dso_local global i32, align 4

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #0

; Function Attrs: nounwind uwtable
declare dso_local void @advance_in_time(double noundef, ptr noundef, ptr noundef) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #2

declare void @glutPostRedisplay() #3

; Function Attrs: nounwind uwtable
define dso_local void @timer_cb(i32 noundef %0) #1 {
  %2 = alloca i32, align 4
  %3 = alloca double, align 8
  %4 = alloca double, align 8
  %5 = alloca double, align 8
  %6 = alloca i32, align 4
  store i32 %0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  %7 = load i32, ptr @array_index, align 4, !tbaa !5
  %8 = add nsw i32 %7, 1
  store i32 %8, ptr %6, align 4, !tbaa !5
  call void @glutTimerFunc(i32 noundef 30, ptr noundef @timer_cb, i32 noundef 0)
  %9 = load i32, ptr @animate, align 4, !tbaa !5
  %10 = icmp sgt i32 %9, 0
  br i1 %10, label %11, label %82

11:                                               ; preds = %1
  %12 = load i32, ptr %6, align 4, !tbaa !5
  %13 = icmp eq i32 %12, 512
  br i1 %13, label %14, label %15

14:                                               ; preds = %11
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %15

15:                                               ; preds = %14, %11
  %16 = load double, ptr @time_step, align 8, !tbaa !9
  %17 = load i32, ptr @array_index, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [512 x [3 x double]], ptr @red_position, i64 0, i64 %18
  %20 = getelementptr inbounds [3 x double], ptr %19, i64 0, i64 0
  %21 = load i32, ptr %6, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [512 x [3 x double]], ptr @red_position, i64 0, i64 %22
  %24 = getelementptr inbounds [3 x double], ptr %23, i64 0, i64 0
  call void @advance_in_time(double noundef %16, ptr noundef %20, ptr noundef %24)
  %25 = load double, ptr @time_step, align 8, !tbaa !9
  %26 = load i32, ptr @array_index, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [512 x [3 x double]], ptr @grn_position, i64 0, i64 %27
  %29 = getelementptr inbounds [3 x double], ptr %28, i64 0, i64 0
  %30 = load i32, ptr %6, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [512 x [3 x double]], ptr @grn_position, i64 0, i64 %31
  %33 = getelementptr inbounds [3 x double], ptr %32, i64 0, i64 0
  call void @advance_in_time(double noundef %25, ptr noundef %29, ptr noundef %33)
  %34 = load i32, ptr %6, align 4, !tbaa !5
  store i32 %34, ptr @array_index, align 4, !tbaa !5
  %35 = load i32, ptr @array_index, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [512 x [3 x double]], ptr @red_position, i64 0, i64 %36
  %38 = getelementptr inbounds [3 x double], ptr %37, i64 0, i64 0
  %39 = load double, ptr %38, align 8, !tbaa !9
  %40 = load i32, ptr @array_index, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [512 x [3 x double]], ptr @grn_position, i64 0, i64 %41
  %43 = getelementptr inbounds [3 x double], ptr %42, i64 0, i64 0
  %44 = load double, ptr %43, align 8, !tbaa !9
  %45 = fsub double %39, %44
  store double %45, ptr %3, align 8, !tbaa !9
  %46 = load i32, ptr @array_index, align 4, !tbaa !5
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [512 x [3 x double]], ptr @red_position, i64 0, i64 %47
  %49 = getelementptr inbounds [3 x double], ptr %48, i64 0, i64 1
  %50 = load double, ptr %49, align 8, !tbaa !9
  %51 = load i32, ptr @array_index, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [512 x [3 x double]], ptr @grn_position, i64 0, i64 %52
  %54 = getelementptr inbounds [3 x double], ptr %53, i64 0, i64 1
  %55 = load double, ptr %54, align 8, !tbaa !9
  %56 = fsub double %50, %55
  store double %56, ptr %4, align 8, !tbaa !9
  %57 = load i32, ptr @array_index, align 4, !tbaa !5
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds [512 x [3 x double]], ptr @red_position, i64 0, i64 %58
  %60 = getelementptr inbounds [3 x double], ptr %59, i64 0, i64 2
  %61 = load double, ptr %60, align 8, !tbaa !9
  %62 = load i32, ptr @array_index, align 4, !tbaa !5
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds [512 x [3 x double]], ptr @grn_position, i64 0, i64 %63
  %65 = getelementptr inbounds [3 x double], ptr %64, i64 0, i64 2
  %66 = load double, ptr %65, align 8, !tbaa !9
  %67 = fsub double %61, %66
  store double %67, ptr %5, align 8, !tbaa !9
  %68 = load double, ptr %3, align 8, !tbaa !9
  %69 = load double, ptr %3, align 8, !tbaa !9
  %70 = load double, ptr %4, align 8, !tbaa !9
  %71 = load double, ptr %4, align 8, !tbaa !9
  %72 = fmul double %70, %71
  %73 = call double @llvm.fmuladd.f64(double %68, double %69, double %72)
  %74 = load double, ptr %5, align 8, !tbaa !9
  %75 = load double, ptr %5, align 8, !tbaa !9
  %76 = call double @llvm.fmuladd.f64(double %74, double %75, double %73)
  %77 = call double @sqrt(double noundef %76) #5
  store double %77, ptr @distance, align 8, !tbaa !9
  %78 = load i32, ptr @animate, align 4, !tbaa !5
  %79 = icmp eq i32 %78, 2
  br i1 %79, label %80, label %81

80:                                               ; preds = %15
  store i32 0, ptr @animate, align 4, !tbaa !5
  br label %81

81:                                               ; preds = %80, %15
  br label %82

82:                                               ; preds = %81, %1
  call void @glutPostRedisplay()
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #5
  ret void
}

declare void @glutTimerFunc(i32 noundef, ptr noundef, i32 noundef) #3

; Function Attrs: nounwind
declare double @sqrt(double noundef) #4

attributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #4 = { nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #5 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}


; Optimized IR (opt -passes='default<O3>'):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

@time_step = external dso_local local_unnamed_addr global double, align 8
@distance = external dso_local local_unnamed_addr global double, align 8
@animate = external dso_local local_unnamed_addr global i32, align 4
@red_position = external dso_local global [512 x [3 x double]], align 16
@grn_position = external dso_local global [512 x [3 x double]], align 16
@array_index = external dso_local local_unnamed_addr global i32, align 4

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #0

; Function Attrs: nounwind uwtable
declare dso_local void @advance_in_time(double noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

declare void @glutPostRedisplay() local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local void @timer_cb(i32 %0) #1 {
  %2 = load i32, ptr @array_index, align 4, !tbaa !5
  tail call void @glutTimerFunc(i32 noundef 30, ptr noundef nonnull @timer_cb, i32 noundef 0) #4
  %3 = load i32, ptr @animate, align 4, !tbaa !5
  %4 = icmp sgt i32 %3, 0
  br i1 %4, label %5, label %38

5:                                                ; preds = %1
  %6 = add nsw i32 %2, 1
  %7 = icmp eq i32 %6, 512
  %spec.store.select = select i1 %7, i32 0, i32 %6
  %8 = load double, ptr @time_step, align 8, !tbaa !9
  %9 = load i32, ptr @array_index, align 4, !tbaa !5
  %10 = sext i32 %9 to i64
  %11 = getelementptr inbounds [512 x [3 x double]], ptr @red_position, i64 0, i64 %10
  %12 = sext i32 %spec.store.select to i64
  %13 = getelementptr inbounds [512 x [3 x double]], ptr @red_position, i64 0, i64 %12
  tail call void @advance_in_time(double noundef %8, ptr noundef nonnull %11, ptr noundef nonnull %13)
  %14 = load double, ptr @time_step, align 8, !tbaa !9
  %15 = load i32, ptr @array_index, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [512 x [3 x double]], ptr @grn_position, i64 0, i64 %16
  %18 = getelementptr inbounds [512 x [3 x double]], ptr @grn_position, i64 0, i64 %12
  tail call void @advance_in_time(double noundef %14, ptr noundef nonnull %17, ptr noundef nonnull %18)
  store i32 %spec.store.select, ptr @array_index, align 4, !tbaa !5
  %19 = load double, ptr %13, align 8, !tbaa !9
  %20 = load double, ptr %18, align 8, !tbaa !9
  %21 = fsub double %19, %20
  %22 = getelementptr inbounds i8, ptr %13, i64 8
  %23 = load double, ptr %22, align 8, !tbaa !9
  %24 = getelementptr inbounds i8, ptr %18, i64 8
  %25 = load double, ptr %24, align 8, !tbaa !9
  %26 = fsub double %23, %25
  %27 = getelementptr inbounds i8, ptr %13, i64 16
  %28 = load double, ptr %27, align 8, !tbaa !9
  %29 = getelementptr inbounds i8, ptr %18, i64 16
  %30 = load double, ptr %29, align 8, !tbaa !9
  %31 = fsub double %28, %30
  %32 = fmul double %26, %26
  %33 = tail call double @llvm.fmuladd.f64(double %21, double %21, double %32)
  %34 = tail call double @llvm.fmuladd.f64(double %31, double %31, double %33)
  %sqrt = tail call double @llvm.sqrt.f64(double %34)
  store double %sqrt, ptr @distance, align 8, !tbaa !9
  %35 = load i32, ptr @animate, align 4, !tbaa !5
  %36 = icmp eq i32 %35, 2
  br i1 %36, label %37, label %38

37:                                               ; preds = %5
  store i32 0, ptr @animate, align 4, !tbaa !5
  br label %38

38:                                               ; preds = %5, %37, %1
  tail call void @glutPostRedisplay() #4
  ret void
}

declare void @glutTimerFunc(i32 noundef, ptr noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.sqrt.f64(double) #3

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}


; Effective O3 passes: AggressiveInstCombinePass,DeadArgumentEliminationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass