; LLVM IR from kparc/ksimple :: a (Tak)

; 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.4 = external hidden unnamed_addr constant [5 x i8], align 1
@__FUNCTION__.Tak = external hidden unnamed_addr constant [4 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

; Function Attrs: nounwind uwtable
declare dso_local i64 @err(i64 noundef, i64 noundef, i64 noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local i64 @a(i64 noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local i64 @_r(i64 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i64 @Tak(i64 noundef %0, i64 noundef %1) #1 {
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i32, align 4
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i64, align 8
  %14 = alloca ptr, align 8
  %15 = alloca i64, align 8
  %16 = alloca i64, align 8
  store i64 %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  %17 = load i64, ptr %4, align 8, !tbaa !5
  store i64 %17, ptr %6, align 8, !tbaa !5
  %18 = load i64, ptr %6, align 8, !tbaa !5
  %19 = icmp ugt i64 256, %18
  %20 = zext i1 %19 to i32
  store i32 %20, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  %21 = load i32, ptr %7, align 4, !tbaa !9
  %22 = icmp ne i32 %21, 0
  br i1 %22, label %25, label %23

23:                                               ; preds = %2
  %24 = call i64 @err(i64 noundef ptrtoint (ptr @__FUNCTION__.Tak to i64), i64 noundef 66, i64 noundef ptrtoint (ptr @.str.4 to i64))
  store i64 %24, ptr %3, align 8
  br label %74

25:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  %26 = load i64, ptr %4, align 8, !tbaa !5
  %27 = call i64 @a(i64 noundef %26)
  store i64 %27, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  %28 = load i64, ptr %4, align 8, !tbaa !5
  %29 = trunc i64 %28 to i32
  store i32 %29, ptr %11, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #2
  store i32 0, ptr %12, align 4, !tbaa !9
  br label %30

30:                                               ; preds = %63, %25
  %31 = load i32, ptr %12, align 4, !tbaa !9
  %32 = load i32, ptr %11, align 4, !tbaa !9
  %33 = icmp slt i32 %31, %32
  br i1 %33, label %34, label %66

34:                                               ; preds = %30
  %35 = load i64, ptr %5, align 8, !tbaa !5
  %36 = icmp ugt i64 256, %35
  br i1 %36, label %37, label %39

37:                                               ; preds = %34
  %38 = load i64, ptr %5, align 8, !tbaa !5
  br label %53

39:                                               ; preds = %34
  %40 = load i64, ptr %5, align 8, !tbaa !5
  %41 = inttoptr i64 %40 to ptr
  %42 = load i32, ptr %12, align 4, !tbaa !9
  %43 = load i64, ptr %5, align 8, !tbaa !5
  %44 = inttoptr i64 %43 to ptr
  %45 = getelementptr inbounds i8, ptr %44, i64 -1
  %46 = load i8, ptr %45, align 1, !tbaa !11
  %47 = zext i8 %46 to i32
  %48 = srem i32 %42, %47
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds i8, ptr %41, i64 %49
  %51 = load i8, ptr %50, align 1, !tbaa !11
  %52 = zext i8 %51 to i64
  br label %53

53:                                               ; preds = %39, %37
  %54 = phi i64 [ %38, %37 ], [ %52, %39 ]
  %55 = trunc i64 %54 to i8
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #2
  %56 = load i64, ptr %10, align 8, !tbaa !5
  store i64 %56, ptr %13, align 8, !tbaa !5
  %57 = load i64, ptr %13, align 8, !tbaa !5
  %58 = inttoptr i64 %57 to ptr
  store ptr %58, ptr %14, align 8, !tbaa !12
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #2
  %59 = load ptr, ptr %14, align 8, !tbaa !12
  %60 = load i32, ptr %12, align 4, !tbaa !9
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds i8, ptr %59, i64 %61
  store i8 %55, ptr %62, align 1, !tbaa !11
  br label %63

63:                                               ; preds = %53
  %64 = load i32, ptr %12, align 4, !tbaa !9
  %65 = add nsw i32 %64, 1
  store i32 %65, ptr %12, align 4, !tbaa !9
  br label %30, !llvm.loop !14

66:                                               ; preds = %30
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  %67 = load i64, ptr %10, align 8, !tbaa !5
  store i64 %67, ptr %15, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  %68 = load i64, ptr %15, align 8, !tbaa !5
  store i64 %68, ptr %9, align 8, !tbaa !5
  %69 = load i64, ptr %4, align 8, !tbaa !5
  %70 = call i64 @_r(i64 noundef %69)
  %71 = load i64, ptr %9, align 8, !tbaa !5
  store i64 %71, ptr %16, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  %72 = load i64, ptr %16, align 8, !tbaa !5
  store i64 %72, ptr %8, align 8, !tbaa !5
  %73 = load i64, ptr %8, align 8, !tbaa !5
  store i64 %73, ptr %3, align 8
  br label %74

74:                                               ; preds = %66, %23
  %75 = load i64, ptr %3, align 8
  ret i64 %75
}

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 }

!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 = !{!"long", !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 = !{!7, !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"any pointer", !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"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"

@.str.4 = external hidden unnamed_addr constant [5 x i8], align 1
@__FUNCTION__.Tak = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i64 @err(i64 noundef, i64 noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i64 @a(i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i64 @_r(i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i64 @Tak(i64 noundef %0, i64 noundef %1) local_unnamed_addr #0 {
  %3 = icmp ult i64 %0, 256
  br i1 %3, label %6, label %4

4:                                                ; preds = %2
  %5 = tail call i64 @err(i64 noundef ptrtoint (ptr @__FUNCTION__.Tak to i64), i64 noundef 66, i64 noundef ptrtoint (ptr @.str.4 to i64))
  br label %42

6:                                                ; preds = %2
  %7 = tail call i64 @a(i64 noundef %0)
  %.not = icmp eq i64 %0, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %6
  %8 = icmp ult i64 %1, 256
  %9 = inttoptr i64 %1 to ptr
  %10 = getelementptr inbounds i8, ptr %9, i64 -1
  %11 = inttoptr i64 %7 to ptr
  br i1 %8, label %.lr.ph.split.us, label %.lr.ph.split.preheader

.lr.ph.split.preheader:                           ; preds = %.lr.ph
  %xtraiter = and i64 %0, 1
  %12 = icmp eq i64 %0, 1
  br i1 %12, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.split.preheader.new

.lr.ph.split.preheader.new:                       ; preds = %.lr.ph.split.preheader
  %unroll_iter = and i64 %0, 254
  br label %.lr.ph.split

.lr.ph.split.us:                                  ; preds = %.lr.ph
  %13 = trunc nuw i64 %1 to i8
  %14 = add nuw nsw i64 %0, 4294967295
  %15 = and i64 %14, 4294967295
  %16 = add nuw nsw i64 %15, 1
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 1 dereferenceable(1) %11, i8 %13, i64 %16, i1 false), !tbaa !5
  br label %._crit_edge

.lr.ph.split:                                     ; preds = %.lr.ph.split, %.lr.ph.split.preheader.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.split.preheader.new ], [ %indvars.iv.next.1, %.lr.ph.split ]
  %niter = phi i64 [ 0, %.lr.ph.split.preheader.new ], [ %niter.next.1, %.lr.ph.split ]
  %17 = load i8, ptr %10, align 1, !tbaa !5
  %18 = zext i8 %17 to i32
  %19 = trunc nuw nsw i64 %indvars.iv to i32
  %20 = urem i32 %19, %18
  %21 = zext nneg i32 %20 to i64
  %22 = getelementptr inbounds i8, ptr %9, i64 %21
  %23 = load i8, ptr %22, align 1, !tbaa !5
  %24 = getelementptr inbounds i8, ptr %11, i64 %indvars.iv
  store i8 %23, ptr %24, align 1, !tbaa !5
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %25 = load i8, ptr %10, align 1, !tbaa !5
  %26 = zext i8 %25 to i32
  %27 = trunc nuw nsw i64 %indvars.iv.next to i32
  %28 = urem i32 %27, %26
  %29 = zext nneg i32 %28 to i64
  %30 = getelementptr inbounds i8, ptr %9, i64 %29
  %31 = load i8, ptr %30, align 1, !tbaa !5
  %32 = getelementptr inbounds i8, ptr %11, i64 %indvars.iv.next
  store i8 %31, ptr %32, align 1, !tbaa !5
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.split, !llvm.loop !8

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

.lr.ph.split.epil:                                ; preds = %._crit_edge.loopexit.unr-lcssa
  %33 = load i8, ptr %10, align 1, !tbaa !5
  %34 = zext i8 %33 to i32
  %35 = trunc nuw nsw i64 %indvars.iv.unr to i32
  %36 = urem i32 %35, %34
  %37 = zext nneg i32 %36 to i64
  %38 = getelementptr inbounds i8, ptr %9, i64 %37
  %39 = load i8, ptr %38, align 1, !tbaa !5
  %40 = getelementptr inbounds i8, ptr %11, i64 %indvars.iv.unr
  store i8 %39, ptr %40, align 1, !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph.split.epil, %._crit_edge.loopexit.unr-lcssa, %.lr.ph.split.us, %6
  %41 = tail call i64 @_r(i64 noundef %0)
  br label %42

42:                                               ; preds = %._crit_edge, %4
  %.0 = phi i64 [ %7, %._crit_edge ], [ %5, %4 ]
  ret i64 %.0
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #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 nounwind willreturn memory(argmem: write) }

!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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopIdiomRecognizePass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass