; LLVM IR from Dev-XYS/Algorithms :: Skip-List.ll (Z5debugv)

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

@head = external dso_local global [20 x ptr], align 16
@.str = external hidden unnamed_addr constant [9 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [2 x i8], align 1

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5debugv() #1 {
  %1 = alloca i32, align 4
  %2 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #3
  store i32 5, ptr %1, align 4, !tbaa !5
  br label %3

3:                                                ; preds = %30, %0
  %4 = load i32, ptr %1, align 4, !tbaa !5
  %5 = icmp sge i32 %4, 0
  br i1 %5, label %7, label %6

6:                                                ; preds = %3
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #3
  br label %33

7:                                                ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #3
  %8 = load i32, ptr %1, align 4, !tbaa !5
  %9 = sext i32 %8 to i64
  %10 = getelementptr inbounds [20 x ptr], ptr @head, i64 0, i64 %9
  %11 = load ptr, ptr %10, align 8, !tbaa !9
  store ptr %11, ptr %2, align 8, !tbaa !9
  %12 = load i32, ptr %1, align 4, !tbaa !5
  %13 = call i32 (ptr, ...) @printf(ptr noundef @.str, i32 noundef %12)
  br label %14

14:                                               ; preds = %17, %7
  %15 = load ptr, ptr %2, align 8, !tbaa !9
  %16 = icmp ne ptr %15, null
  br i1 %16, label %17, label %28

17:                                               ; preds = %14
  %18 = load ptr, ptr %2, align 8, !tbaa !9
  %19 = getelementptr inbounds %struct.node, ptr %18, i32 0, i32 0
  %20 = load i32, ptr %19, align 8, !tbaa !11
  %21 = load ptr, ptr %2, align 8, !tbaa !9
  %22 = getelementptr inbounds %struct.node, ptr %21, i32 0, i32 1
  %23 = load i32, ptr %22, align 4, !tbaa !13
  %24 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %20, i32 noundef %23)
  %25 = load ptr, ptr %2, align 8, !tbaa !9
  %26 = getelementptr inbounds %struct.node, ptr %25, i32 0, i32 2
  %27 = load ptr, ptr %26, align 8, !tbaa !14
  store ptr %27, ptr %2, align 8, !tbaa !9
  br label %14, !llvm.loop !15

28:                                               ; preds = %14
  %29 = call i32 (ptr, ...) @printf(ptr noundef @.str.2)
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #3
  br label %30

30:                                               ; preds = %28
  %31 = load i32, ptr %1, align 4, !tbaa !5
  %32 = add nsw i32 %31, -1
  store i32 %32, ptr %1, align 4, !tbaa !5
  br label %3, !llvm.loop !17

33:                                               ; preds = %6
  ret void
}

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

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


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

@head = external dso_local local_unnamed_addr global [20 x ptr], align 16
@.str = external hidden unnamed_addr constant [9 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: mustprogress nofree nounwind uwtable
define dso_local void @_Z5debugv() local_unnamed_addr #0 {
  %1 = load ptr, ptr getelementptr inbounds (i8, ptr @head, i64 40), align 8, !tbaa !5
  %2 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef 5)
  %.not8 = icmp eq ptr %1, null
  br i1 %.not8, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %0, %.lr.ph
  %.09 = phi ptr [ %8, %.lr.ph ], [ %1, %0 ]
  %3 = load i32, ptr %.09, align 8, !tbaa !9
  %4 = getelementptr inbounds i8, ptr %.09, i64 4
  %5 = load i32, ptr %4, align 4, !tbaa !12
  %6 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %3, i32 noundef %5)
  %7 = getelementptr inbounds i8, ptr %.09, i64 8
  %8 = load ptr, ptr %7, align 8, !tbaa !13
  %.not = icmp eq ptr %8, null
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !14

._crit_edge:                                      ; preds = %.lr.ph, %0
  %9 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2)
  %10 = load ptr, ptr getelementptr inbounds (i8, ptr @head, i64 32), align 16, !tbaa !5
  %11 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef 4)
  %.not8.1 = icmp eq ptr %10, null
  br i1 %.not8.1, label %._crit_edge.1, label %.lr.ph.1

.lr.ph.1:                                         ; preds = %._crit_edge, %.lr.ph.1
  %.09.1 = phi ptr [ %17, %.lr.ph.1 ], [ %10, %._crit_edge ]
  %12 = load i32, ptr %.09.1, align 8, !tbaa !9
  %13 = getelementptr inbounds i8, ptr %.09.1, i64 4
  %14 = load i32, ptr %13, align 4, !tbaa !12
  %15 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %12, i32 noundef %14)
  %16 = getelementptr inbounds i8, ptr %.09.1, i64 8
  %17 = load ptr, ptr %16, align 8, !tbaa !13
  %.not.1 = icmp eq ptr %17, null
  br i1 %.not.1, label %._crit_edge.1, label %.lr.ph.1, !llvm.loop !14

._crit_edge.1:                                    ; preds = %.lr.ph.1, %._crit_edge
  %18 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2)
  %19 = load ptr, ptr getelementptr inbounds (i8, ptr @head, i64 24), align 8, !tbaa !5
  %20 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef 3)
  %.not8.2 = icmp eq ptr %19, null
  br i1 %.not8.2, label %._crit_edge.2, label %.lr.ph.2

.lr.ph.2:                                         ; preds = %._crit_edge.1, %.lr.ph.2
  %.09.2 = phi ptr [ %26, %.lr.ph.2 ], [ %19, %._crit_edge.1 ]
  %21 = load i32, ptr %.09.2, align 8, !tbaa !9
  %22 = getelementptr inbounds i8, ptr %.09.2, i64 4
  %23 = load i32, ptr %22, align 4, !tbaa !12
  %24 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %21, i32 noundef %23)
  %25 = getelementptr inbounds i8, ptr %.09.2, i64 8
  %26 = load ptr, ptr %25, align 8, !tbaa !13
  %.not.2 = icmp eq ptr %26, null
  br i1 %.not.2, label %._crit_edge.2, label %.lr.ph.2, !llvm.loop !14

._crit_edge.2:                                    ; preds = %.lr.ph.2, %._crit_edge.1
  %27 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2)
  %28 = load ptr, ptr getelementptr inbounds (i8, ptr @head, i64 16), align 16, !tbaa !5
  %29 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef 2)
  %.not8.3 = icmp eq ptr %28, null
  br i1 %.not8.3, label %._crit_edge.3, label %.lr.ph.3

.lr.ph.3:                                         ; preds = %._crit_edge.2, %.lr.ph.3
  %.09.3 = phi ptr [ %35, %.lr.ph.3 ], [ %28, %._crit_edge.2 ]
  %30 = load i32, ptr %.09.3, align 8, !tbaa !9
  %31 = getelementptr inbounds i8, ptr %.09.3, i64 4
  %32 = load i32, ptr %31, align 4, !tbaa !12
  %33 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %30, i32 noundef %32)
  %34 = getelementptr inbounds i8, ptr %.09.3, i64 8
  %35 = load ptr, ptr %34, align 8, !tbaa !13
  %.not.3 = icmp eq ptr %35, null
  br i1 %.not.3, label %._crit_edge.3, label %.lr.ph.3, !llvm.loop !14

._crit_edge.3:                                    ; preds = %.lr.ph.3, %._crit_edge.2
  %36 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2)
  %37 = load ptr, ptr getelementptr inbounds (i8, ptr @head, i64 8), align 8, !tbaa !5
  %38 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef 1)
  %.not8.4 = icmp eq ptr %37, null
  br i1 %.not8.4, label %._crit_edge.4, label %.lr.ph.4

.lr.ph.4:                                         ; preds = %._crit_edge.3, %.lr.ph.4
  %.09.4 = phi ptr [ %44, %.lr.ph.4 ], [ %37, %._crit_edge.3 ]
  %39 = load i32, ptr %.09.4, align 8, !tbaa !9
  %40 = getelementptr inbounds i8, ptr %.09.4, i64 4
  %41 = load i32, ptr %40, align 4, !tbaa !12
  %42 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %39, i32 noundef %41)
  %43 = getelementptr inbounds i8, ptr %.09.4, i64 8
  %44 = load ptr, ptr %43, align 8, !tbaa !13
  %.not.4 = icmp eq ptr %44, null
  br i1 %.not.4, label %._crit_edge.4, label %.lr.ph.4, !llvm.loop !14

._crit_edge.4:                                    ; preds = %.lr.ph.4, %._crit_edge.3
  %45 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2)
  %46 = load ptr, ptr @head, align 16, !tbaa !5
  %47 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef 0)
  %.not8.5 = icmp eq ptr %46, null
  br i1 %.not8.5, label %._crit_edge.5, label %.lr.ph.5

.lr.ph.5:                                         ; preds = %._crit_edge.4, %.lr.ph.5
  %.09.5 = phi ptr [ %53, %.lr.ph.5 ], [ %46, %._crit_edge.4 ]
  %48 = load i32, ptr %.09.5, align 8, !tbaa !9
  %49 = getelementptr inbounds i8, ptr %.09.5, i64 4
  %50 = load i32, ptr %49, align 4, !tbaa !12
  %51 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %48, i32 noundef %50)
  %52 = getelementptr inbounds i8, ptr %.09.5, i64 8
  %53 = load ptr, ptr %52, align 8, !tbaa !13
  %.not.5 = icmp eq ptr %53, null
  br i1 %.not.5, label %._crit_edge.5, label %.lr.ph.5, !llvm.loop !14

._crit_edge.5:                                    ; preds = %.lr.ph.5, %._crit_edge.4
  %54 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2)
  ret void
}

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

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

!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++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"_ZTS4node", !11, i64 0, !11, i64 4, !6, i64 8, !6, i64 16}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 4}
!13 = !{!10, !6, i64 8}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


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