; LLVM IR from JessonYue/LeetCodeLearning :: Array/caiweixiong/c (homework_003)

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

@.str.6 = external hidden unnamed_addr constant [63 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [63 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [19 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [19 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [19 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

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

declare i32 @__isoc99_scanf(ptr noundef, ...) #1

; 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
define dso_local void @homework_003_002() #2 {
  %1 = alloca i32, align 4
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #3
  store i32 0, ptr %1, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #3
  store ptr null, ptr %2, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  store ptr null, ptr %3, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %5 = call i32 (ptr, ...) @printf(ptr noundef @.str.6)
  br label %6

6:                                                ; preds = %15, %0
  %7 = load i32, ptr %1, align 4, !tbaa !5
  %8 = icmp slt i32 %7, 10
  br i1 %8, label %9, label %16

9:                                                ; preds = %6
  %10 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.7, ptr noundef %1)
  %11 = load i32, ptr %1, align 4, !tbaa !5
  %12 = icmp slt i32 %11, 10
  br i1 %12, label %13, label %15

13:                                               ; preds = %9
  %14 = load i32, ptr %1, align 4, !tbaa !5
  call void @listInsert(ptr noundef %2, i32 noundef %14)
  br label %15

15:                                               ; preds = %13, %9
  br label %6, !llvm.loop !11

16:                                               ; preds = %6
  %17 = call i32 (ptr, ...) @printf(ptr noundef @.str.8)
  store i32 0, ptr %1, align 4, !tbaa !5
  br label %18

18:                                               ; preds = %27, %16
  %19 = load i32, ptr %1, align 4, !tbaa !5
  %20 = icmp slt i32 %19, 10
  br i1 %20, label %21, label %28

21:                                               ; preds = %18
  %22 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.7, ptr noundef %1)
  %23 = load i32, ptr %1, align 4, !tbaa !5
  %24 = icmp slt i32 %23, 10
  br i1 %24, label %25, label %27

25:                                               ; preds = %21
  %26 = load i32, ptr %1, align 4, !tbaa !5
  call void @listInsert(ptr noundef %3, i32 noundef %26)
  br label %27

27:                                               ; preds = %25, %21
  br label %18, !llvm.loop !13

28:                                               ; preds = %18
  %29 = call i32 (ptr, ...) @printf(ptr noundef @.str.9)
  %30 = load ptr, ptr %2, align 8, !tbaa !9
  call void @displayList(ptr noundef %30)
  %31 = call i32 (ptr, ...) @printf(ptr noundef @.str.10)
  %32 = load ptr, ptr %3, align 8, !tbaa !9
  call void @displayList(ptr noundef %32)
  %33 = load ptr, ptr %2, align 8, !tbaa !9
  %34 = load ptr, ptr %3, align 8, !tbaa !9
  %35 = call ptr @addTwoNumbers(ptr noundef %33, ptr noundef %34)
  store ptr %35, ptr %4, align 8, !tbaa !9
  %36 = call i32 (ptr, ...) @printf(ptr noundef @.str.11)
  %37 = load ptr, ptr %4, align 8, !tbaa !9
  call void @displayList(ptr noundef %37)
  call void @destroyList(ptr noundef %2)
  call void @destroyList(ptr noundef %3)
  call void @destroyList(ptr noundef %4)
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #3
  ret void
}

; Function Attrs: nounwind uwtable
declare dso_local void @listInsert(ptr noundef, i32 noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local void @displayList(ptr noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local ptr @addTwoNumbers(ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local void @destroyList(ptr noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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 #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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !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.6 = external hidden unnamed_addr constant [63 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [63 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [19 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [19 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [19 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: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #1

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

; 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
define dso_local void @homework_003_002() local_unnamed_addr #2 {
.lr.ph.preheader:
  %0 = alloca i32, align 4
  %1 = alloca ptr, align 8
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %0) #3
  store i32 0, ptr %0, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #3
  store ptr null, ptr %1, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #3
  store ptr null, ptr %2, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #3
  %4 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.6)
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %8
  %5 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.7, ptr noundef nonnull %0)
  %6 = load i32, ptr %0, align 4, !tbaa !5
  %7 = icmp slt i32 %6, 10
  br i1 %7, label %8, label %._crit_edge

8:                                                ; preds = %.lr.ph
  call void @listInsert(ptr noundef nonnull %1, i32 noundef %6)
  %.pre = load i32, ptr %0, align 4, !tbaa !5
  %9 = icmp slt i32 %.pre, 10
  br i1 %9, label %.lr.ph, label %._crit_edge, !llvm.loop !11

._crit_edge:                                      ; preds = %.lr.ph, %8
  %10 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.8)
  store i32 0, ptr %0, align 4, !tbaa !5
  br label %11

11:                                               ; preds = %._crit_edge, %15
  %12 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.7, ptr noundef nonnull %0)
  %13 = load i32, ptr %0, align 4, !tbaa !5
  %14 = icmp slt i32 %13, 10
  br i1 %14, label %15, label %.thread3

15:                                               ; preds = %11
  call void @listInsert(ptr noundef nonnull %2, i32 noundef %13)
  %.pr.pre = load i32, ptr %0, align 4, !tbaa !5
  %16 = icmp slt i32 %.pr.pre, 10
  br i1 %16, label %11, label %.thread3, !llvm.loop !13

.thread3:                                         ; preds = %11, %15
  %17 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.9)
  %18 = load ptr, ptr %1, align 8, !tbaa !9
  call void @displayList(ptr noundef %18)
  %19 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.10)
  %20 = load ptr, ptr %2, align 8, !tbaa !9
  call void @displayList(ptr noundef %20)
  %21 = load ptr, ptr %1, align 8, !tbaa !9
  %22 = load ptr, ptr %2, align 8, !tbaa !9
  %23 = call ptr @addTwoNumbers(ptr noundef %21, ptr noundef %22)
  store ptr %23, ptr %3, align 8, !tbaa !9
  %24 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.11)
  call void @displayList(ptr noundef %23)
  call void @destroyList(ptr noundef nonnull %1)
  call void @destroyList(ptr noundef nonnull %2)
  call void @destroyList(ptr noundef nonnull %3)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %0) #3
  ret void
}

; Function Attrs: nounwind uwtable
declare dso_local void @listInsert(ptr noundef, i32 noundef) local_unnamed_addr #2

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

; Function Attrs: nounwind uwtable
declare dso_local ptr @addTwoNumbers(ptr noundef, ptr noundef) local_unnamed_addr #2

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
attributes #2 = { 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 #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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,SCCPPass,SimplifyCFGPass,TailCallElimPass