; LLVM IR from smv1999/CompetitiveProgrammingQuestionBank :: General Questions (CLL SLL Wipro)

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

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

; Function Attrs: nounwind uwtable
define dso_local ptr @addNode(ptr noundef %0, i32 noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %11 = call noalias ptr @malloc(i64 noundef 16) #4
  store ptr %11, ptr %8, align 8, !tbaa !5
  %12 = load i32, ptr %5, align 4, !tbaa !9
  %13 = load ptr, ptr %8, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.cll_sll_wipro, ptr %13, i32 0, i32 0
  store i32 %12, ptr %14, align 8, !tbaa !11
  %15 = load ptr, ptr %8, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.cll_sll_wipro, ptr %15, i32 0, i32 1
  store ptr null, ptr %16, align 8, !tbaa !13
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = icmp eq ptr %17, null
  br i1 %18, label %19, label %24

19:                                               ; preds = %2
  %20 = load ptr, ptr %8, align 8, !tbaa !5
  %21 = load ptr, ptr %8, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.cll_sll_wipro, ptr %21, i32 0, i32 1
  store ptr %20, ptr %22, align 8, !tbaa !13
  %23 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %23, ptr %3, align 8
  store i32 1, ptr %10, align 4
  br label %100

24:                                               ; preds = %2
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %25, ptr %6, align 8, !tbaa !5
  store ptr %25, ptr %9, align 8, !tbaa !5
  br label %26

26:                                               ; preds = %40, %24
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.cll_sll_wipro, ptr %27, i32 0, i32 1
  %29 = load ptr, ptr %28, align 8, !tbaa !13
  store ptr %29, ptr %6, align 8, !tbaa !5
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.cll_sll_wipro, ptr %30, i32 0, i32 0
  %32 = load i32, ptr %31, align 8, !tbaa !11
  %33 = load ptr, ptr %9, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.cll_sll_wipro, ptr %33, i32 0, i32 0
  %35 = load i32, ptr %34, align 8, !tbaa !11
  %36 = icmp slt i32 %32, %35
  br i1 %36, label %37, label %39

37:                                               ; preds = %26
  %38 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %38, ptr %9, align 8, !tbaa !5
  br label %39

39:                                               ; preds = %37, %26
  br label %40

40:                                               ; preds = %39
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = icmp ne ptr %41, %42
  br i1 %43, label %26, label %44, !llvm.loop !14

44:                                               ; preds = %40
  %45 = load ptr, ptr %8, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.cll_sll_wipro, ptr %45, i32 0, i32 0
  %47 = load i32, ptr %46, align 8, !tbaa !11
  %48 = load ptr, ptr %9, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.cll_sll_wipro, ptr %48, i32 0, i32 0
  %50 = load i32, ptr %49, align 8, !tbaa !11
  %51 = icmp slt i32 %47, %50
  br i1 %51, label %52, label %71

52:                                               ; preds = %44
  %53 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %53, ptr %6, align 8, !tbaa !5
  br label %54

54:                                               ; preds = %59, %52
  %55 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %55, ptr %7, align 8, !tbaa !5
  %56 = load ptr, ptr %6, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.cll_sll_wipro, ptr %56, i32 0, i32 1
  %58 = load ptr, ptr %57, align 8, !tbaa !13
  store ptr %58, ptr %6, align 8, !tbaa !5
  br label %59

59:                                               ; preds = %54
  %60 = load ptr, ptr %6, align 8, !tbaa !5
  %61 = load ptr, ptr %9, align 8, !tbaa !5
  %62 = icmp ne ptr %60, %61
  br i1 %62, label %54, label %63, !llvm.loop !16

63:                                               ; preds = %59
  %64 = load ptr, ptr %8, align 8, !tbaa !5
  %65 = load ptr, ptr %7, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.cll_sll_wipro, ptr %65, i32 0, i32 1
  store ptr %64, ptr %66, align 8, !tbaa !13
  %67 = load ptr, ptr %6, align 8, !tbaa !5
  %68 = load ptr, ptr %8, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.cll_sll_wipro, ptr %68, i32 0, i32 1
  store ptr %67, ptr %69, align 8, !tbaa !13
  %70 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %70, ptr %3, align 8
  store i32 1, ptr %10, align 4
  br label %100

71:                                               ; preds = %44
  %72 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %72, ptr %6, align 8, !tbaa !5
  br label %73

73:                                               ; preds = %90, %71
  %74 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %74, ptr %7, align 8, !tbaa !5
  %75 = load ptr, ptr %6, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.cll_sll_wipro, ptr %75, i32 0, i32 1
  %77 = load ptr, ptr %76, align 8, !tbaa !13
  store ptr %77, ptr %6, align 8, !tbaa !5
  br label %78

78:                                               ; preds = %73
  %79 = load ptr, ptr %6, align 8, !tbaa !5
  %80 = load ptr, ptr %9, align 8, !tbaa !5
  %81 = icmp ne ptr %79, %80
  br i1 %81, label %82, label %90

82:                                               ; preds = %78
  %83 = load ptr, ptr %8, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.cll_sll_wipro, ptr %83, i32 0, i32 0
  %85 = load i32, ptr %84, align 8, !tbaa !11
  %86 = load ptr, ptr %6, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct.cll_sll_wipro, ptr %86, i32 0, i32 0
  %88 = load i32, ptr %87, align 8, !tbaa !11
  %89 = icmp sgt i32 %85, %88
  br label %90

90:                                               ; preds = %82, %78
  %91 = phi i1 [ false, %78 ], [ %89, %82 ]
  br i1 %91, label %73, label %92, !llvm.loop !17

92:                                               ; preds = %90
  %93 = load ptr, ptr %8, align 8, !tbaa !5
  %94 = load ptr, ptr %7, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct.cll_sll_wipro, ptr %94, i32 0, i32 1
  store ptr %93, ptr %95, align 8, !tbaa !13
  %96 = load ptr, ptr %6, align 8, !tbaa !5
  %97 = load ptr, ptr %8, align 8, !tbaa !5
  %98 = getelementptr inbounds %struct.cll_sll_wipro, ptr %97, i32 0, i32 1
  store ptr %96, ptr %98, align 8, !tbaa !13
  %99 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %99, ptr %3, align 8
  store i32 1, ptr %10, align 4
  br label %100

100:                                              ; preds = %92, %63, %19
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %101 = load ptr, ptr %3, align 8
  ret ptr %101
}

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

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #2

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 = { nounwind allocsize(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 }
attributes #4 = { nounwind allocsize(0) }

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


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

; Function Attrs: nofree nounwind uwtable
define dso_local noundef ptr @addNode(ptr noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = tail call noalias dereferenceable_or_null(16) ptr @malloc(i64 noundef 16) #3
  store i32 %1, ptr %3, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %3, i64 8
  store ptr null, ptr %4, align 8, !tbaa !11
  %5 = icmp eq ptr %0, null
  br i1 %5, label %23, label %.preheader48.preheader

.preheader48.preheader:                           ; preds = %2
  %.pre = load i32, ptr %0, align 8, !tbaa !5
  br label %.preheader48

.preheader48:                                     ; preds = %.preheader48.preheader, %.preheader48
  %6 = phi i32 [ %11, %.preheader48 ], [ %.pre, %.preheader48.preheader ]
  %.039 = phi ptr [ %8, %.preheader48 ], [ %0, %.preheader48.preheader ]
  %.0 = phi ptr [ %spec.select, %.preheader48 ], [ %0, %.preheader48.preheader ]
  %7 = getelementptr inbounds i8, ptr %.039, i64 8
  %8 = load ptr, ptr %7, align 8, !tbaa !11
  %9 = load i32, ptr %8, align 8, !tbaa !5
  %10 = icmp slt i32 %9, %6
  %11 = tail call i32 @llvm.smin.i32(i32 %9, i32 %6)
  %spec.select = select i1 %10, ptr %8, ptr %.0
  %.not = icmp eq ptr %8, %0
  br i1 %.not, label %12, label %.preheader48, !llvm.loop !12

12:                                               ; preds = %.preheader48
  %13 = load i32, ptr %spec.select, align 8, !tbaa !5
  %14 = icmp sgt i32 %13, %1
  br i1 %14, label %.preheader, label %.preheader47

.preheader:                                       ; preds = %12, %.preheader
  %.140 = phi ptr [ %16, %.preheader ], [ %spec.select, %12 ]
  %15 = getelementptr inbounds i8, ptr %.140, i64 8
  %16 = load ptr, ptr %15, align 8, !tbaa !11
  %.not46 = icmp eq ptr %16, %spec.select
  br i1 %.not46, label %.sink.split, label %.preheader, !llvm.loop !14

.preheader47:                                     ; preds = %12, %19
  %.2 = phi ptr [ %18, %19 ], [ %spec.select, %12 ]
  %17 = getelementptr inbounds i8, ptr %.2, i64 8
  %18 = load ptr, ptr %17, align 8, !tbaa !11
  %.not45 = icmp eq ptr %18, %spec.select
  br i1 %.not45, label %.sink.split, label %19

19:                                               ; preds = %.preheader47
  %20 = load i32, ptr %18, align 8, !tbaa !5
  %21 = icmp slt i32 %20, %1
  br i1 %21, label %.preheader47, label %.sink.split, !llvm.loop !15

.sink.split:                                      ; preds = %19, %.preheader47, %.preheader
  %.2.lcssa.sink = phi ptr [ %.140, %.preheader ], [ %.2, %.preheader47 ], [ %.2, %19 ]
  %.lcssa54.sink.ph = phi ptr [ %16, %.preheader ], [ %18, %.preheader47 ], [ %18, %19 ]
  %22 = getelementptr inbounds i8, ptr %.2.lcssa.sink, i64 8
  store ptr %3, ptr %22, align 8, !tbaa !11
  br label %23

23:                                               ; preds = %.sink.split, %2
  %.lcssa54.sink = phi ptr [ %3, %2 ], [ %.lcssa54.sink.ph, %.sink.split ]
  store ptr %.lcssa54.sink, ptr %4, align 8, !tbaa !11
  ret ptr %3
}

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smin.i32(i32, i32) #2

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 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { nounwind allocsize(0) }

!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 = !{!"cll_sll_wipro", !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 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}
!15 = distinct !{!15, !13}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass