; LLVM IR from simon-zerisenay/42_Push_Swap :: src (sort_three_vals)

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

%struct.t_list = type { i32, i32, i32, i32, i32, ptr }

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

; Function Attrs: nounwind uwtable
define dso_local void @sort_three(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  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
  %7 = load ptr, ptr %2, align 8, !tbaa !5
  %8 = load ptr, ptr %7, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.t_list, ptr %8, i32 0, i32 1
  %10 = load i32, ptr %9, align 4, !tbaa !9
  store i32 %10, ptr %3, align 4, !tbaa !12
  %11 = load ptr, ptr %2, align 8, !tbaa !5
  %12 = load ptr, ptr %11, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.t_list, ptr %12, i32 0, i32 5
  %14 = load ptr, ptr %13, align 8, !tbaa !13
  %15 = getelementptr inbounds %struct.t_list, ptr %14, i32 0, i32 1
  %16 = load i32, ptr %15, align 4, !tbaa !9
  store i32 %16, ptr %4, align 4, !tbaa !12
  %17 = load ptr, ptr %2, align 8, !tbaa !5
  %18 = load ptr, ptr %17, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.t_list, ptr %18, i32 0, i32 5
  %20 = load ptr, ptr %19, align 8, !tbaa !13
  %21 = getelementptr inbounds %struct.t_list, ptr %20, i32 0, i32 5
  %22 = load ptr, ptr %21, align 8, !tbaa !13
  %23 = getelementptr inbounds %struct.t_list, ptr %22, i32 0, i32 1
  %24 = load i32, ptr %23, align 4, !tbaa !9
  store i32 %24, ptr %5, align 4, !tbaa !12
  %25 = load i32, ptr %3, align 4, !tbaa !12
  %26 = load i32, ptr %4, align 4, !tbaa !12
  %27 = icmp slt i32 %25, %26
  br i1 %27, label %28, label %33

28:                                               ; preds = %1
  %29 = load i32, ptr %4, align 4, !tbaa !12
  %30 = load i32, ptr %5, align 4, !tbaa !12
  %31 = icmp slt i32 %29, %30
  br i1 %31, label %32, label %33

32:                                               ; preds = %28
  store i32 1, ptr %6, align 4
  br label %106

33:                                               ; preds = %28, %1
  %34 = load i32, ptr %3, align 4, !tbaa !12
  %35 = load i32, ptr %4, align 4, !tbaa !12
  %36 = icmp slt i32 %34, %35
  br i1 %36, label %37, label %45

37:                                               ; preds = %33
  %38 = load i32, ptr %3, align 4, !tbaa !12
  %39 = load i32, ptr %5, align 4, !tbaa !12
  %40 = icmp slt i32 %38, %39
  br i1 %40, label %41, label %45

41:                                               ; preds = %37
  %42 = load ptr, ptr %2, align 8, !tbaa !5
  %43 = load ptr, ptr %42, align 8, !tbaa !5
  call void @swap(ptr noundef %43, ptr noundef @.str)
  %44 = load ptr, ptr %2, align 8, !tbaa !5
  call void @rotate(ptr noundef %44, ptr noundef @.str.1, i32 noundef 1)
  br label %104

45:                                               ; preds = %37, %33
  %46 = load i32, ptr %3, align 4, !tbaa !12
  %47 = load i32, ptr %4, align 4, !tbaa !12
  %48 = icmp sgt i32 %46, %47
  br i1 %48, label %49, label %60

49:                                               ; preds = %45
  %50 = load i32, ptr %3, align 4, !tbaa !12
  %51 = load i32, ptr %5, align 4, !tbaa !12
  %52 = icmp slt i32 %50, %51
  br i1 %52, label %53, label %60

53:                                               ; preds = %49
  %54 = load i32, ptr %4, align 4, !tbaa !12
  %55 = load i32, ptr %5, align 4, !tbaa !12
  %56 = icmp slt i32 %54, %55
  br i1 %56, label %57, label %60

57:                                               ; preds = %53
  %58 = load ptr, ptr %2, align 8, !tbaa !5
  %59 = load ptr, ptr %58, align 8, !tbaa !5
  call void @swap(ptr noundef %59, ptr noundef @.str)
  br label %103

60:                                               ; preds = %53, %49, %45
  %61 = load i32, ptr %3, align 4, !tbaa !12
  %62 = load i32, ptr %4, align 4, !tbaa !12
  %63 = icmp slt i32 %61, %62
  br i1 %63, label %64, label %70

64:                                               ; preds = %60
  %65 = load i32, ptr %3, align 4, !tbaa !12
  %66 = load i32, ptr %5, align 4, !tbaa !12
  %67 = icmp sgt i32 %65, %66
  br i1 %67, label %68, label %70

68:                                               ; preds = %64
  %69 = load ptr, ptr %2, align 8, !tbaa !5
  call void @reverse_rotate(ptr noundef %69, ptr noundef @.str.2, i32 noundef -1)
  br label %102

70:                                               ; preds = %64, %60
  %71 = load i32, ptr %3, align 4, !tbaa !12
  %72 = load i32, ptr %4, align 4, !tbaa !12
  %73 = icmp sgt i32 %71, %72
  br i1 %73, label %74, label %84

74:                                               ; preds = %70
  %75 = load i32, ptr %3, align 4, !tbaa !12
  %76 = load i32, ptr %5, align 4, !tbaa !12
  %77 = icmp sgt i32 %75, %76
  br i1 %77, label %78, label %84

78:                                               ; preds = %74
  %79 = load i32, ptr %4, align 4, !tbaa !12
  %80 = load i32, ptr %5, align 4, !tbaa !12
  %81 = icmp slt i32 %79, %80
  br i1 %81, label %82, label %84

82:                                               ; preds = %78
  %83 = load ptr, ptr %2, align 8, !tbaa !5
  call void @rotate(ptr noundef %83, ptr noundef @.str.1, i32 noundef 1)
  br label %101

84:                                               ; preds = %78, %74, %70
  %85 = load i32, ptr %3, align 4, !tbaa !12
  %86 = load i32, ptr %4, align 4, !tbaa !12
  %87 = icmp sgt i32 %85, %86
  br i1 %87, label %88, label %100

88:                                               ; preds = %84
  %89 = load i32, ptr %3, align 4, !tbaa !12
  %90 = load i32, ptr %5, align 4, !tbaa !12
  %91 = icmp sgt i32 %89, %90
  br i1 %91, label %92, label %100

92:                                               ; preds = %88
  %93 = load i32, ptr %4, align 4, !tbaa !12
  %94 = load i32, ptr %5, align 4, !tbaa !12
  %95 = icmp sgt i32 %93, %94
  br i1 %95, label %96, label %100

96:                                               ; preds = %92
  %97 = load ptr, ptr %2, align 8, !tbaa !5
  %98 = load ptr, ptr %97, align 8, !tbaa !5
  call void @swap(ptr noundef %98, ptr noundef @.str)
  %99 = load ptr, ptr %2, align 8, !tbaa !5
  call void @reverse_rotate(ptr noundef %99, ptr noundef @.str.2, i32 noundef -1)
  br label %100

100:                                              ; preds = %96, %92, %88, %84
  br label %101

101:                                              ; preds = %100, %82
  br label %102

102:                                              ; preds = %101, %68
  br label %103

103:                                              ; preds = %102, %57
  br label %104

104:                                              ; preds = %103, %41
  br label %105

105:                                              ; preds = %104
  store i32 0, ptr %6, align 4
  br label %106

106:                                              ; preds = %105, %32
  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
  %107 = load i32, ptr %6, align 4
  switch i32 %107, label %109 [
    i32 0, label %108
    i32 1, label %108
  ]

108:                                              ; preds = %106, %106
  ret void

109:                                              ; preds = %106
  unreachable
}

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

declare void @swap(ptr noundef, ptr noundef) #2

declare void @rotate(ptr noundef, ptr noundef, i32 noundef) #2

declare void @reverse_rotate(ptr noundef, ptr noundef, i32 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 4}
!10 = !{!"t_list", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !6, i64 24}
!11 = !{!"int", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!10, !6, i64 24}


; 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 [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @sort_three(ptr noundef %0) local_unnamed_addr #0 {
  %2 = load ptr, ptr %0, align 8, !tbaa !5
  %3 = getelementptr inbounds i8, ptr %2, i64 4
  %4 = load i32, ptr %3, align 4, !tbaa !9
  %5 = getelementptr inbounds i8, ptr %2, i64 24
  %6 = load ptr, ptr %5, align 8, !tbaa !12
  %7 = getelementptr inbounds i8, ptr %6, i64 4
  %8 = load i32, ptr %7, align 4, !tbaa !9
  %9 = getelementptr inbounds i8, ptr %6, i64 24
  %10 = load ptr, ptr %9, align 8, !tbaa !12
  %11 = getelementptr inbounds i8, ptr %10, i64 4
  %12 = load i32, ptr %11, align 4, !tbaa !9
  %13 = icmp slt i32 %4, %8
  %14 = icmp slt i32 %8, %12
  %or.cond = select i1 %13, i1 %14, i1 false
  br i1 %or.cond, label %30, label %15

15:                                               ; preds = %1
  %16 = icmp slt i32 %4, %12
  %or.cond46 = select i1 %13, i1 %16, i1 false
  br i1 %or.cond46, label %17, label %18

17:                                               ; preds = %15
  tail call void @swap(ptr noundef nonnull %2, ptr noundef nonnull @.str) #2
  tail call void @rotate(ptr noundef nonnull %0, ptr noundef nonnull @.str.1, i32 noundef 1) #2
  br label %30

18:                                               ; preds = %15
  %19 = icmp sgt i32 %4, %8
  %20 = and i1 %16, %14
  %or.cond48 = select i1 %19, i1 %20, i1 false
  br i1 %or.cond48, label %21, label %22

21:                                               ; preds = %18
  tail call void @swap(ptr noundef nonnull %2, ptr noundef nonnull @.str) #2
  br label %30

22:                                               ; preds = %18
  %23 = icmp sgt i32 %4, %12
  %or.cond49 = select i1 %13, i1 %23, i1 false
  br i1 %or.cond49, label %24, label %25

24:                                               ; preds = %22
  tail call void @reverse_rotate(ptr noundef nonnull %0, ptr noundef nonnull @.str.2, i32 noundef -1) #2
  br label %30

25:                                               ; preds = %22
  %or.cond50 = select i1 %19, i1 %23, i1 false
  %or.cond51 = select i1 %or.cond50, i1 %14, i1 false
  br i1 %or.cond51, label %26, label %27

26:                                               ; preds = %25
  tail call void @rotate(ptr noundef nonnull %0, ptr noundef nonnull @.str.1, i32 noundef 1) #2
  br label %30

27:                                               ; preds = %25
  %28 = icmp sgt i32 %8, %12
  %or.cond53 = select i1 %or.cond50, i1 %28, i1 false
  br i1 %or.cond53, label %29, label %30

29:                                               ; preds = %27
  tail call void @swap(ptr noundef nonnull %2, ptr noundef nonnull @.str) #2
  tail call void @reverse_rotate(ptr noundef nonnull %0, ptr noundef nonnull @.str.2, i32 noundef -1) #2
  br label %30

30:                                               ; preds = %21, %26, %29, %27, %24, %17, %1
  ret void
}

declare void @swap(ptr noundef, ptr noundef) local_unnamed_addr #1

declare void @rotate(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

declare void @reverse_rotate(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #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 = { "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 }

!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, !11, i64 4}
!10 = !{!"t_list", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !6, i64 24}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !6, i64 24}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass