; LLVM IR from 4N1Z/Sorting-Searching-Algorithms :: Sorting/Selection-sort (in_C)

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

@.str = external hidden unnamed_addr constant [33 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [47 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [47 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @main() #0 {
  %1 = alloca [30 x i32], align 16
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 120, ptr %1) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 0, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 5, ptr %6, align 4, !tbaa !5
  %7 = call i32 (ptr, ...) @printf(ptr noundef @.str)
  %8 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %4)
  %9 = call i32 (ptr, ...) @printf(ptr noundef @.str.2)
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %10

10:                                               ; preds = %19, %0
  %11 = load i32, ptr %2, align 4, !tbaa !5
  %12 = load i32, ptr %4, align 4, !tbaa !5
  %13 = icmp slt i32 %11, %12
  br i1 %13, label %14, label %22

14:                                               ; preds = %10
  %15 = load i32, ptr %2, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [30 x i32], ptr %1, i64 0, i64 %16
  %18 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %17)
  br label %19

19:                                               ; preds = %14
  %20 = load i32, ptr %2, align 4, !tbaa !5
  %21 = add nsw i32 %20, 1
  store i32 %21, ptr %2, align 4, !tbaa !5
  br label %10, !llvm.loop !9

22:                                               ; preds = %10
  %23 = call i32 (ptr, ...) @printf(ptr noundef @.str.3)
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %24

24:                                               ; preds = %34, %22
  %25 = load i32, ptr %2, align 4, !tbaa !5
  %26 = load i32, ptr %4, align 4, !tbaa !5
  %27 = icmp slt i32 %25, %26
  br i1 %27, label %28, label %37

28:                                               ; preds = %24
  %29 = load i32, ptr %2, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [30 x i32], ptr %1, i64 0, i64 %30
  %32 = load i32, ptr %31, align 4, !tbaa !5
  %33 = call i32 (ptr, ...) @printf(ptr noundef @.str.4, i32 noundef %32)
  br label %34

34:                                               ; preds = %28
  %35 = load i32, ptr %2, align 4, !tbaa !5
  %36 = add nsw i32 %35, 1
  store i32 %36, ptr %2, align 4, !tbaa !5
  br label %24, !llvm.loop !11

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

38:                                               ; preds = %83, %37
  %39 = load i32, ptr %2, align 4, !tbaa !5
  %40 = load i32, ptr %4, align 4, !tbaa !5
  %41 = sub nsw i32 %40, 1
  %42 = icmp slt i32 %39, %41
  br i1 %42, label %43, label %86

43:                                               ; preds = %38
  %44 = load i32, ptr %2, align 4, !tbaa !5
  store i32 %44, ptr %5, align 4, !tbaa !5
  %45 = load i32, ptr %2, align 4, !tbaa !5
  %46 = add nsw i32 %45, 1
  store i32 %46, ptr %3, align 4, !tbaa !5
  br label %47

47:                                               ; preds = %64, %43
  %48 = load i32, ptr %3, align 4, !tbaa !5
  %49 = load i32, ptr %4, align 4, !tbaa !5
  %50 = icmp slt i32 %48, %49
  br i1 %50, label %51, label %67

51:                                               ; preds = %47
  %52 = load i32, ptr %3, align 4, !tbaa !5
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [30 x i32], ptr %1, i64 0, i64 %53
  %55 = load i32, ptr %54, align 4, !tbaa !5
  %56 = load i32, ptr %5, align 4, !tbaa !5
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [30 x i32], ptr %1, i64 0, i64 %57
  %59 = load i32, ptr %58, align 4, !tbaa !5
  %60 = icmp slt i32 %55, %59
  br i1 %60, label %61, label %63

61:                                               ; preds = %51
  %62 = load i32, ptr %3, align 4, !tbaa !5
  store i32 %62, ptr %5, align 4, !tbaa !5
  br label %63

63:                                               ; preds = %61, %51
  br label %64

64:                                               ; preds = %63
  %65 = load i32, ptr %3, align 4, !tbaa !5
  %66 = add nsw i32 %65, 1
  store i32 %66, ptr %3, align 4, !tbaa !5
  br label %47, !llvm.loop !12

67:                                               ; preds = %47
  %68 = load i32, ptr %2, align 4, !tbaa !5
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds [30 x i32], ptr %1, i64 0, i64 %69
  %71 = load i32, ptr %70, align 4, !tbaa !5
  store i32 %71, ptr %6, align 4, !tbaa !5
  %72 = load i32, ptr %5, align 4, !tbaa !5
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds [30 x i32], ptr %1, i64 0, i64 %73
  %75 = load i32, ptr %74, align 4, !tbaa !5
  %76 = load i32, ptr %2, align 4, !tbaa !5
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds [30 x i32], ptr %1, i64 0, i64 %77
  store i32 %75, ptr %78, align 4, !tbaa !5
  %79 = load i32, ptr %6, align 4, !tbaa !5
  %80 = load i32, ptr %5, align 4, !tbaa !5
  %81 = sext i32 %80 to i64
  %82 = getelementptr inbounds [30 x i32], ptr %1, i64 0, i64 %81
  store i32 %79, ptr %82, align 4, !tbaa !5
  br label %83

83:                                               ; preds = %67
  %84 = load i32, ptr %2, align 4, !tbaa !5
  %85 = add nsw i32 %84, 1
  store i32 %85, ptr %2, align 4, !tbaa !5
  br label %38, !llvm.loop !13

86:                                               ; preds = %38
  %87 = call i32 (ptr, ...) @printf(ptr noundef @.str.5)
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %88

88:                                               ; preds = %98, %86
  %89 = load i32, ptr %2, align 4, !tbaa !5
  %90 = load i32, ptr %4, align 4, !tbaa !5
  %91 = icmp slt i32 %89, %90
  br i1 %91, label %92, label %101

92:                                               ; preds = %88
  %93 = load i32, ptr %2, align 4, !tbaa !5
  %94 = sext i32 %93 to i64
  %95 = getelementptr inbounds [30 x i32], ptr %1, i64 0, i64 %94
  %96 = load i32, ptr %95, align 4, !tbaa !5
  %97 = call i32 (ptr, ...) @printf(ptr noundef @.str.4, i32 noundef %96)
  br label %98

98:                                               ; preds = %92
  %99 = load i32, ptr %2, align 4, !tbaa !5
  %100 = add nsw i32 %99, 1
  store i32 %100, ptr %2, align 4, !tbaa !5
  br label %88, !llvm.loop !14

101:                                              ; preds = %88
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  call void @llvm.lifetime.end.p0(i64 120, ptr %1) #3
  ret void
}

; 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

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

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

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 }

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


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

@.str = external hidden unnamed_addr constant [33 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [47 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [47 x i8], align 1

; Function Attrs: nofree nounwind uwtable
define dso_local void @main() local_unnamed_addr #0 {
  %1 = alloca [30 x i32], align 16
  %2 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 120, ptr nonnull %1) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #3
  %3 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str)
  %4 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %2)
  %5 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2)
  %6 = load i32, ptr %2, align 4, !tbaa !5
  %7 = icmp sgt i32 %6, 0
  br i1 %7, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %0, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %0 ]
  %8 = getelementptr inbounds [30 x i32], ptr %1, i64 0, i64 %indvars.iv
  %9 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %8)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %10 = load i32, ptr %2, align 4, !tbaa !5
  %11 = sext i32 %10 to i64
  %12 = icmp slt i64 %indvars.iv.next, %11
  br i1 %12, label %.lr.ph, label %._crit_edge, !llvm.loop !9

._crit_edge:                                      ; preds = %.lr.ph, %0
  %13 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3)
  %14 = load i32, ptr %2, align 4, !tbaa !5
  %15 = icmp sgt i32 %14, 0
  br i1 %15, label %.lr.ph29, label %._crit_edge38

.preheader:                                       ; preds = %.lr.ph29
  %16 = icmp sgt i32 %21, 1
  br i1 %16, label %.lr.ph37.preheader, label %._crit_edge38

.lr.ph37.preheader:                               ; preds = %.preheader
  %17 = add nsw i32 %21, -1
  %wide.trip.count56 = zext nneg i32 %17 to i64
  %wide.trip.count = zext nneg i32 %21 to i64
  br label %.lr.ph33.preheader

.lr.ph29:                                         ; preds = %._crit_edge, %.lr.ph29
  %indvars.iv45 = phi i64 [ %indvars.iv.next46, %.lr.ph29 ], [ 0, %._crit_edge ]
  %18 = getelementptr inbounds [30 x i32], ptr %1, i64 0, i64 %indvars.iv45
  %19 = load i32, ptr %18, align 4, !tbaa !5
  %20 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4, i32 noundef %19)
  %indvars.iv.next46 = add nuw nsw i64 %indvars.iv45, 1
  %21 = load i32, ptr %2, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = icmp slt i64 %indvars.iv.next46, %22
  br i1 %23, label %.lr.ph29, label %.preheader, !llvm.loop !11

.lr.ph33.preheader:                               ; preds = %._crit_edge34, %.lr.ph37.preheader
  %indvars.iv53 = phi i64 [ 0, %.lr.ph37.preheader ], [ %indvars.iv.next54, %._crit_edge34 ]
  %indvars.iv48 = phi i64 [ 1, %.lr.ph37.preheader ], [ %indvars.iv.next49, %._crit_edge34 ]
  %indvars.iv.next54 = add nuw nsw i64 %indvars.iv53, 1
  %24 = trunc nuw nsw i64 %indvars.iv53 to i32
  br label %.lr.ph33

.lr.ph33:                                         ; preds = %.lr.ph33.preheader, %.lr.ph33
  %indvars.iv50 = phi i64 [ %indvars.iv48, %.lr.ph33.preheader ], [ %indvars.iv.next51, %.lr.ph33 ]
  %.031 = phi i32 [ %24, %.lr.ph33.preheader ], [ %spec.select, %.lr.ph33 ]
  %25 = getelementptr inbounds [30 x i32], ptr %1, i64 0, i64 %indvars.iv50
  %26 = load i32, ptr %25, align 4, !tbaa !5
  %27 = sext i32 %.031 to i64
  %28 = getelementptr inbounds [30 x i32], ptr %1, i64 0, i64 %27
  %29 = load i32, ptr %28, align 4, !tbaa !5
  %30 = icmp slt i32 %26, %29
  %31 = trunc nuw nsw i64 %indvars.iv50 to i32
  %spec.select = select i1 %30, i32 %31, i32 %.031
  %indvars.iv.next51 = add nuw nsw i64 %indvars.iv50, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next51, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge34, label %.lr.ph33, !llvm.loop !12

._crit_edge34:                                    ; preds = %.lr.ph33
  %32 = getelementptr inbounds [30 x i32], ptr %1, i64 0, i64 %indvars.iv53
  %33 = load i32, ptr %32, align 4, !tbaa !5
  %34 = sext i32 %spec.select to i64
  %35 = getelementptr inbounds [30 x i32], ptr %1, i64 0, i64 %34
  %36 = load i32, ptr %35, align 4, !tbaa !5
  store i32 %36, ptr %32, align 4, !tbaa !5
  store i32 %33, ptr %35, align 4, !tbaa !5
  %indvars.iv.next49 = add nuw nsw i64 %indvars.iv48, 1
  %exitcond57.not = icmp eq i64 %indvars.iv.next54, %wide.trip.count56
  br i1 %exitcond57.not, label %._crit_edge38, label %.lr.ph33.preheader, !llvm.loop !13

._crit_edge38:                                    ; preds = %._crit_edge34, %._crit_edge, %.preheader
  %37 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.5)
  %38 = load i32, ptr %2, align 4, !tbaa !5
  %39 = icmp sgt i32 %38, 0
  br i1 %39, label %.lr.ph41, label %._crit_edge42

.lr.ph41:                                         ; preds = %._crit_edge38, %.lr.ph41
  %indvars.iv58 = phi i64 [ %indvars.iv.next59, %.lr.ph41 ], [ 0, %._crit_edge38 ]
  %40 = getelementptr inbounds [30 x i32], ptr %1, i64 0, i64 %indvars.iv58
  %41 = load i32, ptr %40, align 4, !tbaa !5
  %42 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4, i32 noundef %41)
  %indvars.iv.next59 = add nuw nsw i64 %indvars.iv58, 1
  %43 = load i32, ptr %2, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = icmp slt i64 %indvars.iv.next59, %44
  br i1 %45, label %.lr.ph41, label %._crit_edge42, !llvm.loop !14

._crit_edge42:                                    ; preds = %.lr.ph41, %._crit_edge38
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #3
  call void @llvm.lifetime.end.p0(i64 120, ptr nonnull %1) #3
  ret void
}

; 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: nofree nounwind
declare noundef i32 @__isoc99_scanf(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

attributes #0 = { nofree 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 }

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


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