; 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.62 = external hidden unnamed_addr constant [27 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 @arrIsRotation(ptr noundef %0, i32 noundef %1, ptr noundef %2, i32 noundef %3, i32 noundef %4, ptr noundef %5) #3 {
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca ptr, align 8
  %16 = alloca i32, align 4
  %17 = alloca i32, align 4
  %18 = alloca i32, align 4
  %19 = alloca i32, align 4
  %20 = alloca i32, align 4
  store ptr %0, ptr %8, align 8, !tbaa !5
  store i32 %1, ptr %9, align 4, !tbaa !9
  store ptr %2, ptr %10, align 8, !tbaa !5
  store i32 %3, ptr %11, align 4, !tbaa !9
  store i32 %4, ptr %12, align 4, !tbaa !9
  store ptr %5, ptr %13, align 8, !tbaa !5
  %21 = load ptr, ptr %8, align 8, !tbaa !5
  %22 = icmp eq ptr %21, null
  br i1 %22, label %23, label %26

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

26:                                               ; preds = %6
  %27 = load ptr, ptr %10, align 8, !tbaa !5
  %28 = icmp eq ptr %27, null
  br i1 %28, label %29, label %32

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

32:                                               ; preds = %26
  %33 = load ptr, ptr %13, align 8, !tbaa !5
  %34 = icmp eq ptr %33, null
  br i1 %34, label %35, label %38

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

38:                                               ; preds = %32
  %39 = load i32, ptr %9, align 4, !tbaa !9
  %40 = icmp slt i32 %39, 0
  br i1 %40, label %44, label %41

41:                                               ; preds = %38
  %42 = load i32, ptr %11, align 4, !tbaa !9
  %43 = icmp slt i32 %42, 0
  br i1 %43, label %44, label %47

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

47:                                               ; preds = %41
  %48 = load i32, ptr %12, align 4, !tbaa !9
  %49 = icmp sle i32 %48, 0
  br i1 %49, label %50, label %53

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

53:                                               ; preds = %47
  br label %54

54:                                               ; preds = %53
  br label %55

55:                                               ; preds = %54
  br label %56

56:                                               ; preds = %55
  br label %57

57:                                               ; preds = %56
  %58 = load i32, ptr %9, align 4, !tbaa !9
  %59 = load i32, ptr %11, align 4, !tbaa !9
  %60 = icmp ne i32 %58, %59
  br i1 %60, label %61, label %62

61:                                               ; preds = %57
  store i32 0, ptr %7, align 4
  br label %127

62:                                               ; preds = %57
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  %63 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %63, ptr %14, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #4
  %64 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %64, ptr %15, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #4
  store i32 0, ptr %16, align 4, !tbaa !9
  br label %65

65:                                               ; preds = %120, %62
  %66 = load i32, ptr %16, align 4, !tbaa !9
  %67 = load i32, ptr %9, align 4, !tbaa !9
  %68 = icmp slt i32 %66, %67
  br i1 %68, label %70, label %69

69:                                               ; preds = %65
  store i32 2, ptr %17, align 4
  br label %123

70:                                               ; preds = %65
  %71 = load ptr, ptr %13, align 8, !tbaa !5
  %72 = load ptr, ptr %14, align 8, !tbaa !5
  %73 = load i32, ptr %16, align 4, !tbaa !9
  %74 = load i32, ptr %12, align 4, !tbaa !9
  %75 = mul nsw i32 %73, %74
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds i8, ptr %72, i64 %76
  %78 = load ptr, ptr %15, align 8, !tbaa !5
  %79 = call i32 %71(ptr noundef %77, ptr noundef %78)
  %80 = icmp eq i32 %79, 0
  br i1 %80, label %81, label %119

81:                                               ; preds = %70
  call void @llvm.lifetime.start.p0(i64 4, ptr %18) #4
  %82 = load i32, ptr %16, align 4, !tbaa !9
  store i32 %82, ptr %18, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %19) #4
  store i32 0, ptr %19, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %20) #4
  store i32 1, ptr %20, align 4, !tbaa !9
  br label %83

83:                                               ; preds = %104, %81
  %84 = load i32, ptr %19, align 4, !tbaa !9
  %85 = load i32, ptr %11, align 4, !tbaa !9
  %86 = icmp ne i32 %84, %85
  br i1 %86, label %87, label %111

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

103:                                              ; preds = %87
  store i32 0, ptr %20, align 4, !tbaa !9
  br label %111

104:                                              ; preds = %87
  %105 = load i32, ptr %18, align 4, !tbaa !9
  %106 = add nsw i32 %105, 1
  %107 = load i32, ptr %9, align 4, !tbaa !9
  %108 = srem i32 %106, %107
  store i32 %108, ptr %18, align 4, !tbaa !9
  %109 = load i32, ptr %19, align 4, !tbaa !9
  %110 = add nsw i32 %109, 1
  store i32 %110, ptr %19, align 4, !tbaa !9
  br label %83, !llvm.loop !11

111:                                              ; preds = %103, %83
  %112 = load i32, ptr %20, align 4, !tbaa !9
  %113 = icmp ne i32 %112, 0
  br i1 %113, label %114, label %115

114:                                              ; preds = %111
  store i32 1, ptr %7, align 4
  store i32 1, ptr %17, align 4
  br label %116

115:                                              ; preds = %111
  store i32 0, ptr %17, align 4
  br label %116

116:                                              ; preds = %115, %114
  call void @llvm.lifetime.end.p0(i64 4, ptr %20) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %19) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #4
  %117 = load i32, ptr %17, align 4
  switch i32 %117, label %123 [
    i32 0, label %118
  ]

118:                                              ; preds = %116
  br label %119

119:                                              ; preds = %118, %70
  br label %120

120:                                              ; preds = %119
  %121 = load i32, ptr %16, align 4, !tbaa !9
  %122 = add nsw i32 %121, 1
  store i32 %122, ptr %16, align 4, !tbaa !9
  br label %65, !llvm.loop !13

123:                                              ; preds = %116, %69
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #4
  %124 = load i32, ptr %17, align 4
  switch i32 %124, label %126 [
    i32 2, label %125
  ]

125:                                              ; preds = %123
  store i32 0, ptr %7, align 4
  store i32 1, ptr %17, align 4
  br label %126

126:                                              ; preds = %125, %123
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  br label %127

127:                                              ; preds = %126, %61
  %128 = load i32, ptr %7, align 4
  ret i32 %128
}

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"}
!13 = distinct !{!13, !12}


; 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.62 = external hidden unnamed_addr constant [27 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 i32 @arrIsRotation(ptr noundef %0, i32 noundef %1, ptr noundef %2, i32 noundef %3, i32 noundef %4, ptr noundef readonly %5) local_unnamed_addr #2 {
  %7 = icmp eq ptr %0, null
  br i1 %7, label %8, label %11

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

11:                                               ; preds = %6
  %12 = icmp eq ptr %2, null
  br i1 %12, label %13, label %16

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

16:                                               ; preds = %11
  %17 = icmp eq ptr %5, null
  br i1 %17, label %18, label %21

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

21:                                               ; preds = %16
  %22 = or i32 %3, %1
  %or.cond.not = icmp sgt i32 %22, -1
  br i1 %or.cond.not, label %26, label %23

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

26:                                               ; preds = %21
  %27 = icmp slt i32 %4, 1
  br i1 %27, label %28, label %31

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

31:                                               ; preds = %26
  %.not = icmp eq i32 %1, %3
  br i1 %.not, label %.preheader52, label %49

.preheader52:                                     ; preds = %31
  %.not5160 = icmp sgt i32 %3, 0
  br i1 %.not5160, label %.lr.ph63.split.preheader, label %.critedge

.lr.ph63.split.preheader:                         ; preds = %.preheader52
  %32 = zext nneg i32 %4 to i64
  %33 = zext nneg i32 %3 to i64
  %34 = zext nneg i32 %3 to i64
  br label %.lr.ph63.split

.lr.ph63.split:                                   ; preds = %.lr.ph63.split.preheader, %.loopexit
  %indvars.iv72 = phi i64 [ 0, %.lr.ph63.split.preheader ], [ %indvars.iv.next73, %.loopexit ]
  %.not5162 = phi i1 [ true, %.lr.ph63.split.preheader ], [ %.not51, %.loopexit ]
  %35 = mul nuw nsw i64 %indvars.iv72, %32
  %36 = getelementptr inbounds i8, ptr %0, i64 %35
  %37 = tail call i32 %5(ptr noundef nonnull %36, ptr noundef nonnull %2) #5
  %38 = icmp eq i32 %37, 0
  br i1 %38, label %.preheader.preheader, label %.loopexit

.preheader.preheader:                             ; preds = %.lr.ph63.split
  %39 = trunc nuw nsw i64 %indvars.iv72 to i32
  br label %.preheader

.preheader:                                       ; preds = %.preheader.preheader, %46
  %indvars.iv = phi i64 [ 0, %.preheader.preheader ], [ %indvars.iv.next, %46 ]
  %.03757 = phi i32 [ %39, %.preheader.preheader ], [ %48, %46 ]
  %40 = mul nsw i32 %.03757, %4
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds i8, ptr %0, i64 %41
  %43 = mul nuw nsw i64 %indvars.iv, %32
  %44 = getelementptr inbounds i8, ptr %2, i64 %43
  %45 = tail call i32 %5(ptr noundef nonnull %42, ptr noundef nonnull %44) #5
  %.not49 = icmp eq i32 %45, 0
  br i1 %.not49, label %46, label %.loopexit

46:                                               ; preds = %.preheader
  %47 = add nsw i32 %.03757, 1
  %48 = srem i32 %47, %3
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %.not48.not.not = icmp eq i64 %indvars.iv.next, %33
  br i1 %.not48.not.not, label %.critedge, label %.preheader, !llvm.loop !9

.loopexit:                                        ; preds = %.preheader, %.lr.ph63.split
  %indvars.iv.next73 = add nuw nsw i64 %indvars.iv72, 1
  %.not51 = icmp ult i64 %indvars.iv.next73, %34
  %exitcond.not = icmp eq i64 %indvars.iv.next73, %33
  br i1 %exitcond.not, label %.critedge, label %.lr.ph63.split, !llvm.loop !11

.critedge:                                        ; preds = %.loopexit, %46, %.preheader52
  %.not5155 = phi i1 [ false, %.preheader52 ], [ %.not5162, %46 ], [ %.not51, %.loopexit ]
  %spec.select = zext i1 %.not5155 to i32
  br label %49

49:                                               ; preds = %31, %.critedge
  %.5 = phi i32 [ %spec.select, %.critedge ], [ 0, %31 ]
  ret i32 %.5
}

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"}
!11 = distinct !{!11, !10}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass