; LLVM IR from AlgoGenesis/C :: Sorting Algorithms/Shell Sort (Program)

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

@bigONotation = external dso_local global ptr, align 8
@.str.3 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [29 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @displayArray(ptr noundef, i32 noundef) #0

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

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @shellSort(ptr noundef, i32 noundef) #0

; Function Attrs: nounwind uwtable
define dso_local i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca [15 x i32], align 16
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca double, align 8
  %8 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 60, ptr %2) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store i32 500, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %9 = call i64 @time(ptr noundef null) #4
  %10 = trunc i64 %9 to i32
  call void @srand(i32 noundef %10) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  store i32 0, ptr %8, align 4, !tbaa !5
  br label %11

11:                                               ; preds = %23, %0
  %12 = load i32, ptr %8, align 4, !tbaa !5
  %13 = icmp slt i32 %12, 15
  br i1 %13, label %15, label %14

14:                                               ; preds = %11
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  br label %26

15:                                               ; preds = %11
  %16 = call i32 @rand() #4
  %17 = load i32, ptr %3, align 4, !tbaa !5
  %18 = srem i32 %16, %17
  %19 = add nsw i32 %18, 1
  %20 = load i32, ptr %8, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [15 x i32], ptr %2, i64 0, i64 %21
  store i32 %19, ptr %22, align 4, !tbaa !5
  br label %23

23:                                               ; preds = %15
  %24 = load i32, ptr %8, align 4, !tbaa !5
  %25 = add nsw i32 %24, 1
  store i32 %25, ptr %8, align 4, !tbaa !5
  br label %11, !llvm.loop !9

26:                                               ; preds = %14
  store i32 15, ptr %4, align 4, !tbaa !5
  %27 = getelementptr inbounds [15 x i32], ptr %2, i64 0, i64 0
  %28 = load i32, ptr %4, align 4, !tbaa !5
  call void @displayArray(ptr noundef %27, i32 noundef %28)
  %29 = call i64 @clock() #4
  store i64 %29, ptr %5, align 8, !tbaa !11
  %30 = getelementptr inbounds [15 x i32], ptr %2, i64 0, i64 0
  %31 = load i32, ptr %4, align 4, !tbaa !5
  call void @shellSort(ptr noundef %30, i32 noundef %31)
  %32 = call i64 @clock() #4
  store i64 %32, ptr %6, align 8, !tbaa !11
  %33 = load i64, ptr %6, align 8, !tbaa !11
  %34 = load i64, ptr %5, align 8, !tbaa !11
  %35 = sub nsw i64 %33, %34
  %36 = sitofp i64 %35 to double
  %37 = fdiv double %36, 1.000000e+06
  store double %37, ptr %7, align 8, !tbaa !13
  %38 = call i32 (ptr, ...) @printf(ptr noundef @.str.3)
  %39 = getelementptr inbounds [15 x i32], ptr %2, i64 0, i64 0
  %40 = load i32, ptr %4, align 4, !tbaa !5
  call void @displayArray(ptr noundef %39, i32 noundef %40)
  %41 = load ptr, ptr @bigONotation, align 8, !tbaa !15
  %42 = call i32 (ptr, ...) @printf(ptr noundef @.str.4, ptr noundef %41)
  %43 = load double, ptr %7, align 8, !tbaa !13
  %44 = fmul double %43, 1.000000e+03
  %45 = call i32 (ptr, ...) @printf(ptr noundef @.str.5, double noundef %44)
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 60, ptr %2) #4
  ret i32 0
}

; Function Attrs: nounwind
declare void @srand(i32 noundef) #3

; Function Attrs: nounwind
declare i64 @time(ptr noundef) #3

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

; Function Attrs: nounwind
declare i64 @clock() #3

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = { 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"double", !7, i64 0}
!15 = !{!16, !16, i64 0}
!16 = !{!"any pointer", !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"

@bigONotation = external dso_local local_unnamed_addr global ptr, align 8
@.str.3 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [29 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @displayArray(ptr noundef, i32 noundef) local_unnamed_addr #0

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

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @shellSort(ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca [15 x i32], align 16
  call void @llvm.lifetime.start.p0(i64 60, ptr nonnull %1) #4
  %2 = tail call i64 @time(ptr noundef null) #4
  %3 = trunc i64 %2 to i32
  tail call void @srand(i32 noundef %3) #4
  %4 = tail call i32 @rand() #4
  %5 = tail call i32 @rand() #4
  %6 = tail call i32 @rand() #4
  %7 = tail call i32 @rand() #4
  %8 = insertelement <4 x i32> poison, i32 %4, i64 0
  %9 = insertelement <4 x i32> %8, i32 %5, i64 1
  %10 = insertelement <4 x i32> %9, i32 %6, i64 2
  %11 = insertelement <4 x i32> %10, i32 %7, i64 3
  %12 = srem <4 x i32> %11, <i32 500, i32 500, i32 500, i32 500>
  %13 = add nsw <4 x i32> %12, <i32 1, i32 1, i32 1, i32 1>
  store <4 x i32> %13, ptr %1, align 16, !tbaa !5
  %14 = tail call i32 @rand() #4
  %15 = getelementptr inbounds i8, ptr %1, i64 16
  %16 = tail call i32 @rand() #4
  %17 = tail call i32 @rand() #4
  %18 = tail call i32 @rand() #4
  %19 = insertelement <4 x i32> poison, i32 %14, i64 0
  %20 = insertelement <4 x i32> %19, i32 %16, i64 1
  %21 = insertelement <4 x i32> %20, i32 %17, i64 2
  %22 = insertelement <4 x i32> %21, i32 %18, i64 3
  %23 = srem <4 x i32> %22, <i32 500, i32 500, i32 500, i32 500>
  %24 = add nsw <4 x i32> %23, <i32 1, i32 1, i32 1, i32 1>
  store <4 x i32> %24, ptr %15, align 16, !tbaa !5
  %25 = tail call i32 @rand() #4
  %26 = getelementptr inbounds i8, ptr %1, i64 32
  %27 = tail call i32 @rand() #4
  %28 = tail call i32 @rand() #4
  %29 = tail call i32 @rand() #4
  %30 = insertelement <4 x i32> poison, i32 %25, i64 0
  %31 = insertelement <4 x i32> %30, i32 %27, i64 1
  %32 = insertelement <4 x i32> %31, i32 %28, i64 2
  %33 = insertelement <4 x i32> %32, i32 %29, i64 3
  %34 = srem <4 x i32> %33, <i32 500, i32 500, i32 500, i32 500>
  %35 = add nsw <4 x i32> %34, <i32 1, i32 1, i32 1, i32 1>
  store <4 x i32> %35, ptr %26, align 16, !tbaa !5
  %36 = tail call i32 @rand() #4
  %37 = srem i32 %36, 500
  %38 = add nsw i32 %37, 1
  %39 = getelementptr inbounds i8, ptr %1, i64 48
  store i32 %38, ptr %39, align 16, !tbaa !5
  %40 = tail call i32 @rand() #4
  %41 = srem i32 %40, 500
  %42 = add nsw i32 %41, 1
  %43 = getelementptr inbounds i8, ptr %1, i64 52
  store i32 %42, ptr %43, align 4, !tbaa !5
  %44 = tail call i32 @rand() #4
  %45 = srem i32 %44, 500
  %46 = add nsw i32 %45, 1
  %47 = getelementptr inbounds i8, ptr %1, i64 56
  store i32 %46, ptr %47, align 8, !tbaa !5
  call void @displayArray(ptr noundef nonnull %1, i32 noundef 15)
  %48 = call i64 @clock() #4
  call void @shellSort(ptr noundef nonnull %1, i32 noundef 15)
  %49 = call i64 @clock() #4
  %50 = sub nsw i64 %49, %48
  %51 = sitofp i64 %50 to double
  %52 = fdiv double %51, 1.000000e+06
  %53 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3)
  call void @displayArray(ptr noundef nonnull %1, i32 noundef 15)
  %54 = load ptr, ptr @bigONotation, align 8, !tbaa !9
  %55 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4, ptr noundef %54)
  %56 = fmul double %52, 1.000000e+03
  %57 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.5, double noundef %56)
  call void @llvm.lifetime.end.p0(i64 60, ptr nonnull %1) #4
  ret i32 0
}

; Function Attrs: nounwind
declare void @srand(i32 noundef) local_unnamed_addr #3

; Function Attrs: nounwind
declare i64 @time(ptr noundef) local_unnamed_addr #3

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

; Function Attrs: nounwind
declare i64 @clock() local_unnamed_addr #3

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


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass