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

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

; Function Attrs: nounwind uwtable
define dso_local void @reorder_a_and_b(i32 noundef %0, ptr noundef %1, ptr noundef %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  store ptr %2, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %8 = load ptr, ptr %6, align 8, !tbaa !9
  %9 = load ptr, ptr %8, align 8, !tbaa !9
  store ptr %9, ptr %7, align 8, !tbaa !9
  br label %10

10:                                               ; preds = %16, %3
  %11 = load ptr, ptr %7, align 8, !tbaa !9
  %12 = getelementptr inbounds %struct.t_list, ptr %11, i32 0, i32 4
  %13 = load i32, ptr %12, align 8, !tbaa !11
  %14 = load i32, ptr %4, align 4, !tbaa !5
  %15 = icmp ne i32 %13, %14
  br i1 %15, label %16, label %20

16:                                               ; preds = %10
  %17 = load ptr, ptr %7, align 8, !tbaa !9
  %18 = getelementptr inbounds %struct.t_list, ptr %17, i32 0, i32 5
  %19 = load ptr, ptr %18, align 8, !tbaa !13
  store ptr %19, ptr %7, align 8, !tbaa !9
  br label %10, !llvm.loop !14

20:                                               ; preds = %10
  %21 = load ptr, ptr %7, align 8, !tbaa !9
  %22 = getelementptr inbounds %struct.t_list, ptr %21, i32 0, i32 2
  %23 = load i32, ptr %22, align 8, !tbaa !16
  %24 = icmp slt i32 %23, 0
  br i1 %24, label %25, label %39

25:                                               ; preds = %20
  %26 = load ptr, ptr %7, align 8, !tbaa !9
  %27 = getelementptr inbounds %struct.t_list, ptr %26, i32 0, i32 3
  %28 = load i32, ptr %27, align 4, !tbaa !17
  %29 = icmp slt i32 %28, 0
  br i1 %29, label %30, label %39

30:                                               ; preds = %25
  %31 = load ptr, ptr %5, align 8, !tbaa !9
  %32 = load ptr, ptr %6, align 8, !tbaa !9
  %33 = load ptr, ptr %7, align 8, !tbaa !9
  %34 = getelementptr inbounds %struct.t_list, ptr %33, i32 0, i32 2
  %35 = load i32, ptr %34, align 8, !tbaa !16
  %36 = load ptr, ptr %7, align 8, !tbaa !9
  %37 = getelementptr inbounds %struct.t_list, ptr %36, i32 0, i32 3
  %38 = load i32, ptr %37, align 4, !tbaa !17
  call void @reverse_rotate_both(ptr noundef %31, ptr noundef %32, i32 noundef %35, i32 noundef %38)
  br label %99

39:                                               ; preds = %25, %20
  %40 = load ptr, ptr %7, align 8, !tbaa !9
  %41 = getelementptr inbounds %struct.t_list, ptr %40, i32 0, i32 2
  %42 = load i32, ptr %41, align 8, !tbaa !16
  %43 = icmp sgt i32 %42, 0
  br i1 %43, label %44, label %58

44:                                               ; preds = %39
  %45 = load ptr, ptr %7, align 8, !tbaa !9
  %46 = getelementptr inbounds %struct.t_list, ptr %45, i32 0, i32 3
  %47 = load i32, ptr %46, align 4, !tbaa !17
  %48 = icmp sgt i32 %47, 0
  br i1 %48, label %49, label %58

49:                                               ; preds = %44
  %50 = load ptr, ptr %5, align 8, !tbaa !9
  %51 = load ptr, ptr %6, align 8, !tbaa !9
  %52 = load ptr, ptr %7, align 8, !tbaa !9
  %53 = getelementptr inbounds %struct.t_list, ptr %52, i32 0, i32 2
  %54 = load i32, ptr %53, align 8, !tbaa !16
  %55 = load ptr, ptr %7, align 8, !tbaa !9
  %56 = getelementptr inbounds %struct.t_list, ptr %55, i32 0, i32 3
  %57 = load i32, ptr %56, align 4, !tbaa !17
  call void @rotate_both(ptr noundef %50, ptr noundef %51, i32 noundef %54, i32 noundef %57)
  br label %98

58:                                               ; preds = %44, %39
  %59 = load ptr, ptr %7, align 8, !tbaa !9
  %60 = getelementptr inbounds %struct.t_list, ptr %59, i32 0, i32 3
  %61 = load i32, ptr %60, align 4, !tbaa !17
  %62 = icmp sge i32 %61, 0
  br i1 %62, label %63, label %77

63:                                               ; preds = %58
  %64 = load ptr, ptr %7, align 8, !tbaa !9
  %65 = getelementptr inbounds %struct.t_list, ptr %64, i32 0, i32 2
  %66 = load i32, ptr %65, align 8, !tbaa !16
  %67 = icmp sle i32 %66, 0
  br i1 %67, label %68, label %77

68:                                               ; preds = %63
  %69 = load ptr, ptr %6, align 8, !tbaa !9
  %70 = load ptr, ptr %7, align 8, !tbaa !9
  %71 = getelementptr inbounds %struct.t_list, ptr %70, i32 0, i32 3
  %72 = load i32, ptr %71, align 4, !tbaa !17
  call void @rotate(ptr noundef %69, ptr noundef @.str, i32 noundef %72)
  %73 = load ptr, ptr %5, align 8, !tbaa !9
  %74 = load ptr, ptr %7, align 8, !tbaa !9
  %75 = getelementptr inbounds %struct.t_list, ptr %74, i32 0, i32 2
  %76 = load i32, ptr %75, align 8, !tbaa !16
  call void @reverse_rotate(ptr noundef %73, ptr noundef @.str.1, i32 noundef %76)
  br label %97

77:                                               ; preds = %63, %58
  %78 = load ptr, ptr %7, align 8, !tbaa !9
  %79 = getelementptr inbounds %struct.t_list, ptr %78, i32 0, i32 3
  %80 = load i32, ptr %79, align 4, !tbaa !17
  %81 = icmp sle i32 %80, 0
  br i1 %81, label %82, label %96

82:                                               ; preds = %77
  %83 = load ptr, ptr %7, align 8, !tbaa !9
  %84 = getelementptr inbounds %struct.t_list, ptr %83, i32 0, i32 2
  %85 = load i32, ptr %84, align 8, !tbaa !16
  %86 = icmp sge i32 %85, 0
  br i1 %86, label %87, label %96

87:                                               ; preds = %82
  %88 = load ptr, ptr %6, align 8, !tbaa !9
  %89 = load ptr, ptr %7, align 8, !tbaa !9
  %90 = getelementptr inbounds %struct.t_list, ptr %89, i32 0, i32 3
  %91 = load i32, ptr %90, align 4, !tbaa !17
  call void @reverse_rotate(ptr noundef %88, ptr noundef @.str.2, i32 noundef %91)
  %92 = load ptr, ptr %5, align 8, !tbaa !9
  %93 = load ptr, ptr %7, align 8, !tbaa !9
  %94 = getelementptr inbounds %struct.t_list, ptr %93, i32 0, i32 2
  %95 = load i32, ptr %94, align 8, !tbaa !16
  call void @rotate(ptr noundef %92, ptr noundef @.str.3, i32 noundef %95)
  br label %96

96:                                               ; preds = %87, %82, %77
  br label %97

97:                                               ; preds = %96, %68
  br label %98

98:                                               ; preds = %97, %49
  br label %99

99:                                               ; preds = %98, %30
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #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 void @reverse_rotate_both(ptr noundef, ptr noundef, i32 noundef, i32 noundef) #2

declare void @rotate_both(ptr noundef, ptr noundef, i32 noundef, i32 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 = !{!"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}
!11 = !{!12, !6, i64 16}
!12 = !{!"t_list", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !6, i64 16, !10, i64 24}
!13 = !{!12, !10, i64 24}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!12, !6, i64 8}
!17 = !{!12, !6, i64 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"

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

; Function Attrs: nounwind uwtable
define dso_local void @reorder_a_and_b(i32 noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  br label %4

4:                                                ; preds = %4, %3
  %.0.in = phi ptr [ %2, %3 ], [ %7, %4 ]
  %.0 = load ptr, ptr %.0.in, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %.0, i64 16
  %6 = load i32, ptr %5, align 8, !tbaa !9
  %.not = icmp eq i32 %6, %0
  %7 = getelementptr inbounds i8, ptr %.0, i64 24
  br i1 %.not, label %8, label %4, !llvm.loop !12

8:                                                ; preds = %4
  %9 = getelementptr inbounds i8, ptr %.0, i64 8
  %10 = load i32, ptr %9, align 8, !tbaa !14
  %11 = icmp slt i32 %10, 0
  br i1 %11, label %12, label %17

12:                                               ; preds = %8
  %13 = getelementptr inbounds i8, ptr %.0, i64 12
  %14 = load i32, ptr %13, align 4, !tbaa !15
  %15 = icmp slt i32 %14, 0
  br i1 %15, label %16, label %.thread34

16:                                               ; preds = %12
  tail call void @reverse_rotate_both(ptr noundef %1, ptr noundef %2, i32 noundef %10, i32 noundef %14) #2
  br label %27

17:                                               ; preds = %8
  %.not39 = icmp eq i32 %10, 0
  %18 = getelementptr inbounds i8, ptr %.0, i64 12
  %19 = load i32, ptr %18, align 4, !tbaa !15
  br i1 %.not39, label %.thread33, label %20

20:                                               ; preds = %17
  %21 = icmp sgt i32 %19, 0
  br i1 %21, label %22, label %.thread37

22:                                               ; preds = %20
  tail call void @rotate_both(ptr noundef %1, ptr noundef %2, i32 noundef %10, i32 noundef %19) #2
  br label %27

.thread33:                                        ; preds = %17
  %23 = icmp sgt i32 %19, -1
  br i1 %23, label %.thread34, label %.thread37

.thread34:                                        ; preds = %12, %.thread33
  %24 = phi i32 [ %19, %.thread33 ], [ %14, %12 ]
  tail call void @rotate(ptr noundef %2, ptr noundef nonnull @.str, i32 noundef %24) #2
  %25 = load i32, ptr %9, align 8, !tbaa !14
  tail call void @reverse_rotate(ptr noundef %1, ptr noundef nonnull @.str.1, i32 noundef %25) #2
  br label %27

.thread37:                                        ; preds = %20, %.thread33
  tail call void @reverse_rotate(ptr noundef %2, ptr noundef nonnull @.str.2, i32 noundef %19) #2
  %26 = load i32, ptr %9, align 8, !tbaa !14
  tail call void @rotate(ptr noundef %1, ptr noundef nonnull @.str.3, i32 noundef %26) #2
  br label %27

27:                                               ; preds = %22, %.thread37, %.thread34, %16
  ret void
}

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

declare void @rotate_both(ptr noundef, ptr noundef, i32 noundef, i32 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 16}
!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 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!10, !11, i64 8}
!15 = !{!10, !11, i64 12}


; Effective O3 passes: BDCEPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass