; LLVM IR from alexzheng42/sDMD :: src (ToolFunctions)

; 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.2 = external hidden unnamed_addr constant [70 x i8], align 1
@.str.49 = external hidden unnamed_addr constant [53 x i8], align 1
@.str.50 = 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

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

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

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @FindElemInList(ptr noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) #3 {
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store i32 %1, ptr %8, align 4, !tbaa !9
  store i32 %2, ptr %9, align 4, !tbaa !9
  store i32 %3, ptr %10, align 4, !tbaa !9
  store i32 %4, ptr %11, align 4, !tbaa !9
  %15 = load i32, ptr %10, align 4, !tbaa !9
  %16 = icmp sge i32 %15, 0
  br i1 %16, label %17, label %66

17:                                               ; preds = %5
  %18 = load i32, ptr %9, align 4, !tbaa !9
  %19 = icmp sge i32 %18, 0
  br i1 %19, label %20, label %66

20:                                               ; preds = %17
  %21 = load i32, ptr %10, align 4, !tbaa !9
  %22 = load i32, ptr %9, align 4, !tbaa !9
  %23 = icmp sge i32 %21, %22
  br i1 %23, label %24, label %66

24:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  %25 = load i32, ptr %9, align 4, !tbaa !9
  store i32 %25, ptr %12, align 4, !tbaa !9
  br label %26

26:                                               ; preds = %60, %24
  %27 = load i32, ptr %12, align 4, !tbaa !9
  %28 = load i32, ptr %10, align 4, !tbaa !9
  %29 = icmp sle i32 %27, %28
  br i1 %29, label %31, label %30

30:                                               ; preds = %26
  store i32 2, ptr %13, align 4
  br label %63

31:                                               ; preds = %26
  %32 = load ptr, ptr %7, align 8, !tbaa !5
  %33 = load i32, ptr %12, align 4, !tbaa !9
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds i32, ptr %32, i64 %34
  %36 = load i32, ptr %35, align 4, !tbaa !9
  %37 = load i32, ptr %8, align 4, !tbaa !9
  %38 = icmp eq i32 %36, %37
  br i1 %38, label %39, label %41

39:                                               ; preds = %31
  %40 = load i32, ptr %12, align 4, !tbaa !9
  store i32 %40, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %63

41:                                               ; preds = %31
  %42 = load ptr, ptr %7, align 8, !tbaa !5
  %43 = load i32, ptr %12, align 4, !tbaa !9
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds i32, ptr %42, i64 %44
  %46 = load i32, ptr %45, align 4, !tbaa !9
  %47 = icmp eq i32 %46, 0
  br i1 %47, label %48, label %58

48:                                               ; preds = %41
  %49 = load i32, ptr %11, align 4, !tbaa !9
  %50 = icmp ne i32 %49, 0
  br i1 %50, label %51, label %57

51:                                               ; preds = %48
  %52 = load i32, ptr %8, align 4, !tbaa !9
  %53 = load ptr, ptr %7, align 8, !tbaa !5
  %54 = load i32, ptr %12, align 4, !tbaa !9
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds i32, ptr %53, i64 %55
  store i32 %52, ptr %56, align 4, !tbaa !9
  br label %57

57:                                               ; preds = %51, %48
  store i32 0, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %63

58:                                               ; preds = %41
  br label %59

59:                                               ; preds = %58
  br label %60

60:                                               ; preds = %59
  %61 = load i32, ptr %12, align 4, !tbaa !9
  %62 = add nsw i32 %61, 1
  store i32 %62, ptr %12, align 4, !tbaa !9
  br label %26, !llvm.loop !11

63:                                               ; preds = %57, %39, %30
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  %64 = load i32, ptr %13, align 4
  switch i32 %64, label %99 [
    i32 2, label %65
    i32 1, label %97
  ]

65:                                               ; preds = %63
  br label %96

66:                                               ; preds = %20, %17, %5
  %67 = load i32, ptr %11, align 4, !tbaa !9
  %68 = icmp ne i32 %67, 0
  br i1 %68, label %69, label %72

69:                                               ; preds = %66
  %70 = call i32 (ptr, ...) @printf(ptr noundef @.str.49)
  %71 = call i32 (ptr, ...) @printf(ptr noundef @.str.50, ptr noundef @.str.2, i32 noundef 1075)
  call void @exit(i32 noundef 1) #5
  unreachable

72:                                               ; preds = %66
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #4
  store i32 0, ptr %14, align 4, !tbaa !9
  br label %73

73:                                               ; preds = %91, %72
  %74 = load ptr, ptr %7, align 8, !tbaa !5
  %75 = load i32, ptr %14, align 4, !tbaa !9
  %76 = add nsw i32 %75, 1
  store i32 %76, ptr %14, align 4, !tbaa !9
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds i32, ptr %74, i64 %77
  %79 = load i32, ptr %78, align 4, !tbaa !9
  %80 = icmp ne i32 %79, 0
  br i1 %80, label %81, label %92

81:                                               ; preds = %73
  %82 = load ptr, ptr %7, align 8, !tbaa !5
  %83 = load i32, ptr %14, align 4, !tbaa !9
  %84 = sext i32 %83 to i64
  %85 = getelementptr inbounds i32, ptr %82, i64 %84
  %86 = load i32, ptr %85, align 4, !tbaa !9
  %87 = load i32, ptr %8, align 4, !tbaa !9
  %88 = icmp eq i32 %86, %87
  br i1 %88, label %89, label %91

89:                                               ; preds = %81
  %90 = load i32, ptr %14, align 4, !tbaa !9
  store i32 %90, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %93

91:                                               ; preds = %81
  br label %73, !llvm.loop !13

92:                                               ; preds = %73
  store i32 0, ptr %13, align 4
  br label %93

93:                                               ; preds = %92, %89
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #4
  %94 = load i32, ptr %13, align 4
  switch i32 %94, label %99 [
    i32 0, label %95
    i32 1, label %97
  ]

95:                                               ; preds = %93
  br label %96

96:                                               ; preds = %95, %65
  store i32 0, ptr %6, align 4
  br label %97

97:                                               ; preds = %96, %93, %63
  %98 = load i32, ptr %6, align 4
  ret i32 %98

99:                                               ; preds = %93, %63
  unreachable
}

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 = { noreturn 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 = { nounwind }
attributes #5 = { noreturn 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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


; 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.2 = external hidden unnamed_addr constant [70 x i8], align 1
@.str.49 = external hidden unnamed_addr constant [53 x i8], align 1
@.str.50 = external hidden unnamed_addr constant [7 x i8], align 1

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

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local i32 @FindElemInList(ptr nocapture noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) local_unnamed_addr #2 {
  %6 = or i32 %3, %2
  %or.cond = icmp slt i32 %6, 0
  %.not = icmp slt i32 %3, %2
  %or.cond41 = or i1 %.not, %or.cond
  br i1 %or.cond41, label %18, label %.preheader50.preheader

.preheader50.preheader:                           ; preds = %5
  %7 = zext i32 %2 to i64
  br label %.preheader50

.preheader50:                                     ; preds = %.preheader50.preheader, %16
  %indvars.iv = phi i64 [ %7, %.preheader50.preheader ], [ %indvars.iv.next, %16 ]
  %8 = getelementptr inbounds i32, ptr %0, i64 %indvars.iv
  %9 = load i32, ptr %8, align 4, !tbaa !5
  %10 = icmp eq i32 %9, %1
  br i1 %10, label %.thread.loopexit, label %11

11:                                               ; preds = %.preheader50
  %12 = icmp eq i32 %9, 0
  br i1 %12, label %13, label %16

13:                                               ; preds = %11
  %.not40 = icmp eq i32 %4, 0
  br i1 %.not40, label %.thread, label %14

14:                                               ; preds = %13
  %15 = getelementptr inbounds i32, ptr %0, i64 %indvars.iv
  store i32 %1, ptr %15, align 4, !tbaa !5
  br label %.thread

16:                                               ; preds = %11
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %17 = trunc nuw i64 %indvars.iv to i32
  %.not39.not = icmp slt i32 %17, %3
  br i1 %.not39.not, label %.preheader50, label %.loopexit, !llvm.loop !9

18:                                               ; preds = %5
  %.not37 = icmp eq i32 %4, 0
  br i1 %.not37, label %.preheader, label %19

19:                                               ; preds = %18
  %20 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.49)
  %21 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.50, ptr noundef nonnull @.str.2, i32 noundef 1075)
  tail call void @exit(i32 noundef 1) #3
  unreachable

.preheader:                                       ; preds = %18, %.preheader
  %indvars.iv63 = phi i64 [ %indvars.iv.next64, %.preheader ], [ 0, %18 ]
  %indvars.iv.next64 = add nuw nsw i64 %indvars.iv63, 1
  %22 = getelementptr inbounds i32, ptr %0, i64 %indvars.iv.next64
  %23 = load i32, ptr %22, align 4, !tbaa !5
  %.not38 = icmp ne i32 %23, 0
  %24 = icmp ne i32 %23, %1
  %or.cond44.not = and i1 %24, %.not38
  br i1 %or.cond44.not, label %.preheader, label %25, !llvm.loop !11

25:                                               ; preds = %.preheader
  %26 = trunc nuw nsw i64 %indvars.iv.next64 to i32
  br i1 %.not38, label %.thread, label %.loopexit

.loopexit:                                        ; preds = %16, %25
  br label %.thread

.thread.loopexit:                                 ; preds = %.preheader50
  %27 = trunc nuw i64 %indvars.iv to i32
  br label %.thread

.thread:                                          ; preds = %.thread.loopexit, %13, %14, %25, %.loopexit
  %.2 = phi i32 [ 0, %.loopexit ], [ %26, %25 ], [ 0, %13 ], [ 0, %14 ], [ %27, %.thread.loopexit ]
  ret i32 %.2
}

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 = { noreturn 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 = { 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 = { noreturn 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}


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