; LLVM IR from freddiev4/dailyprogrammerchallenges :: Intermediate Challenges/Challenge 0219 Intermediate - To-do list (Part 2) (list)

; 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 { ptr, ptr, ptr, ptr }

@first = external dso_local global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.20 = external hidden unnamed_addr constant [19 x i8], align 1
@.str.21 = external hidden unnamed_addr constant [32 x i8], align 1
@.str.27 = external hidden unnamed_addr constant [20 x i8], align 1
@.str.30 = external hidden unnamed_addr constant [26 x i8], align 1
@.str.31 = external hidden unnamed_addr constant [34 x i8], align 1
@.str.32 = external hidden unnamed_addr constant [7 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: inlinehint nounwind uwtable
declare i32 @getchar() #2

; Function Attrs: nounwind uwtable
define dso_local void @view_list() #3 {
  %1 = alloca i8, align 1
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 1, ptr %1) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #5
  %5 = load ptr, ptr @first, align 8, !tbaa !5
  %6 = icmp eq ptr %5, null
  br i1 %6, label %7, label %9

7:                                                ; preds = %0
  %8 = call i32 (ptr, ...) @printf(ptr noundef @.str.30)
  store i32 1, ptr %4, align 4
  br label %75

9:                                                ; preds = %0
  %10 = call i32 (ptr, ...) @printf(ptr noundef @.str.31)
  %11 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.2, ptr noundef %1)
  br label %12

12:                                               ; preds = %15, %9
  %13 = call i32 @getchar()
  %14 = icmp ne i32 %13, 10
  br i1 %14, label %15, label %16

15:                                               ; preds = %12
  br label %12, !llvm.loop !9

16:                                               ; preds = %12
  %17 = load i8, ptr %1, align 1, !tbaa !11
  %18 = sext i8 %17 to i32
  %19 = icmp eq i32 %18, 97
  br i1 %19, label %20, label %35

20:                                               ; preds = %16
  %21 = load ptr, ptr @first, align 8, !tbaa !5
  store ptr %21, ptr %2, align 8, !tbaa !5
  br label %22

22:                                               ; preds = %30, %20
  %23 = load ptr, ptr %2, align 8, !tbaa !5
  %24 = icmp ne ptr %23, null
  br i1 %24, label %25, label %34

25:                                               ; preds = %22
  %26 = load ptr, ptr %2, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.node, ptr %26, i32 0, i32 0
  %28 = load ptr, ptr %27, align 8, !tbaa !12
  %29 = call i32 (ptr, ...) @printf(ptr noundef @.str.32, ptr noundef %28)
  br label %30

30:                                               ; preds = %25
  %31 = load ptr, ptr %2, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.node, ptr %31, i32 0, i32 2
  %33 = load ptr, ptr %32, align 8, !tbaa !14
  store ptr %33, ptr %2, align 8, !tbaa !5
  br label %22, !llvm.loop !15

34:                                               ; preds = %22
  br label %74

35:                                               ; preds = %16
  %36 = load i8, ptr %1, align 1, !tbaa !11
  %37 = sext i8 %36 to i32
  %38 = icmp eq i32 %37, 99
  br i1 %38, label %39, label %71

39:                                               ; preds = %35
  %40 = call i32 (ptr, ...) @printf(ptr noundef @.str.20)
  %41 = call ptr @search(i32 noundef 0)
  store ptr %41, ptr %3, align 8, !tbaa !5
  %42 = icmp ne ptr %41, null
  br i1 %42, label %43, label %68

43:                                               ; preds = %39
  %44 = load ptr, ptr @first, align 8, !tbaa !5
  store ptr %44, ptr %2, align 8, !tbaa !5
  br label %45

45:                                               ; preds = %63, %43
  %46 = load ptr, ptr %2, align 8, !tbaa !5
  %47 = icmp ne ptr %46, null
  br i1 %47, label %48, label %67

48:                                               ; preds = %45
  %49 = load ptr, ptr %3, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.node, ptr %49, i32 0, i32 1
  %51 = load ptr, ptr %50, align 8, !tbaa !16
  %52 = load ptr, ptr %2, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.node, ptr %52, i32 0, i32 1
  %54 = load ptr, ptr %53, align 8, !tbaa !16
  %55 = call i32 @strcmp(ptr noundef %51, ptr noundef %54) #6
  %56 = icmp eq i32 %55, 0
  br i1 %56, label %57, label %62

57:                                               ; preds = %48
  %58 = load ptr, ptr %2, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.node, ptr %58, i32 0, i32 0
  %60 = load ptr, ptr %59, align 8, !tbaa !12
  %61 = call i32 (ptr, ...) @printf(ptr noundef @.str.32, ptr noundef %60)
  br label %62

62:                                               ; preds = %57, %48
  br label %63

63:                                               ; preds = %62
  %64 = load ptr, ptr %2, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.node, ptr %64, i32 0, i32 2
  %66 = load ptr, ptr %65, align 8, !tbaa !14
  store ptr %66, ptr %2, align 8, !tbaa !5
  br label %45, !llvm.loop !17

67:                                               ; preds = %45
  br label %70

68:                                               ; preds = %39
  %69 = call i32 (ptr, ...) @printf(ptr noundef @.str.27)
  br label %70

70:                                               ; preds = %68, %67
  br label %73

71:                                               ; preds = %35
  %72 = call i32 (ptr, ...) @printf(ptr noundef @.str.21)
  br label %73

73:                                               ; preds = %71, %70
  br label %74

74:                                               ; preds = %73, %34
  store i32 0, ptr %4, align 4
  br label %75

75:                                               ; preds = %74, %7
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #5
  call void @llvm.lifetime.end.p0(i64 1, ptr %1) #5
  %76 = load i32, ptr %4, align 4
  switch i32 %76, label %78 [
    i32 0, label %77
    i32 1, label %77
  ]

77:                                               ; preds = %75, %75
  ret void

78:                                               ; preds = %75
  unreachable
}

; 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 @search(i32 noundef) #3

; Function Attrs: nounwind willreturn memory(read)
declare i32 @strcmp(ptr noundef, ptr noundef) #4

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 = { inlinehint 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 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 #4 = { nounwind willreturn memory(read) "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 #5 = { nounwind }
attributes #6 = { nounwind willreturn memory(read) }

!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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !6, i64 0}
!13 = !{!"node", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!14 = !{!13, !6, i64 16}
!15 = distinct !{!15, !10}
!16 = !{!13, !6, i64 8}
!17 = distinct !{!17, !10}


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

@first = external dso_local local_unnamed_addr global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.20 = external hidden unnamed_addr constant [19 x i8], align 1
@.str.21 = external hidden unnamed_addr constant [32 x i8], align 1
@.str.27 = external hidden unnamed_addr constant [20 x i8], align 1
@.str.30 = external hidden unnamed_addr constant [26 x i8], align 1
@.str.31 = external hidden unnamed_addr constant [34 x i8], align 1
@.str.32 = external hidden unnamed_addr constant [7 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: inlinehint nofree nounwind uwtable
declare noundef i32 @getchar() local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local void @view_list() local_unnamed_addr #3 {
  %1 = alloca i8, align 1
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %1) #5
  %2 = load ptr, ptr @first, align 8, !tbaa !5
  %3 = icmp eq ptr %2, null
  br i1 %3, label %4, label %6

4:                                                ; preds = %0
  %5 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.30)
  br label %.loopexit

6:                                                ; preds = %0
  %7 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.31)
  %8 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.2, ptr noundef nonnull %1)
  br label %9

9:                                                ; preds = %9, %6
  %10 = call i32 @getchar()
  %.not = icmp eq i32 %10, 10
  br i1 %.not, label %11, label %9, !llvm.loop !9

11:                                               ; preds = %9
  %12 = load i8, ptr %1, align 1, !tbaa !11
  switch i8 %12, label %33 [
    i8 97, label %.preheader
    i8 99, label %16
  ]

.preheader:                                       ; preds = %11
  %.018 = load ptr, ptr @first, align 8, !tbaa !5
  %.not1219 = icmp eq ptr %.018, null
  br i1 %.not1219, label %.loopexit, label %.lr.ph21

.lr.ph21:                                         ; preds = %.preheader, %.lr.ph21
  %.020 = phi ptr [ %.0, %.lr.ph21 ], [ %.018, %.preheader ]
  %13 = load ptr, ptr %.020, align 8, !tbaa !12
  %14 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.32, ptr noundef %13)
  %15 = getelementptr inbounds i8, ptr %.020, i64 16
  %.0 = load ptr, ptr %15, align 8, !tbaa !5
  %.not12 = icmp eq ptr %.0, null
  br i1 %.not12, label %.loopexit, label %.lr.ph21, !llvm.loop !14

16:                                               ; preds = %11
  %17 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.20)
  %18 = call ptr @search(i32 noundef 0)
  %.not10 = icmp eq ptr %18, null
  br i1 %.not10, label %31, label %.preheader13

.preheader13:                                     ; preds = %16
  %.115 = load ptr, ptr @first, align 8, !tbaa !5
  %.not1116 = icmp eq ptr %.115, null
  br i1 %.not1116, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader13
  %19 = getelementptr inbounds i8, ptr %18, i64 8
  br label %20

20:                                               ; preds = %.lr.ph, %29
  %.117 = phi ptr [ %.115, %.lr.ph ], [ %.1, %29 ]
  %21 = load ptr, ptr %19, align 8, !tbaa !15
  %22 = getelementptr inbounds i8, ptr %.117, i64 8
  %23 = load ptr, ptr %22, align 8, !tbaa !15
  %24 = call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %21, ptr noundef nonnull dereferenceable(1) %23) #6
  %25 = icmp eq i32 %24, 0
  br i1 %25, label %26, label %29

26:                                               ; preds = %20
  %27 = load ptr, ptr %.117, align 8, !tbaa !12
  %28 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.32, ptr noundef %27)
  br label %29

29:                                               ; preds = %20, %26
  %30 = getelementptr inbounds i8, ptr %.117, i64 16
  %.1 = load ptr, ptr %30, align 8, !tbaa !5
  %.not11 = icmp eq ptr %.1, null
  br i1 %.not11, label %.loopexit, label %20, !llvm.loop !16

31:                                               ; preds = %16
  %32 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.27)
  br label %.loopexit

33:                                               ; preds = %11
  %34 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.21)
  br label %.loopexit

.loopexit:                                        ; preds = %29, %.lr.ph21, %.preheader13, %.preheader, %31, %33, %4
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %1) #5
  ret void
}

; 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 @search(i32 noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i32 @strcmp(ptr nocapture noundef, ptr nocapture noundef) local_unnamed_addr #4

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 = { inlinehint 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 #3 = { 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 #4 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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 #5 = { nounwind }
attributes #6 = { nounwind willreturn memory(read) }

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


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