; 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"

@s0 = external dso_local global double, align 8
@r0 = external dso_local global double, align 8
@b0 = external dso_local global double, align 8
@sigma = external dso_local global double, align 8
@r = external dso_local global double, align 8
@b = 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
@.str = external hidden unnamed_addr constant [64 x i8], align 1
@stdin = external global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [60 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [60 x i8], align 1

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

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

; Function Attrs: nounwind uwtable
define dso_local void @key_cb(i8 noundef zeroext %0, i32 noundef %1, i32 noundef %2) #2 {
  %4 = alloca i8, align 1
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca [80 x i8], align 16
  store i8 %0, ptr %4, align 1, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !8
  store i32 %2, ptr %6, align 4, !tbaa !8
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  call void @llvm.lifetime.start.p0(i64 80, ptr %8) #5
  %9 = load i8, ptr %4, align 1, !tbaa !5
  %10 = zext i8 %9 to i32
  switch i32 %10, label %75 [
    i32 114, label %11
    i32 82, label %11
    i32 109, label %49
    i32 77, label %49
    i32 115, label %71
    i32 83, label %71
    i32 103, label %72
    i32 71, label %72
    i32 32, label %73
    i32 27, label %74
  ]

11:                                               ; preds = %3, %3
  %12 = load double, ptr @s0, align 8, !tbaa !10
  store double %12, ptr @sigma, align 8, !tbaa !10
  %13 = load double, ptr @b0, align 8, !tbaa !10
  store double %13, ptr @b, align 8, !tbaa !10
  %14 = load double, ptr @r0, align 8, !tbaa !10
  store double %14, ptr @r, align 8, !tbaa !10
  %15 = call i32 @rand() #5
  %16 = sitofp i32 %15 to double
  %17 = fdiv double %16, 0x41DFFFFFFFC00000
  store double %17, ptr @red_position, align 16, !tbaa !10
  %18 = call i32 @rand() #5
  %19 = sitofp i32 %18 to double
  %20 = fdiv double %19, 0x41DFFFFFFFC00000
  store double %20, ptr getelementptr inbounds ([3 x double], ptr @red_position, i64 0, i64 1), align 8, !tbaa !10
  %21 = call i32 @rand() #5
  %22 = sitofp i32 %21 to double
  %23 = fdiv double %22, 0x41DFFFFFFFC00000
  store double %23, ptr getelementptr inbounds ([3 x double], ptr @red_position, i64 0, i64 2), align 16, !tbaa !10
  %24 = call i32 @rand() #5
  %25 = sitofp i32 %24 to double
  %26 = fdiv double %25, 0x41DFFFFFFFC00000
  store double %26, ptr @grn_position, align 16, !tbaa !10
  %27 = call i32 @rand() #5
  %28 = sitofp i32 %27 to double
  %29 = fdiv double %28, 0x41DFFFFFFFC00000
  store double %29, ptr getelementptr inbounds ([3 x double], ptr @grn_position, i64 0, i64 1), align 8, !tbaa !10
  %30 = call i32 @rand() #5
  %31 = sitofp i32 %30 to double
  %32 = fdiv double %31, 0x41DFFFFFFFC00000
  store double %32, ptr getelementptr inbounds ([3 x double], ptr @grn_position, i64 0, i64 2), align 16, !tbaa !10
  store i32 0, ptr @array_index, align 4, !tbaa !8
  store i32 1, ptr %7, align 4, !tbaa !8
  br label %33

33:                                               ; preds = %45, %11
  %34 = load i32, ptr %7, align 4, !tbaa !8
  %35 = icmp slt i32 %34, 512
  br i1 %35, label %36, label %48

36:                                               ; preds = %33
  %37 = load i32, ptr %7, align 4, !tbaa !8
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [512 x [3 x double]], ptr @red_position, i64 0, i64 %38
  %40 = getelementptr inbounds [3 x double], ptr %39, i64 0, i64 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %40, ptr align 16 @red_position, i64 24, i1 false)
  %41 = load i32, ptr %7, align 4, !tbaa !8
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [512 x [3 x double]], ptr @grn_position, i64 0, i64 %42
  %44 = getelementptr inbounds [3 x double], ptr %43, i64 0, i64 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %44, ptr align 16 @grn_position, i64 24, i1 false)
  br label %45

45:                                               ; preds = %36
  %46 = load i32, ptr %7, align 4, !tbaa !8
  %47 = add nsw i32 %46, 1
  store i32 %47, ptr %7, align 4, !tbaa !8
  br label %33, !llvm.loop !12

48:                                               ; preds = %33
  br label %75

49:                                               ; preds = %3, %3
  %50 = load double, ptr @s0, align 8, !tbaa !10
  %51 = load double, ptr @sigma, align 8, !tbaa !10
  %52 = call i32 (ptr, ...) @printf(ptr noundef @.str, double noundef %50, double noundef %51)
  %53 = getelementptr inbounds [80 x i8], ptr %8, i64 0, i64 0
  %54 = load ptr, ptr @stdin, align 8, !tbaa !14
  call void @checkedFGets(ptr noundef %53, i32 noundef 80, ptr noundef %54)
  %55 = getelementptr inbounds [80 x i8], ptr %8, i64 0, i64 0
  %56 = call i32 (ptr, ptr, ...) @__isoc99_sscanf(ptr noundef %55, ptr noundef @.str.1, ptr noundef @sigma) #5
  %57 = load double, ptr @b0, align 8, !tbaa !10
  %58 = load double, ptr @b, align 8, !tbaa !10
  %59 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, double noundef %57, double noundef %58)
  %60 = getelementptr inbounds [80 x i8], ptr %8, i64 0, i64 0
  %61 = load ptr, ptr @stdin, align 8, !tbaa !14
  call void @checkedFGets(ptr noundef %60, i32 noundef 80, ptr noundef %61)
  %62 = getelementptr inbounds [80 x i8], ptr %8, i64 0, i64 0
  %63 = call i32 (ptr, ptr, ...) @__isoc99_sscanf(ptr noundef %62, ptr noundef @.str.1, ptr noundef @b) #5
  %64 = load double, ptr @r0, align 8, !tbaa !10
  %65 = load double, ptr @r, align 8, !tbaa !10
  %66 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, double noundef %64, double noundef %65)
  %67 = getelementptr inbounds [80 x i8], ptr %8, i64 0, i64 0
  %68 = load ptr, ptr @stdin, align 8, !tbaa !14
  call void @checkedFGets(ptr noundef %67, i32 noundef 80, ptr noundef %68)
  %69 = getelementptr inbounds [80 x i8], ptr %8, i64 0, i64 0
  %70 = call i32 (ptr, ptr, ...) @__isoc99_sscanf(ptr noundef %69, ptr noundef @.str.1, ptr noundef @r) #5
  br label %75

71:                                               ; preds = %3, %3
  store i32 0, ptr @animate, align 4, !tbaa !8
  br label %75

72:                                               ; preds = %3, %3
  store i32 1, ptr @animate, align 4, !tbaa !8
  br label %75

73:                                               ; preds = %3
  store i32 2, ptr @animate, align 4, !tbaa !8
  br label %75

74:                                               ; preds = %3
  call void @glutLeaveMainLoop()
  br label %75

75:                                               ; preds = %74, %73, %72, %71, %49, %48, %3
  call void @llvm.lifetime.end.p0(i64 80, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  ret void
}

; Function Attrs: nounwind
declare i32 @rand() #3

declare i32 @printf(ptr noundef, ...) #4

; Function Attrs: nounwind uwtable
declare hidden void @checkedFGets(ptr noundef, i32 noundef, ptr noundef) #2

; Function Attrs: nounwind
declare i32 @__isoc99_sscanf(ptr noundef, ptr noundef, ...) #3

declare void @glutLeaveMainLoop() #4

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { 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 #4 = { "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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"int", !6, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"double", !6, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!15, !15, i64 0}
!15 = !{!"any pointer", !6, 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"

@s0 = external dso_local local_unnamed_addr global double, align 8
@r0 = external dso_local local_unnamed_addr global double, align 8
@b0 = external dso_local local_unnamed_addr global double, align 8
@sigma = external dso_local global double, align 8
@r = external dso_local global double, align 8
@b = external dso_local global double, align 8
@animate = external dso_local local_unnamed_addr global i32, align 4
@red_position = external dso_local local_unnamed_addr global [512 x [3 x double]], align 16
@grn_position = external dso_local local_unnamed_addr global [512 x [3 x double]], align 16
@array_index = external dso_local local_unnamed_addr global i32, align 4
@.str = external hidden unnamed_addr constant [64 x i8], align 1
@stdin = external local_unnamed_addr global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [60 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [60 x i8], align 1

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

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

; Function Attrs: nounwind uwtable
define dso_local void @key_cb(i8 noundef zeroext %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #2 {
  %4 = alloca [80 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 80, ptr nonnull %4) #6
  switch i8 %0, label %.loopexit [
    i8 114, label %5
    i8 82, label %5
    i8 109, label %33
    i8 77, label %33
    i8 115, label %49
    i8 83, label %49
    i8 103, label %50
    i8 71, label %50
    i8 32, label %51
    i8 27, label %52
  ]

5:                                                ; preds = %3, %3
  %6 = load double, ptr @s0, align 8, !tbaa !5
  store double %6, ptr @sigma, align 8, !tbaa !5
  %7 = load double, ptr @b0, align 8, !tbaa !5
  store double %7, ptr @b, align 8, !tbaa !5
  %8 = load double, ptr @r0, align 8, !tbaa !5
  store double %8, ptr @r, align 8, !tbaa !5
  %9 = tail call i32 @rand() #6
  %10 = sitofp i32 %9 to double
  %11 = fdiv double %10, 0x41DFFFFFFFC00000
  store double %11, ptr @red_position, align 16, !tbaa !5
  %12 = tail call i32 @rand() #6
  %13 = sitofp i32 %12 to double
  %14 = fdiv double %13, 0x41DFFFFFFFC00000
  store double %14, ptr getelementptr inbounds (i8, ptr @red_position, i64 8), align 8, !tbaa !5
  %15 = tail call i32 @rand() #6
  %16 = sitofp i32 %15 to double
  %17 = fdiv double %16, 0x41DFFFFFFFC00000
  store double %17, ptr getelementptr inbounds (i8, ptr @red_position, i64 16), align 16, !tbaa !5
  %18 = tail call i32 @rand() #6
  %19 = sitofp i32 %18 to double
  %20 = fdiv double %19, 0x41DFFFFFFFC00000
  store double %20, ptr @grn_position, align 16, !tbaa !5
  %21 = tail call i32 @rand() #6
  %22 = sitofp i32 %21 to double
  %23 = fdiv double %22, 0x41DFFFFFFFC00000
  store double %23, ptr getelementptr inbounds (i8, ptr @grn_position, i64 8), align 8, !tbaa !5
  %24 = tail call i32 @rand() #6
  %25 = sitofp i32 %24 to double
  %26 = fdiv double %25, 0x41DFFFFFFFC00000
  store double %26, ptr getelementptr inbounds (i8, ptr @grn_position, i64 16), align 16, !tbaa !5
  store i32 0, ptr @array_index, align 4, !tbaa !9
  br label %27

27:                                               ; preds = %30, %5
  %indvars.iv = phi i64 [ 1, %5 ], [ %indvars.iv.next.1, %30 ]
  %28 = getelementptr inbounds [512 x [3 x double]], ptr @red_position, i64 0, i64 %indvars.iv
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %28, ptr noundef nonnull align 16 dereferenceable(24) @red_position, i64 24, i1 false)
  %29 = getelementptr inbounds [512 x [3 x double]], ptr @grn_position, i64 0, i64 %indvars.iv
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %29, ptr noundef nonnull align 16 dereferenceable(24) @grn_position, i64 24, i1 false)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 512
  br i1 %exitcond.not, label %.loopexit, label %30, !llvm.loop !11

30:                                               ; preds = %27
  %31 = getelementptr inbounds [512 x [3 x double]], ptr @red_position, i64 0, i64 %indvars.iv.next
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %31, ptr noundef nonnull align 16 dereferenceable(24) @red_position, i64 24, i1 false)
  %32 = getelementptr inbounds [512 x [3 x double]], ptr @grn_position, i64 0, i64 %indvars.iv.next
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %32, ptr noundef nonnull align 16 dereferenceable(24) @grn_position, i64 24, i1 false)
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  br label %27

33:                                               ; preds = %3, %3
  %34 = load double, ptr @s0, align 8, !tbaa !5
  %35 = load double, ptr @sigma, align 8, !tbaa !5
  %36 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, double noundef %34, double noundef %35)
  %37 = load ptr, ptr @stdin, align 8, !tbaa !13
  call void @checkedFGets(ptr noundef nonnull %4, i32 noundef 80, ptr noundef %37)
  %38 = call i32 (ptr, ptr, ...) @__isoc99_sscanf(ptr noundef nonnull %4, ptr noundef nonnull @.str.1, ptr noundef nonnull @sigma) #6
  %39 = load double, ptr @b0, align 8, !tbaa !5
  %40 = load double, ptr @b, align 8, !tbaa !5
  %41 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, double noundef %39, double noundef %40)
  %42 = load ptr, ptr @stdin, align 8, !tbaa !13
  call void @checkedFGets(ptr noundef nonnull %4, i32 noundef 80, ptr noundef %42)
  %43 = call i32 (ptr, ptr, ...) @__isoc99_sscanf(ptr noundef nonnull %4, ptr noundef nonnull @.str.1, ptr noundef nonnull @b) #6
  %44 = load double, ptr @r0, align 8, !tbaa !5
  %45 = load double, ptr @r, align 8, !tbaa !5
  %46 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, double noundef %44, double noundef %45)
  %47 = load ptr, ptr @stdin, align 8, !tbaa !13
  call void @checkedFGets(ptr noundef nonnull %4, i32 noundef 80, ptr noundef %47)
  %48 = call i32 (ptr, ptr, ...) @__isoc99_sscanf(ptr noundef nonnull %4, ptr noundef nonnull @.str.1, ptr noundef nonnull @r) #6
  br label %.loopexit

49:                                               ; preds = %3, %3
  store i32 0, ptr @animate, align 4, !tbaa !9
  br label %.loopexit

50:                                               ; preds = %3, %3
  store i32 1, ptr @animate, align 4, !tbaa !9
  br label %.loopexit

51:                                               ; preds = %3
  store i32 2, ptr @animate, align 4, !tbaa !9
  br label %.loopexit

52:                                               ; preds = %3
  tail call void @glutLeaveMainLoop() #6
  br label %.loopexit

.loopexit:                                        ; preds = %27, %52, %51, %50, %49, %33, %3
  call void @llvm.lifetime.end.p0(i64 80, ptr nonnull %4) #6
  ret void
}

; Function Attrs: nounwind
declare i32 @rand() local_unnamed_addr #3

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #4

; Function Attrs: nounwind uwtable
declare hidden void @checkedFGets(ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef i32 @__isoc99_sscanf(ptr nocapture noundef readonly, ptr nocapture noundef readonly, ...) local_unnamed_addr #4

declare void @glutLeaveMainLoop() local_unnamed_addr #5

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { 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 #4 = { nofree 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 = { "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 #6 = { 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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!14, !14, i64 0}
!14 = !{!"any pointer", !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass