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

; 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 = external hidden unnamed_addr constant [37 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [24 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [1 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [14 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i8, align 1
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 1, ptr %2) #4
  %3 = call i32 (ptr, ...) @printf(ptr noundef @.str)
  call void @print_help()
  call void @read_from_file()
  br label %4

4:                                                ; preds = %23, %0
  %5 = call i32 (ptr, ...) @printf(ptr noundef @.str.1)
  %6 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.2, ptr noundef %2)
  br label %7

7:                                                ; preds = %10, %4
  %8 = call i32 @getchar()
  %9 = icmp ne i32 %8, 10
  br i1 %9, label %10, label %11

10:                                               ; preds = %7
  br label %7, !llvm.loop !5

11:                                               ; preds = %7
  %12 = load i8, ptr %2, align 1, !tbaa !7
  %13 = sext i8 %12 to i32
  switch i32 %13, label %21 [
    i32 105, label %14
    i32 109, label %15
    i32 99, label %16
    i32 114, label %17
    i32 118, label %18
    i32 113, label %19
    i32 104, label %20
  ]

14:                                               ; preds = %11
  call void @insert_task(i32 noundef 1, ptr noundef @.str.3, ptr noundef @.str.3)
  br label %23

15:                                               ; preds = %11
  call void @modify_task()
  br label %23

16:                                               ; preds = %11
  call void @change_category()
  br label %23

17:                                               ; preds = %11
  call void @remove_task()
  br label %23

18:                                               ; preds = %11
  call void @view_list()
  br label %23

19:                                               ; preds = %11
  call void @terminate(ptr noundef @.str.4, i32 noundef 0)
  br label %23

20:                                               ; preds = %11
  call void @print_help()
  br label %23

21:                                               ; preds = %11
  %22 = call i32 (ptr, ...) @printf(ptr noundef @.str.5)
  br label %23

23:                                               ; preds = %21, %20, %19, %18, %17, %16, %15, %14
  br label %4
}

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @print_help() #0

; Function Attrs: nounwind uwtable
declare dso_local void @read_from_file() #0

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

; Function Attrs: inlinehint nounwind uwtable
declare i32 @getchar() #3

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

; Function Attrs: nounwind uwtable
declare dso_local void @modify_task() #0

; Function Attrs: nounwind uwtable
declare dso_local void @change_category() #0

; Function Attrs: nounwind uwtable
declare dso_local void @remove_task() #0

; Function Attrs: nounwind uwtable
declare dso_local void @view_list() #0

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

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 = { 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 #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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}


; 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 [37 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [24 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [1 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [14 x i8], align 1

; Function Attrs: noreturn nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca i8, align 1
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %1) #5
  %2 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str)
  tail call void @print_help()
  tail call void @read_from_file()
  br label %3

3:                                                ; preds = %.backedge, %0
  %4 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1)
  %5 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.2, ptr noundef nonnull %1)
  br label %6

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

8:                                                ; preds = %6
  %9 = load i8, ptr %1, align 1, !tbaa !7
  switch i8 %9, label %17 [
    i8 105, label %10
    i8 109, label %11
    i8 99, label %12
    i8 114, label %13
    i8 118, label %14
    i8 113, label %15
    i8 104, label %16
  ]

10:                                               ; preds = %8
  call void @insert_task(i32 noundef 1, ptr noundef nonnull @.str.3, ptr noundef nonnull @.str.3)
  br label %.backedge

11:                                               ; preds = %8
  call void @modify_task()
  br label %.backedge

12:                                               ; preds = %8
  call void @change_category()
  br label %.backedge

13:                                               ; preds = %8
  call void @remove_task()
  br label %.backedge

14:                                               ; preds = %8
  call void @view_list()
  br label %.backedge

15:                                               ; preds = %8
  call void @terminate(ptr noundef nonnull @.str.4, i32 noundef 0)
  br label %.backedge

16:                                               ; preds = %8
  call void @print_help()
  br label %.backedge

17:                                               ; preds = %8
  %18 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.5)
  br label %.backedge

.backedge:                                        ; preds = %17, %16, %15, %14, %13, %12, %11, %10
  br label %3
}

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @print_help() local_unnamed_addr #3

; Function Attrs: nounwind uwtable
declare dso_local void @read_from_file() local_unnamed_addr #3

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

; Function Attrs: inlinehint nofree nounwind uwtable
declare noundef i32 @getchar() local_unnamed_addr #4

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

; Function Attrs: nounwind uwtable
declare dso_local void @modify_task() local_unnamed_addr #3

; Function Attrs: nounwind uwtable
declare dso_local void @change_category() local_unnamed_addr #3

; Function Attrs: nounwind uwtable
declare dso_local void @remove_task() local_unnamed_addr #3

; Function Attrs: nounwind uwtable
declare dso_local void @view_list() local_unnamed_addr #3

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

attributes #0 = { noreturn 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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 = { 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 #5 = { 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}


; Effective O3 passes: GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass