; LLVM IR from AdrianWR/push_swap :: src/checker (execute)

; 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.s_stack = type { i32, i32, ptr }

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

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

10:                                               ; preds = %44, %2
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = load ptr, ptr %11, align 8, !tbaa !5
  %13 = icmp ne ptr %12, null
  br i1 %13, label %14, label %47

14:                                               ; preds = %10
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = getelementptr inbounds ptr, ptr %15, i64 0
  %17 = load ptr, ptr %16, align 8, !tbaa !5
  %18 = load i8, ptr %17, align 1, !tbaa !12
  %19 = sext i8 %18 to i32
  %20 = icmp eq i32 %19, 115
  br i1 %20, label %21, label %26

21:                                               ; preds = %14
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = load ptr, ptr %22, align 8, !tbaa !5
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  call void @swap_stacks(ptr noundef %23, ptr noundef %24, ptr noundef %25)
  br label %44

26:                                               ; preds = %14
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = getelementptr inbounds ptr, ptr %27, i64 0
  %29 = load ptr, ptr %28, align 8, !tbaa !5
  %30 = load i8, ptr %29, align 1, !tbaa !12
  %31 = sext i8 %30 to i32
  %32 = icmp eq i32 %31, 112
  br i1 %32, label %33, label %38

33:                                               ; preds = %26
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  %35 = load ptr, ptr %34, align 8, !tbaa !5
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  call void @push_stacks(ptr noundef %35, ptr noundef %36, ptr noundef %37)
  br label %43

38:                                               ; preds = %26
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  %40 = load ptr, ptr %39, align 8, !tbaa !5
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  call void @rotate_stacks(ptr noundef %40, ptr noundef %41, ptr noundef %42)
  br label %43

43:                                               ; preds = %38, %33
  br label %44

44:                                               ; preds = %43, %21
  %45 = load ptr, ptr %3, align 8, !tbaa !5
  %46 = getelementptr inbounds ptr, ptr %45, i32 1
  store ptr %46, ptr %3, align 8, !tbaa !5
  br label %10, !llvm.loop !13

47:                                               ; preds = %10
  %48 = load ptr, ptr %4, align 8, !tbaa !5
  %49 = call zeroext i1 @is_sorted(ptr noundef %48)
  br i1 %49, label %50, label %55

50:                                               ; preds = %47
  %51 = load ptr, ptr %5, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.s_stack, ptr %51, i32 0, i32 0
  %53 = load i32, ptr %52, align 8, !tbaa !15
  %54 = icmp sgt i32 %53, -1
  br i1 %54, label %55, label %56

55:                                               ; preds = %50, %47
  call void @ft_putstr_fd(ptr noundef @.str, i32 noundef 1)
  br label %57

56:                                               ; preds = %50
  call void @ft_putstr_fd(ptr noundef @.str.1, i32 noundef 1)
  br label %57

57:                                               ; preds = %56, %55
  %58 = load ptr, ptr %5, align 8, !tbaa !5
  call void @free_stack(ptr noundef %58)
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret i32 0
}

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

declare ptr @initialize(i32 noundef) #2

; Function Attrs: nounwind uwtable
declare hidden void @swap_stacks(ptr noundef, ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
declare hidden void @push_stacks(ptr noundef, ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
declare hidden void @rotate_stacks(ptr noundef, ptr noundef, ptr noundef) #0

declare zeroext i1 @is_sorted(ptr noundef) #2

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

declare void @free_stack(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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 4}
!10 = !{!"s_stack", !11, i64 0, !11, i64 4, !6, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = !{!7, !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!10, !11, 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"

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

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @execute(ptr nocapture noundef readonly %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %1, i64 4
  %4 = load i32, ptr %3, align 4, !tbaa !5
  %5 = tail call ptr @initialize(i32 noundef %4) #2
  %6 = load ptr, ptr %0, align 8, !tbaa !11
  %.not19 = icmp eq ptr %6, null
  br i1 %.not19, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %2, %12
  %7 = phi ptr [ %14, %12 ], [ %6, %2 ]
  %.020 = phi ptr [ %13, %12 ], [ %0, %2 ]
  %8 = load i8, ptr %7, align 1, !tbaa !12
  switch i8 %8, label %11 [
    i8 115, label %9
    i8 112, label %10
  ]

9:                                                ; preds = %.lr.ph
  tail call void @swap_stacks(ptr noundef nonnull %7, ptr noundef %1, ptr noundef %5)
  br label %12

10:                                               ; preds = %.lr.ph
  tail call void @push_stacks(ptr noundef nonnull %7, ptr noundef %1, ptr noundef %5)
  br label %12

11:                                               ; preds = %.lr.ph
  tail call void @rotate_stacks(ptr noundef nonnull %7, ptr noundef %1, ptr noundef %5)
  br label %12

12:                                               ; preds = %10, %11, %9
  %13 = getelementptr inbounds i8, ptr %.020, i64 8
  %14 = load ptr, ptr %13, align 8, !tbaa !11
  %.not = icmp eq ptr %14, null
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !13

._crit_edge:                                      ; preds = %12, %2
  %15 = tail call zeroext i1 @is_sorted(ptr noundef %1) #2
  br i1 %15, label %16, label %19

16:                                               ; preds = %._crit_edge
  %17 = load i32, ptr %5, align 8, !tbaa !15
  %18 = icmp sgt i32 %17, -1
  %spec.select = select i1 %18, ptr @.str, ptr @.str.1
  br label %19

19:                                               ; preds = %16, %._crit_edge
  %.str.1.sink = phi ptr [ @.str, %._crit_edge ], [ %spec.select, %16 ]
  tail call void @ft_putstr_fd(ptr noundef nonnull %.str.1.sink, i32 noundef 1) #2
  tail call void @free_stack(ptr noundef %5) #2
  ret i32 0
}

declare ptr @initialize(i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden void @swap_stacks(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden void @push_stacks(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden void @rotate_stacks(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

declare zeroext i1 @is_sorted(ptr noundef) local_unnamed_addr #1

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

declare void @free_stack(ptr 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, !7, i64 4}
!6 = !{!"s_stack", !7, i64 0, !7, i64 4, !10, i64 8}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!10, !10, i64 0}
!12 = !{!8, !8, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!6, !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass