; LLVM IR from tum-i4/obfuscation-benchmarks :: basic-algorithms (linearsearch)

; 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 [31 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [21 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @main(i32 noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca [10 x i32], align 16
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store i32 0, ptr %3, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  %10 = load i32, ptr %4, align 4, !tbaa !5
  %11 = icmp slt i32 %10, 12
  br i1 %11, label %12, label %13

12:                                               ; preds = %2
  store i32 1, ptr %3, align 4
  br label %70

13:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 40, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  store i32 0, ptr %9, align 4, !tbaa !5
  store i32 1, ptr %7, align 4, !tbaa !5
  br label %14

14:                                               ; preds = %32, %13
  %15 = load i32, ptr %7, align 4, !tbaa !5
  %16 = load i32, ptr %4, align 4, !tbaa !5
  %17 = sub nsw i32 %16, 1
  %18 = icmp slt i32 %15, %17
  br i1 %18, label %19, label %35

19:                                               ; preds = %14
  %20 = load ptr, ptr %5, align 8, !tbaa !9
  %21 = load i32, ptr %7, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds ptr, ptr %20, i64 %22
  %24 = load ptr, ptr %23, align 8, !tbaa !9
  %25 = getelementptr inbounds i8, ptr %24, i64 0
  %26 = load i8, ptr %25, align 1, !tbaa !11
  %27 = sext i8 %26 to i32
  %28 = load i32, ptr %7, align 4, !tbaa !5
  %29 = sub nsw i32 %28, 1
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [10 x i32], ptr %6, i64 0, i64 %30
  store i32 %27, ptr %31, align 4, !tbaa !5
  br label %32

32:                                               ; preds = %19
  %33 = load i32, ptr %7, align 4, !tbaa !5
  %34 = add nsw i32 %33, 1
  store i32 %34, ptr %7, align 4, !tbaa !5
  br label %14, !llvm.loop !12

35:                                               ; preds = %14
  %36 = load ptr, ptr %5, align 8, !tbaa !9
  %37 = load i32, ptr %4, align 4, !tbaa !5
  %38 = sub nsw i32 %37, 1
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds ptr, ptr %36, i64 %39
  %41 = load ptr, ptr %40, align 8, !tbaa !9
  %42 = getelementptr inbounds i8, ptr %41, i64 0
  %43 = load i8, ptr %42, align 1, !tbaa !11
  %44 = sext i8 %43 to i32
  store i32 %44, ptr %8, align 4, !tbaa !5
  store i32 0, ptr %7, align 4, !tbaa !5
  br label %45

45:                                               ; preds = %59, %35
  %46 = load i32, ptr %7, align 4, !tbaa !5
  %47 = load i32, ptr %4, align 4, !tbaa !5
  %48 = sub nsw i32 %47, 2
  %49 = icmp sle i32 %46, %48
  br i1 %49, label %50, label %62

50:                                               ; preds = %45
  %51 = load i32, ptr %7, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [10 x i32], ptr %6, i64 0, i64 %52
  %54 = load i32, ptr %53, align 4, !tbaa !5
  %55 = load i32, ptr %8, align 4, !tbaa !5
  %56 = icmp eq i32 %54, %55
  br i1 %56, label %57, label %58

57:                                               ; preds = %50
  store i32 1, ptr %9, align 4, !tbaa !5
  br label %62

58:                                               ; preds = %50
  br label %59

59:                                               ; preds = %58
  %60 = load i32, ptr %7, align 4, !tbaa !5
  %61 = add nsw i32 %60, 1
  store i32 %61, ptr %7, align 4, !tbaa !5
  br label %45, !llvm.loop !14

62:                                               ; preds = %57, %45
  %63 = load i32, ptr %9, align 4, !tbaa !5
  %64 = icmp eq i32 %63, 0
  br i1 %64, label %65, label %67

65:                                               ; preds = %62
  %66 = call i32 (ptr, ...) @printf(ptr noundef @.str)
  br label %69

67:                                               ; preds = %62
  %68 = call i32 (ptr, ...) @printf(ptr noundef @.str.1)
  br label %69

69:                                               ; preds = %67, %65
  store i32 0, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 40, ptr %6) #3
  br label %70

70:                                               ; preds = %69, %12
  %71 = load i32, ptr %3, align 4
  ret i32 %71
}

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


; 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 [31 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [21 x i8], align 1

; Function Attrs: nofree nounwind uwtable
define dso_local range(i32 0, 2) i32 @main(i32 noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %3 = alloca [10 x i32], align 16
  %4 = icmp slt i32 %0, 12
  br i1 %4, label %46, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %2
  call void @llvm.lifetime.start.p0(i64 40, ptr nonnull %3) #4
  %5 = add nsw i32 %0, -1
  %wide.trip.count = zext nneg i32 %5 to i64
  %6 = add nsw i64 %wide.trip.count, -1
  %7 = add nsw i64 %wide.trip.count, -2
  %xtraiter = and i64 %6, 3
  %8 = icmp ult i64 %7, 3
  br i1 %8, label %.lr.ph23.preheader.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i64 %6, -4
  %invariant.gep = getelementptr inbounds i8, ptr %1, i64 8
  %invariant.gep30 = getelementptr inbounds i8, ptr %1, i64 16
  %invariant.gep32 = getelementptr inbounds i8, ptr %1, i64 24
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %indvars.iv = phi i64 [ 1, %.lr.ph.preheader.new ], [ %indvars.iv.next.3, %.lr.ph ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.3, %.lr.ph ]
  %9 = getelementptr inbounds ptr, ptr %1, i64 %indvars.iv
  %10 = load ptr, ptr %9, align 8, !tbaa !5
  %11 = load i8, ptr %10, align 1, !tbaa !9
  %12 = sext i8 %11 to i32
  %13 = add nsw i64 %indvars.iv, -1
  %14 = getelementptr inbounds [10 x i32], ptr %3, i64 0, i64 %13
  store i32 %12, ptr %14, align 4, !tbaa !10
  %gep = getelementptr inbounds ptr, ptr %invariant.gep, i64 %indvars.iv
  %15 = load ptr, ptr %gep, align 8, !tbaa !5
  %16 = load i8, ptr %15, align 1, !tbaa !9
  %17 = sext i8 %16 to i32
  %18 = getelementptr inbounds [10 x i32], ptr %3, i64 0, i64 %indvars.iv
  store i32 %17, ptr %18, align 4, !tbaa !10
  %gep31 = getelementptr inbounds ptr, ptr %invariant.gep30, i64 %indvars.iv
  %19 = load ptr, ptr %gep31, align 8, !tbaa !5
  %20 = load i8, ptr %19, align 1, !tbaa !9
  %21 = sext i8 %20 to i32
  %22 = add nuw nsw i64 %indvars.iv, 1
  %23 = getelementptr inbounds [10 x i32], ptr %3, i64 0, i64 %22
  store i32 %21, ptr %23, align 4, !tbaa !10
  %gep33 = getelementptr inbounds ptr, ptr %invariant.gep32, i64 %indvars.iv
  %24 = load ptr, ptr %gep33, align 8, !tbaa !5
  %25 = load i8, ptr %24, align 1, !tbaa !9
  %26 = sext i8 %25 to i32
  %27 = add nuw nsw i64 %indvars.iv, 2
  %28 = getelementptr inbounds [10 x i32], ptr %3, i64 0, i64 %27
  store i32 %26, ptr %28, align 4, !tbaa !10
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %niter.next.3 = add nuw nsw i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %.lr.ph23.preheader.unr-lcssa, label %.lr.ph, !llvm.loop !12

.lr.ph23.preheader.unr-lcssa:                     ; preds = %.lr.ph, %.lr.ph.preheader
  %indvars.iv.unr = phi i64 [ 1, %.lr.ph.preheader ], [ %indvars.iv.next.3, %.lr.ph ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.lr.ph23.preheader, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %.lr.ph23.preheader.unr-lcssa, %.lr.ph.epil
  %indvars.iv.epil = phi i64 [ %indvars.iv.next.epil, %.lr.ph.epil ], [ %indvars.iv.unr, %.lr.ph23.preheader.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.lr.ph.epil ], [ 0, %.lr.ph23.preheader.unr-lcssa ]
  %29 = getelementptr inbounds ptr, ptr %1, i64 %indvars.iv.epil
  %30 = load ptr, ptr %29, align 8, !tbaa !5
  %31 = load i8, ptr %30, align 1, !tbaa !9
  %32 = sext i8 %31 to i32
  %33 = add nsw i64 %indvars.iv.epil, -1
  %34 = getelementptr inbounds [10 x i32], ptr %3, i64 0, i64 %33
  store i32 %32, ptr %34, align 4, !tbaa !10
  %indvars.iv.next.epil = add nuw nsw i64 %indvars.iv.epil, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %.lr.ph23.preheader, label %.lr.ph.epil, !llvm.loop !14

.lr.ph23.preheader:                               ; preds = %.lr.ph.epil, %.lr.ph23.preheader.unr-lcssa
  %35 = getelementptr inbounds ptr, ptr %1, i64 %wide.trip.count
  %36 = load ptr, ptr %35, align 8, !tbaa !5
  %37 = load i8, ptr %36, align 1, !tbaa !9
  %38 = sext i8 %37 to i32
  %39 = tail call i32 @llvm.smax.i32(i32 %0, i32 2)
  %40 = add nsw i32 %39, -1
  %wide.trip.count28 = zext nneg i32 %40 to i64
  br label %.lr.ph23

41:                                               ; preds = %.lr.ph23
  %indvars.iv.next26 = add nuw nsw i64 %indvars.iv25, 1
  %exitcond29.not = icmp eq i64 %indvars.iv.next26, %wide.trip.count28
  br i1 %exitcond29.not, label %.critedge, label %.lr.ph23, !llvm.loop !16

.lr.ph23:                                         ; preds = %.lr.ph23.preheader, %41
  %indvars.iv25 = phi i64 [ 0, %.lr.ph23.preheader ], [ %indvars.iv.next26, %41 ]
  %42 = getelementptr inbounds [10 x i32], ptr %3, i64 0, i64 %indvars.iv25
  %43 = load i32, ptr %42, align 4, !tbaa !10
  %44 = icmp eq i32 %43, %38
  br i1 %44, label %.critedge, label %41

.critedge:                                        ; preds = %.lr.ph23, %41
  %.str.1.sink = phi ptr [ @.str, %41 ], [ @.str.1, %.lr.ph23 ]
  %45 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) %.str.1.sink)
  call void @llvm.lifetime.end.p0(i64 40, ptr nonnull %3) #4
  br label %46

46:                                               ; preds = %2, %.critedge
  %.015 = phi i32 [ 0, %.critedge ], [ 1, %2 ]
  ret i32 %.015
}

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

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

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 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.unroll.disable"}
!16 = distinct !{!16, !13}


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