; LLVM IR from smv1999/CompetitiveProgrammingQuestionBank :: Dynamic Programming (job_sequencing_greedyMethod)

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

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

; 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 i32 @isEmpty(ptr noundef, i32 noundef) #2

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

; Function Attrs: nounwind uwtable
define dso_local i32 @job_sequencing(ptr noundef %0, i32 noundef %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  %11 = load i32, ptr %4, align 4, !tbaa !9
  %12 = zext i32 %11 to i64
  %13 = call ptr @llvm.stacksave.p0()
  store ptr %13, ptr %5, align 8
  %14 = alloca i32, i64 %12, align 16
  store i64 %12, ptr %6, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 0, ptr %7, align 4, !tbaa !9
  %15 = load i32, ptr %4, align 4, !tbaa !9
  call void @initSlots(ptr noundef %14, i32 noundef %15)
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %16

16:                                               ; preds = %83, %2
  %17 = load i32, ptr %8, align 4, !tbaa !9
  %18 = load i32, ptr %4, align 4, !tbaa !9
  %19 = icmp slt i32 %17, %18
  br i1 %19, label %20, label %86

20:                                               ; preds = %16
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = load i32, ptr %8, align 4, !tbaa !9
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds %struct.job, ptr %21, i64 %23
  %25 = getelementptr inbounds %struct.job, ptr %24, i32 0, i32 2
  %26 = load i32, ptr %25, align 4, !tbaa !11
  %27 = sub nsw i32 %26, 1
  store i32 %27, ptr %10, align 4, !tbaa !9
  %28 = load i32, ptr %10, align 4, !tbaa !9
  %29 = call i32 @isEmpty(ptr noundef %14, i32 noundef %28)
  %30 = icmp ne i32 %29, 0
  br i1 %30, label %31, label %49

31:                                               ; preds = %20
  %32 = load ptr, ptr %3, align 8, !tbaa !5
  %33 = load i32, ptr %8, align 4, !tbaa !9
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds %struct.job, ptr %32, i64 %34
  %36 = getelementptr inbounds %struct.job, ptr %35, i32 0, i32 0
  %37 = load i32, ptr %36, align 4, !tbaa !13
  %38 = load i32, ptr %10, align 4, !tbaa !9
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds i32, ptr %14, i64 %39
  store i32 %37, ptr %40, align 4, !tbaa !9
  %41 = load ptr, ptr %3, align 8, !tbaa !5
  %42 = load i32, ptr %8, align 4, !tbaa !9
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds %struct.job, ptr %41, i64 %43
  %45 = getelementptr inbounds %struct.job, ptr %44, i32 0, i32 1
  %46 = load i32, ptr %45, align 4, !tbaa !14
  %47 = load i32, ptr %7, align 4, !tbaa !9
  %48 = add nsw i32 %47, %46
  store i32 %48, ptr %7, align 4, !tbaa !9
  br label %82

49:                                               ; preds = %20
  %50 = load i32, ptr %10, align 4, !tbaa !9
  %51 = sub nsw i32 %50, 1
  store i32 %51, ptr %9, align 4, !tbaa !9
  br label %52

52:                                               ; preds = %78, %49
  %53 = load i32, ptr %9, align 4, !tbaa !9
  %54 = icmp sge i32 %53, 0
  br i1 %54, label %55, label %81

55:                                               ; preds = %52
  %56 = load i32, ptr %9, align 4, !tbaa !9
  %57 = call i32 @isEmpty(ptr noundef %14, i32 noundef %56)
  %58 = icmp ne i32 %57, 0
  br i1 %58, label %59, label %77

59:                                               ; preds = %55
  %60 = load ptr, ptr %3, align 8, !tbaa !5
  %61 = load i32, ptr %8, align 4, !tbaa !9
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds %struct.job, ptr %60, i64 %62
  %64 = getelementptr inbounds %struct.job, ptr %63, i32 0, i32 0
  %65 = load i32, ptr %64, align 4, !tbaa !13
  %66 = load i32, ptr %9, align 4, !tbaa !9
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds i32, ptr %14, i64 %67
  store i32 %65, ptr %68, align 4, !tbaa !9
  %69 = load ptr, ptr %3, align 8, !tbaa !5
  %70 = load i32, ptr %8, align 4, !tbaa !9
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds %struct.job, ptr %69, i64 %71
  %73 = getelementptr inbounds %struct.job, ptr %72, i32 0, i32 1
  %74 = load i32, ptr %73, align 4, !tbaa !14
  %75 = load i32, ptr %7, align 4, !tbaa !9
  %76 = add nsw i32 %75, %74
  store i32 %76, ptr %7, align 4, !tbaa !9
  br label %77

77:                                               ; preds = %59, %55
  br label %78

78:                                               ; preds = %77
  %79 = load i32, ptr %9, align 4, !tbaa !9
  %80 = add nsw i32 %79, -1
  store i32 %80, ptr %9, align 4, !tbaa !9
  br label %52, !llvm.loop !15

81:                                               ; preds = %52
  br label %82

82:                                               ; preds = %81, %31
  br label %83

83:                                               ; preds = %82
  %84 = load i32, ptr %8, align 4, !tbaa !9
  %85 = add nsw i32 %84, 1
  store i32 %85, ptr %8, align 4, !tbaa !9
  br label %16, !llvm.loop !17

86:                                               ; preds = %16
  %87 = call i32 (ptr, ...) @printf(ptr noundef @.str.2)
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %88

88:                                               ; preds = %98, %86
  %89 = load i32, ptr %8, align 4, !tbaa !9
  %90 = load i32, ptr %4, align 4, !tbaa !9
  %91 = icmp slt i32 %89, %90
  br i1 %91, label %92, label %101

92:                                               ; preds = %88
  %93 = load i32, ptr %8, align 4, !tbaa !9
  %94 = sext i32 %93 to i64
  %95 = getelementptr inbounds i32, ptr %14, i64 %94
  %96 = load i32, ptr %95, align 4, !tbaa !9
  %97 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, i32 noundef %96)
  br label %98

98:                                               ; preds = %92
  %99 = load i32, ptr %8, align 4, !tbaa !9
  %100 = add nsw i32 %99, 1
  store i32 %100, ptr %8, align 4, !tbaa !9
  br label %88, !llvm.loop !18

101:                                              ; preds = %88
  %102 = call i32 (ptr, ...) @printf(ptr noundef @.str.4)
  %103 = load i32, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  %104 = load ptr, ptr %5, align 8
  call void @llvm.stackrestore.p0(ptr %104)
  ret i32 %103
}

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #3

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #3

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 = { nocallback nofree nosync nounwind willreturn }
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 = !{!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 8}
!12 = !{!"job", !10, i64 0, !10, i64 4, !10, i64 8}
!13 = !{!12, !10, i64 0}
!14 = !{!12, !10, i64 4}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}
!18 = distinct !{!18, !16}


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

%struct.job = type { i32, i32, i32 }

@.str.2 = external hidden unnamed_addr constant [19 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [2 x i8], align 1

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @isEmpty(ptr noundef, i32 noundef) local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
define dso_local i32 @job_sequencing(ptr nocapture noundef readonly %0, i32 noundef %1) local_unnamed_addr #1 {
  %3 = zext i32 %1 to i64
  %4 = alloca i32, i64 %3, align 16
  call void @initSlots(ptr noundef nonnull %4, i32 noundef %1)
  %5 = icmp sgt i32 %1, 0
  br i1 %5, label %.lr.ph38, label %._crit_edge.thread

._crit_edge.thread:                               ; preds = %2
  %6 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2)
  br label %._crit_edge43

.lr.ph38:                                         ; preds = %2, %.loopexit
  %indvars.iv45 = phi i64 [ %indvars.iv.next46, %.loopexit ], [ 0, %2 ]
  %.037 = phi i32 [ %.3, %.loopexit ], [ 0, %2 ]
  %7 = getelementptr inbounds %struct.job, ptr %0, i64 %indvars.iv45
  %8 = getelementptr inbounds i8, ptr %7, i64 8
  %9 = load i32, ptr %8, align 4, !tbaa !5
  %10 = add nsw i32 %9, -1
  %11 = call i32 @isEmpty(ptr noundef nonnull %4, i32 noundef %10)
  %.not = icmp eq i32 %11, 0
  br i1 %.not, label %19, label %12

12:                                               ; preds = %.lr.ph38
  %13 = load i32, ptr %7, align 4, !tbaa !10
  %14 = sext i32 %10 to i64
  %15 = getelementptr inbounds i32, ptr %4, i64 %14
  store i32 %13, ptr %15, align 4, !tbaa !11
  %16 = getelementptr inbounds i8, ptr %7, i64 4
  %17 = load i32, ptr %16, align 4, !tbaa !12
  %18 = add nsw i32 %17, %.037
  br label %.loopexit

19:                                               ; preds = %.lr.ph38
  %20 = icmp sgt i32 %9, 1
  br i1 %20, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %19
  %21 = add nsw i32 %9, -2
  %22 = getelementptr inbounds i8, ptr %7, i64 4
  %23 = zext nneg i32 %21 to i64
  br label %24

24:                                               ; preds = %.lr.ph, %32
  %indvars.iv = phi i64 [ %23, %.lr.ph ], [ %indvars.iv.next, %32 ]
  %.135 = phi i32 [ %.037, %.lr.ph ], [ %.2, %32 ]
  %25 = trunc nuw nsw i64 %indvars.iv to i32
  %26 = call i32 @isEmpty(ptr noundef nonnull %4, i32 noundef %25)
  %.not33 = icmp eq i32 %26, 0
  br i1 %.not33, label %32, label %27

27:                                               ; preds = %24
  %28 = load i32, ptr %7, align 4, !tbaa !10
  %29 = getelementptr inbounds i32, ptr %4, i64 %indvars.iv
  store i32 %28, ptr %29, align 4, !tbaa !11
  %30 = load i32, ptr %22, align 4, !tbaa !12
  %31 = add nsw i32 %30, %.135
  br label %32

32:                                               ; preds = %24, %27
  %.2 = phi i32 [ %31, %27 ], [ %.135, %24 ]
  %indvars.iv.next = add nsw i64 %indvars.iv, -1
  %33 = icmp sgt i64 %indvars.iv, 0
  br i1 %33, label %24, label %.loopexit, !llvm.loop !13

.loopexit:                                        ; preds = %32, %19, %12
  %.3 = phi i32 [ %18, %12 ], [ %.037, %19 ], [ %.2, %32 ]
  %indvars.iv.next46 = add nuw nsw i64 %indvars.iv45, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next46, %3
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph38, !llvm.loop !15

._crit_edge:                                      ; preds = %.loopexit
  %34 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2)
  br i1 %5, label %.lr.ph42, label %._crit_edge43

.lr.ph42:                                         ; preds = %._crit_edge, %.lr.ph42
  %indvars.iv48 = phi i64 [ %indvars.iv.next49, %.lr.ph42 ], [ 0, %._crit_edge ]
  %35 = getelementptr inbounds i32, ptr %4, i64 %indvars.iv48
  %36 = load i32, ptr %35, align 4, !tbaa !11
  %37 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i32 noundef %36)
  %indvars.iv.next49 = add nuw nsw i64 %indvars.iv48, 1
  %exitcond52.not = icmp eq i64 %indvars.iv.next49, %3
  br i1 %exitcond52.not, label %._crit_edge43, label %.lr.ph42, !llvm.loop !16

._crit_edge43:                                    ; preds = %.lr.ph42, %._crit_edge.thread, %._crit_edge
  %.0.lcssa54 = phi i32 [ 0, %._crit_edge.thread ], [ %.3, %._crit_edge ], [ %.3, %.lr.ph42 ]
  %38 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4)
  ret i32 %.0.lcssa54
}

attributes #0 = { 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 #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" }

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


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass