; LLVM IR from 6leetcode/6leetcode :: questions/Algorithms/0061. Rotate List (Solution)

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

@.str = external hidden unnamed_addr constant [12 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [6 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: nounwind uwtable
declare dso_local ptr @rotateRight(ptr noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @free_node(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @main(i32 noundef %0, ptr noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca %struct.ListNode, align 8
  %7 = alloca %struct.ListNode, align 8
  %8 = alloca %struct.ListNode, align 8
  %9 = alloca %struct.ListNode, align 8
  %10 = alloca %struct.ListNode, align 8
  %11 = alloca ptr, align 8
  %12 = alloca %struct.ListNode, align 8
  %13 = alloca ptr, align 8
  store i32 0, ptr %3, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 16, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 16, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 16, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 16, ptr %9) #4
  call void @llvm.lifetime.start.p0(i64 16, ptr %10) #4
  %14 = getelementptr inbounds %struct.ListNode, ptr %6, i32 0, i32 0
  store i32 1, ptr %14, align 8, !tbaa !11
  %15 = getelementptr inbounds %struct.ListNode, ptr %7, i32 0, i32 0
  store i32 2, ptr %15, align 8, !tbaa !11
  %16 = getelementptr inbounds %struct.ListNode, ptr %8, i32 0, i32 0
  store i32 3, ptr %16, align 8, !tbaa !11
  %17 = getelementptr inbounds %struct.ListNode, ptr %9, i32 0, i32 0
  store i32 4, ptr %17, align 8, !tbaa !11
  %18 = getelementptr inbounds %struct.ListNode, ptr %10, i32 0, i32 0
  store i32 5, ptr %18, align 8, !tbaa !11
  %19 = getelementptr inbounds %struct.ListNode, ptr %6, i32 0, i32 1
  store ptr %7, ptr %19, align 8, !tbaa !13
  %20 = getelementptr inbounds %struct.ListNode, ptr %7, i32 0, i32 1
  store ptr %8, ptr %20, align 8, !tbaa !13
  %21 = getelementptr inbounds %struct.ListNode, ptr %8, i32 0, i32 1
  store ptr %9, ptr %21, align 8, !tbaa !13
  %22 = getelementptr inbounds %struct.ListNode, ptr %9, i32 0, i32 1
  store ptr %10, ptr %22, align 8, !tbaa !13
  %23 = getelementptr inbounds %struct.ListNode, ptr %10, i32 0, i32 1
  store ptr null, ptr %23, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %24 = call ptr @rotateRight(ptr noundef %6, i32 noundef 3)
  store ptr %24, ptr %11, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 16, ptr %12) #4
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %12, ptr align 8 %6, i64 16, i1 false), !tbaa.struct !14
  %25 = getelementptr inbounds %struct.ListNode, ptr %12, i32 0, i32 0
  %26 = load i32, ptr %25, align 8, !tbaa !11
  %27 = call i32 (ptr, ...) @printf(ptr noundef @.str, i32 noundef %26)
  %28 = getelementptr inbounds %struct.ListNode, ptr %12, i32 0, i32 1
  %29 = load ptr, ptr %28, align 8, !tbaa !13
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %12, ptr align 8 %29, i64 16, i1 false), !tbaa.struct !14
  br label %30

30:                                               ; preds = %39, %2
  br label %31

31:                                               ; preds = %30
  %32 = getelementptr inbounds %struct.ListNode, ptr %12, i32 0, i32 0
  %33 = load i32, ptr %32, align 8, !tbaa !11
  %34 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %33)
  %35 = getelementptr inbounds %struct.ListNode, ptr %12, i32 0, i32 1
  %36 = load ptr, ptr %35, align 8, !tbaa !13
  %37 = icmp eq ptr %36, null
  br i1 %37, label %38, label %39

38:                                               ; preds = %31
  br label %42

39:                                               ; preds = %31
  %40 = getelementptr inbounds %struct.ListNode, ptr %12, i32 0, i32 1
  %41 = load ptr, ptr %40, align 8, !tbaa !13
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %12, ptr align 8 %41, i64 16, i1 false), !tbaa.struct !14
  br label %30

42:                                               ; preds = %38
  %43 = call i32 (ptr, ...) @printf(ptr noundef @.str.2)
  %44 = load ptr, ptr %11, align 8, !tbaa !9
  %45 = getelementptr inbounds %struct.ListNode, ptr %44, i32 0, i32 0
  %46 = load i32, ptr %45, align 8, !tbaa !11
  %47 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, i32 noundef %46)
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  %48 = load ptr, ptr %11, align 8, !tbaa !9
  %49 = getelementptr inbounds %struct.ListNode, ptr %48, i32 0, i32 1
  %50 = load ptr, ptr %49, align 8, !tbaa !13
  store ptr %50, ptr %13, align 8, !tbaa !9
  %51 = load ptr, ptr %13, align 8, !tbaa !9
  %52 = icmp eq ptr %51, null
  br i1 %52, label %53, label %55

53:                                               ; preds = %42
  %54 = call i32 (ptr, ...) @printf(ptr noundef @.str.4)
  br label %72

55:                                               ; preds = %42
  br label %56

56:                                               ; preds = %67, %55
  br label %57

57:                                               ; preds = %56
  %58 = load ptr, ptr %13, align 8, !tbaa !9
  %59 = getelementptr inbounds %struct.ListNode, ptr %58, i32 0, i32 0
  %60 = load i32, ptr %59, align 8, !tbaa !11
  %61 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %60)
  %62 = load ptr, ptr %13, align 8, !tbaa !9
  %63 = getelementptr inbounds %struct.ListNode, ptr %62, i32 0, i32 1
  %64 = load ptr, ptr %63, align 8, !tbaa !13
  %65 = icmp eq ptr %64, null
  br i1 %65, label %66, label %67

66:                                               ; preds = %57
  br label %71

67:                                               ; preds = %57
  %68 = load ptr, ptr %13, align 8, !tbaa !9
  %69 = getelementptr inbounds %struct.ListNode, ptr %68, i32 0, i32 1
  %70 = load ptr, ptr %69, align 8, !tbaa !13
  store ptr %70, ptr %13, align 8, !tbaa !9
  br label %56

71:                                               ; preds = %66
  br label %72

72:                                               ; preds = %71, %53
  %73 = load ptr, ptr %11, align 8, !tbaa !9
  call void @free_node(ptr noundef %73)
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr %6) #4
  ret i32 0
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { "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 #4 = { 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 0}
!12 = !{!"ListNode", !6, i64 0, !10, i64 8}
!13 = !{!12, !10, i64 8}
!14 = !{i64 0, i64 4, !5, i64 8, i64 8, !9}


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

%struct.ListNode = type { i32, ptr }

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

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

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

; Function Attrs: nounwind uwtable
declare dso_local ptr @rotateRight(ptr noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @free_node(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main(i32 noundef %0, ptr nocapture noundef readnone %1) local_unnamed_addr #1 {
  %3 = alloca %struct.ListNode, align 8
  %4 = alloca %struct.ListNode, align 8
  %5 = alloca %struct.ListNode, align 8
  %6 = alloca %struct.ListNode, align 8
  %7 = alloca %struct.ListNode, align 8
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %3) #3
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %4) #3
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %5) #3
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %6) #3
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %7) #3
  store i32 1, ptr %3, align 8, !tbaa !5
  store i32 2, ptr %4, align 8, !tbaa !5
  store i32 3, ptr %5, align 8, !tbaa !5
  store i32 4, ptr %6, align 8, !tbaa !5
  store i32 5, ptr %7, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %3, i64 8
  store ptr %4, ptr %8, align 8, !tbaa !11
  %9 = getelementptr inbounds i8, ptr %4, i64 8
  store ptr %5, ptr %9, align 8, !tbaa !11
  %10 = getelementptr inbounds i8, ptr %5, i64 8
  store ptr %6, ptr %10, align 8, !tbaa !11
  %11 = getelementptr inbounds i8, ptr %6, i64 8
  store ptr %7, ptr %11, align 8, !tbaa !11
  %12 = getelementptr inbounds i8, ptr %7, i64 8
  store ptr null, ptr %12, align 8, !tbaa !11
  %13 = call ptr @rotateRight(ptr noundef nonnull %3, i32 noundef 3)
  %.sroa.0.0.copyload = load i32, ptr %3, align 8, !tbaa !12
  %.sroa.711.0.copyload = load ptr, ptr %8, align 8, !tbaa !13
  %14 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %.sroa.0.0.copyload)
  br label %15

15:                                               ; preds = %15, %2
  %.sroa.711.0.copyload.pn = phi ptr [ %.sroa.711.0.copyload, %2 ], [ %.sroa.711.0, %15 ]
  %.sroa.0.0 = load i32, ptr %.sroa.711.0.copyload.pn, align 8, !tbaa !12
  %.sroa.711.0.in = getelementptr inbounds i8, ptr %.sroa.711.0.copyload.pn, i64 8
  %.sroa.711.0 = load ptr, ptr %.sroa.711.0.in, align 8, !tbaa !13
  %16 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %.sroa.0.0)
  %17 = icmp eq ptr %.sroa.711.0, null
  br i1 %17, label %18, label %15

18:                                               ; preds = %15
  %19 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2)
  %20 = load i32, ptr %13, align 8, !tbaa !5
  %21 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i32 noundef %20)
  %22 = getelementptr inbounds i8, ptr %13, i64 8
  %23 = load ptr, ptr %22, align 8, !tbaa !11
  %24 = icmp eq ptr %23, null
  br i1 %24, label %25, label %.preheader

25:                                               ; preds = %18
  %26 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4)
  br label %.loopexit

.preheader:                                       ; preds = %18, %.preheader
  %.0 = phi ptr [ %30, %.preheader ], [ %23, %18 ]
  %27 = load i32, ptr %.0, align 8, !tbaa !5
  %28 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %27)
  %29 = getelementptr inbounds i8, ptr %.0, i64 8
  %30 = load ptr, ptr %29, align 8, !tbaa !11
  %31 = icmp eq ptr %30, null
  br i1 %31, label %.loopexit, label %.preheader

.loopexit:                                        ; preds = %.preheader, %25
  call void @free_node(ptr noundef nonnull %13)
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %7) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %6) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %5) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %4) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %3) #3
  ret i32 0
}

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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, !7, i64 0}
!6 = !{!"ListNode", !7, i64 0, !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 = !{!6, !10, i64 8}
!12 = !{!7, !7, i64 0}
!13 = !{!10, !10, i64 0}


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