; LLVM IR from MostafaTwfiq/C-DataStructures-And-Algorithms :: Algorithms/ArraysAlg/Sources (ArraysAlg)

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

@stderr = external global ptr, align 8
@.str = external hidden unnamed_addr constant [31 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [42 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [28 x i8], align 1
@.str.33 = external hidden unnamed_addr constant [19 x i8], align 1
@.str.35 = external hidden unnamed_addr constant [20 x i8], align 1
@.str.36 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.38 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.40 = external hidden unnamed_addr constant [33 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 nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #1

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @arrMismatchOfRange(ptr noundef %0, i32 noundef %1, ptr noundef %2, i32 noundef %3, i32 noundef %4, i32 noundef %5, i32 noundef %6, ptr noundef %7) #3 {
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  %17 = alloca ptr, align 8
  %18 = alloca ptr, align 8
  %19 = alloca ptr, align 8
  %20 = alloca i32, align 4
  %21 = alloca i32, align 4
  store ptr %0, ptr %10, align 8, !tbaa !5
  store i32 %1, ptr %11, align 4, !tbaa !9
  store ptr %2, ptr %12, align 8, !tbaa !5
  store i32 %3, ptr %13, align 4, !tbaa !9
  store i32 %4, ptr %14, align 4, !tbaa !9
  store i32 %5, ptr %15, align 4, !tbaa !9
  store i32 %6, ptr %16, align 4, !tbaa !9
  store ptr %7, ptr %17, align 8, !tbaa !5
  %22 = load ptr, ptr %10, align 8, !tbaa !5
  %23 = icmp eq ptr %22, null
  br i1 %23, label %24, label %27

24:                                               ; preds = %8
  %25 = load ptr, ptr @stderr, align 8, !tbaa !5
  %26 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %25, ptr noundef @.str, ptr noundef @.str.33, ptr noundef @.str.40) #4
  call void @exit(i32 noundef -83386157) #5
  unreachable

27:                                               ; preds = %8
  %28 = load ptr, ptr %12, align 8, !tbaa !5
  %29 = icmp eq ptr %28, null
  br i1 %29, label %30, label %33

30:                                               ; preds = %27
  %31 = load ptr, ptr @stderr, align 8, !tbaa !5
  %32 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %31, ptr noundef @.str, ptr noundef @.str.35, ptr noundef @.str.40) #4
  call void @exit(i32 noundef -83386157) #5
  unreachable

33:                                               ; preds = %27
  %34 = load ptr, ptr %17, align 8, !tbaa !5
  %35 = icmp eq ptr %34, null
  br i1 %35, label %36, label %39

36:                                               ; preds = %33
  %37 = load ptr, ptr @stderr, align 8, !tbaa !5
  %38 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %37, ptr noundef @.str.3, ptr noundef @.str.7, ptr noundef @.str.40) #4
  call void @exit(i32 noundef -83384987) #5
  unreachable

39:                                               ; preds = %33
  %40 = load i32, ptr %11, align 4, !tbaa !9
  %41 = icmp slt i32 %40, 0
  br i1 %41, label %45, label %42

42:                                               ; preds = %39
  %43 = load i32, ptr %13, align 4, !tbaa !9
  %44 = icmp slt i32 %43, 0
  br i1 %44, label %45, label %48

45:                                               ; preds = %42, %39
  %46 = load ptr, ptr @stderr, align 8, !tbaa !5
  %47 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %46, ptr noundef @.str.3, ptr noundef @.str.36, ptr noundef @.str.40) #4
  call void @exit(i32 noundef -83384987) #5
  unreachable

48:                                               ; preds = %42
  %49 = load i32, ptr %14, align 4, !tbaa !9
  %50 = icmp sle i32 %49, 0
  br i1 %50, label %51, label %54

51:                                               ; preds = %48
  %52 = load ptr, ptr @stderr, align 8, !tbaa !5
  %53 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %52, ptr noundef @.str.3, ptr noundef @.str.5, ptr noundef @.str.40) #4
  call void @exit(i32 noundef -83384987) #5
  unreachable

54:                                               ; preds = %48
  %55 = load i32, ptr %15, align 4, !tbaa !9
  %56 = icmp slt i32 %55, 0
  br i1 %56, label %69, label %57

57:                                               ; preds = %54
  %58 = load i32, ptr %15, align 4, !tbaa !9
  %59 = load i32, ptr %16, align 4, !tbaa !9
  %60 = icmp sgt i32 %58, %59
  br i1 %60, label %69, label %61

61:                                               ; preds = %57
  %62 = load i32, ptr %16, align 4, !tbaa !9
  %63 = load i32, ptr %11, align 4, !tbaa !9
  %64 = icmp sge i32 %62, %63
  br i1 %64, label %69, label %65

65:                                               ; preds = %61
  %66 = load i32, ptr %16, align 4, !tbaa !9
  %67 = load i32, ptr %13, align 4, !tbaa !9
  %68 = icmp sge i32 %66, %67
  br i1 %68, label %69, label %72

69:                                               ; preds = %65, %61, %57, %54
  %70 = load ptr, ptr @stderr, align 8, !tbaa !5
  %71 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %70, ptr noundef @.str.3, ptr noundef @.str.38, ptr noundef @.str.40) #4
  call void @exit(i32 noundef -83384987) #5
  unreachable

72:                                               ; preds = %65
  br label %73

73:                                               ; preds = %72
  br label %74

74:                                               ; preds = %73
  br label %75

75:                                               ; preds = %74
  br label %76

76:                                               ; preds = %75
  br label %77

77:                                               ; preds = %76
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #4
  %78 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %78, ptr %18, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #4
  %79 = load ptr, ptr %12, align 8, !tbaa !5
  store ptr %79, ptr %19, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %20) #4
  %80 = load i32, ptr %15, align 4, !tbaa !9
  store i32 %80, ptr %20, align 4, !tbaa !9
  br label %81

81:                                               ; preds = %105, %77
  %82 = load i32, ptr %20, align 4, !tbaa !9
  %83 = load i32, ptr %16, align 4, !tbaa !9
  %84 = icmp sle i32 %82, %83
  br i1 %84, label %86, label %85

85:                                               ; preds = %81
  store i32 2, ptr %21, align 4
  br label %108

86:                                               ; preds = %81
  %87 = load ptr, ptr %17, align 8, !tbaa !5
  %88 = load ptr, ptr %18, align 8, !tbaa !5
  %89 = load i32, ptr %20, align 4, !tbaa !9
  %90 = load i32, ptr %14, align 4, !tbaa !9
  %91 = mul nsw i32 %89, %90
  %92 = sext i32 %91 to i64
  %93 = getelementptr inbounds i8, ptr %88, i64 %92
  %94 = load ptr, ptr %19, align 8, !tbaa !5
  %95 = load i32, ptr %20, align 4, !tbaa !9
  %96 = load i32, ptr %14, align 4, !tbaa !9
  %97 = mul nsw i32 %95, %96
  %98 = sext i32 %97 to i64
  %99 = getelementptr inbounds i8, ptr %94, i64 %98
  %100 = call i32 %87(ptr noundef %93, ptr noundef %99)
  %101 = icmp ne i32 %100, 0
  br i1 %101, label %102, label %104

102:                                              ; preds = %86
  %103 = load i32, ptr %20, align 4, !tbaa !9
  store i32 %103, ptr %9, align 4
  store i32 1, ptr %21, align 4
  br label %108

104:                                              ; preds = %86
  br label %105

105:                                              ; preds = %104
  %106 = load i32, ptr %20, align 4, !tbaa !9
  %107 = add nsw i32 %106, 1
  store i32 %107, ptr %20, align 4, !tbaa !9
  br label %81, !llvm.loop !11

108:                                              ; preds = %102, %85
  call void @llvm.lifetime.end.p0(i64 4, ptr %20) #4
  %109 = load i32, ptr %21, align 4
  switch i32 %109, label %111 [
    i32 2, label %110
  ]

110:                                              ; preds = %108
  store i32 -1, ptr %9, align 4
  store i32 1, ptr %21, align 4
  br label %111

111:                                              ; preds = %110, %108
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #4
  %112 = load i32, ptr %9, align 4
  ret i32 %112
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { noreturn 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 #3 = { 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 #4 = { nounwind }
attributes #5 = { noreturn 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 = !{!"any pointer", !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"}


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

@stderr = external local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [31 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [42 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [28 x i8], align 1
@.str.33 = external hidden unnamed_addr constant [19 x i8], align 1
@.str.35 = external hidden unnamed_addr constant [20 x i8], align 1
@.str.36 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.38 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.40 = external hidden unnamed_addr constant [33 x i8], align 1

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

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, -2147483648) i32 @arrMismatchOfRange(ptr noundef %0, i32 noundef %1, ptr noundef %2, i32 noundef %3, i32 noundef %4, i32 noundef %5, i32 noundef %6, ptr noundef readonly %7) local_unnamed_addr #2 {
  %9 = icmp eq ptr %0, null
  br i1 %9, label %10, label %13

10:                                               ; preds = %8
  %11 = load ptr, ptr @stderr, align 8, !tbaa !5
  %12 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %11, ptr noundef nonnull @.str, ptr noundef nonnull @.str.33, ptr noundef nonnull @.str.40) #3
  tail call void @exit(i32 noundef -83386157) #4
  unreachable

13:                                               ; preds = %8
  %14 = icmp eq ptr %2, null
  br i1 %14, label %15, label %18

15:                                               ; preds = %13
  %16 = load ptr, ptr @stderr, align 8, !tbaa !5
  %17 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %16, ptr noundef nonnull @.str, ptr noundef nonnull @.str.35, ptr noundef nonnull @.str.40) #3
  tail call void @exit(i32 noundef -83386157) #4
  unreachable

18:                                               ; preds = %13
  %19 = icmp eq ptr %7, null
  br i1 %19, label %20, label %23

20:                                               ; preds = %18
  %21 = load ptr, ptr @stderr, align 8, !tbaa !5
  %22 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %21, ptr noundef nonnull @.str.3, ptr noundef nonnull @.str.7, ptr noundef nonnull @.str.40) #3
  tail call void @exit(i32 noundef -83384987) #4
  unreachable

23:                                               ; preds = %18
  %24 = or i32 %3, %1
  %or.cond.not = icmp sgt i32 %24, -1
  br i1 %or.cond.not, label %28, label %25

25:                                               ; preds = %23
  %26 = load ptr, ptr @stderr, align 8, !tbaa !5
  %27 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %26, ptr noundef nonnull @.str.3, ptr noundef nonnull @.str.36, ptr noundef nonnull @.str.40) #3
  tail call void @exit(i32 noundef -83384987) #4
  unreachable

28:                                               ; preds = %23
  %29 = icmp slt i32 %4, 1
  br i1 %29, label %30, label %33

30:                                               ; preds = %28
  %31 = load ptr, ptr @stderr, align 8, !tbaa !5
  %32 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %31, ptr noundef nonnull @.str.3, ptr noundef nonnull @.str.5, ptr noundef nonnull @.str.40) #3
  tail call void @exit(i32 noundef -83384987) #4
  unreachable

33:                                               ; preds = %28
  %34 = icmp sgt i32 %5, -1
  %35 = icmp sle i32 %5, %6
  %or.cond.not47 = and i1 %34, %35
  %.not = icmp slt i32 %6, %1
  %or.cond43 = and i1 %.not, %or.cond.not47
  %.not39 = icmp slt i32 %6, %3
  %or.cond44 = and i1 %.not39, %or.cond43
  br i1 %or.cond44, label %.preheader.preheader, label %38

.preheader.preheader:                             ; preds = %33
  %36 = zext nneg i32 %5 to i64
  %37 = zext nneg i32 %4 to i64
  br label %.preheader

38:                                               ; preds = %33
  %39 = load ptr, ptr @stderr, align 8, !tbaa !5
  %40 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %39, ptr noundef nonnull @.str.3, ptr noundef nonnull @.str.38, ptr noundef nonnull @.str.40) #3
  tail call void @exit(i32 noundef -83384987) #4
  unreachable

.preheader:                                       ; preds = %.preheader.preheader, %46
  %indvars.iv = phi i64 [ %36, %.preheader.preheader ], [ %indvars.iv.next, %46 ]
  %41 = mul nuw nsw i64 %indvars.iv, %37
  %42 = getelementptr inbounds i8, ptr %0, i64 %41
  %43 = getelementptr inbounds i8, ptr %2, i64 %41
  %44 = tail call i32 %7(ptr noundef nonnull %42, ptr noundef nonnull %43) #5
  %.not41 = icmp eq i32 %44, 0
  %45 = trunc nuw i64 %indvars.iv to i32
  br i1 %.not41, label %46, label %47

46:                                               ; preds = %.preheader
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %.not40.not = icmp slt i32 %45, %6
  br i1 %.not40.not, label %.preheader, label %47, !llvm.loop !9

47:                                               ; preds = %.preheader, %46
  %spec.select = phi i32 [ %45, %.preheader ], [ -1, %46 ]
  ret i32 %spec.select
}

attributes #0 = { 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 #1 = { noreturn 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 #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 = { cold nounwind }
attributes #4 = { noreturn nounwind }
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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,LoopSimplifyPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass