; LLVM IR from AllAlgorithms/c :: algorithms/data-structures (Add_Ploynomial_Linklist)

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

@poly1 = external dso_local global ptr, align 8
@poly2 = external dso_local global ptr, align 8
@poly3 = external dso_local global ptr, align 8
@.str = external hidden unnamed_addr constant [20 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [12 x i8], align 1

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

8:                                                ; preds = %1
  %9 = load ptr, ptr @poly1, align 8, !tbaa !9
  store ptr %9, ptr %3, align 8, !tbaa !9
  br label %18

10:                                               ; preds = %1
  %11 = load i32, ptr %2, align 4, !tbaa !5
  %12 = icmp eq i32 %11, 2
  br i1 %12, label %13, label %15

13:                                               ; preds = %10
  %14 = load ptr, ptr @poly2, align 8, !tbaa !9
  store ptr %14, ptr %3, align 8, !tbaa !9
  br label %17

15:                                               ; preds = %10
  %16 = load ptr, ptr @poly3, align 8, !tbaa !9
  store ptr %16, ptr %3, align 8, !tbaa !9
  br label %17

17:                                               ; preds = %15, %13
  br label %18

18:                                               ; preds = %17, %8
  %19 = load ptr, ptr %3, align 8, !tbaa !9
  %20 = icmp eq ptr %19, null
  br i1 %20, label %21, label %23

21:                                               ; preds = %18
  %22 = call i32 (ptr, ...) @printf(ptr noundef @.str)
  store i32 1, ptr %4, align 4
  br label %41

23:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %24 = load ptr, ptr %3, align 8, !tbaa !9
  store ptr %24, ptr %5, align 8, !tbaa !9
  br label %25

25:                                               ; preds = %28, %23
  %26 = load ptr, ptr %5, align 8, !tbaa !9
  %27 = icmp ne ptr %26, null
  br i1 %27, label %28, label %40

28:                                               ; preds = %25
  %29 = load ptr, ptr %5, align 8, !tbaa !9
  %30 = getelementptr inbounds %struct.node, ptr %29, i32 0, i32 1
  %31 = load float, ptr %30, align 4, !tbaa !11
  %32 = fpext float %31 to double
  %33 = load ptr, ptr %5, align 8, !tbaa !9
  %34 = getelementptr inbounds %struct.node, ptr %33, i32 0, i32 0
  %35 = load i32, ptr %34, align 8, !tbaa !14
  %36 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, double noundef %32, i32 noundef %35)
  %37 = load ptr, ptr %5, align 8, !tbaa !9
  %38 = getelementptr inbounds %struct.node, ptr %37, i32 0, i32 2
  %39 = load ptr, ptr %38, align 8, !tbaa !15
  store ptr %39, ptr %5, align 8, !tbaa !9
  br label %25, !llvm.loop !16

40:                                               ; preds = %25
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  store i32 0, ptr %4, align 4
  br label %41

41:                                               ; preds = %40, %21
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  %42 = load i32, ptr %4, align 4
  switch i32 %42, label %44 [
    i32 0, label %43
    i32 1, label %43
  ]

43:                                               ; preds = %41, %41
  ret void

44:                                               ; preds = %41
  unreachable
}

; 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

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


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

@poly1 = external dso_local local_unnamed_addr global ptr, align 8
@poly2 = external dso_local local_unnamed_addr global ptr, align 8
@poly3 = external dso_local local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [20 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [12 x i8], align 1

; Function Attrs: nofree nounwind uwtable
define dso_local void @display(i32 noundef %0) local_unnamed_addr #0 {
  %switch.selectcmp = icmp eq i32 %0, 2
  %switch.selectcmp9 = icmp eq i32 %0, 1
  %poly1.val = load ptr, ptr @poly1, align 8
  %poly2.val = load ptr, ptr @poly2, align 8
  %poly3.val = load ptr, ptr @poly3, align 8
  %switch.select.val = select i1 %switch.selectcmp, ptr %poly2.val, ptr %poly3.val
  %.07 = select i1 %switch.selectcmp9, ptr %poly1.val, ptr %switch.select.val
  %2 = icmp eq ptr %.07, null
  br i1 %2, label %3, label %.preheader

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

.preheader:                                       ; preds = %1, %.preheader
  %.011 = phi ptr [ %11, %.preheader ], [ %.07, %1 ]
  %5 = getelementptr inbounds i8, ptr %.011, i64 4
  %6 = load float, ptr %5, align 4, !tbaa !5
  %7 = fpext float %6 to double
  %8 = load i32, ptr %.011, align 8, !tbaa !12
  %9 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, double noundef %7, i32 noundef %8)
  %10 = getelementptr inbounds i8, ptr %.011, i64 8
  %11 = load ptr, ptr %10, align 8, !tbaa !13
  %.not = icmp eq ptr %11, null
  br i1 %.not, label %.loopexit, label %.preheader, !llvm.loop !14

.loopexit:                                        ; preds = %.preheader, %3
  ret void
}

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

attributes #0 = { 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, !10, i64 4}
!6 = !{!"node", !7, i64 0, !10, i64 4, !11, i64 8}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"float", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!6, !7, i64 0}
!13 = !{!6, !11, i64 8}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


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