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

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

@F = external dso_local global [12 x ptr], align 16

; 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 @a(i64 noundef) #1

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

; Function Attrs: nounwind uwtable
define dso_local i64 @Scn(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 i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i64, align 8
  %13 = alloca ptr, align 8
  %14 = alloca i64, align 8
  %15 = alloca ptr, align 8
  %16 = alloca i64, align 8
  %17 = alloca i64, align 8
  store i64 %0, ptr %3, align 8, !tbaa !5
  store i64 %1, ptr %4, align 8, !tbaa !5
  %18 = load i64, ptr %4, align 8, !tbaa !5
  %19 = icmp ugt i64 256, %18
  br i1 %19, label %20, label %22

20:                                               ; preds = %2
  %21 = load i64, ptr %4, align 8, !tbaa !5
  br label %87

22:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %23 = load i64, ptr %4, align 8, !tbaa !5
  %24 = inttoptr i64 %23 to ptr
  %25 = getelementptr inbounds i8, ptr %24, i64 -1
  %26 = load i8, ptr %25, align 1, !tbaa !9
  %27 = zext i8 %26 to i64
  %28 = call i64 @a(i64 noundef %27)
  store i64 %28, ptr %7, align 8, !tbaa !5
  %29 = load i64, ptr %4, align 8, !tbaa !5
  %30 = inttoptr i64 %29 to ptr
  %31 = load i8, ptr %30, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  %32 = load i64, ptr %7, align 8, !tbaa !5
  store i64 %32, ptr %8, align 8, !tbaa !5
  %33 = load i64, ptr %8, align 8, !tbaa !5
  %34 = inttoptr i64 %33 to ptr
  store ptr %34, ptr %9, align 8, !tbaa !10
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  %35 = load ptr, ptr %9, align 8, !tbaa !10
  store i8 %31, ptr %35, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  %36 = load i64, ptr %4, align 8, !tbaa !5
  %37 = inttoptr i64 %36 to ptr
  %38 = getelementptr inbounds i8, ptr %37, i64 -1
  %39 = load i8, ptr %38, align 1, !tbaa !9
  %40 = zext i8 %39 to i32
  %41 = sub nsw i32 %40, 1
  store i32 %41, ptr %10, align 4, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  store i32 0, ptr %11, align 4, !tbaa !12
  br label %42

42:                                               ; preds = %77, %22
  %43 = load i32, ptr %11, align 4, !tbaa !12
  %44 = load i32, ptr %10, align 4, !tbaa !12
  %45 = icmp slt i32 %43, %44
  br i1 %45, label %46, label %80

46:                                               ; preds = %42
  %47 = load i64, ptr %3, align 8, !tbaa !5
  %48 = getelementptr inbounds [12 x ptr], ptr @F, i64 0, i64 %47
  %49 = load ptr, ptr %48, align 8, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #2
  %50 = load i64, ptr %7, align 8, !tbaa !5
  store i64 %50, ptr %12, align 8, !tbaa !5
  %51 = load i64, ptr %12, align 8, !tbaa !5
  %52 = inttoptr i64 %51 to ptr
  store ptr %52, ptr %13, align 8, !tbaa !10
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #2
  %53 = load ptr, ptr %13, align 8, !tbaa !10
  %54 = load i32, ptr %11, align 4, !tbaa !12
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds i8, ptr %53, i64 %55
  %57 = load i8, ptr %56, align 1, !tbaa !9
  %58 = zext i8 %57 to i64
  %59 = load i64, ptr %4, align 8, !tbaa !5
  %60 = inttoptr i64 %59 to ptr
  %61 = load i32, ptr %11, align 4, !tbaa !12
  %62 = add nsw i32 %61, 1
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds i8, ptr %60, i64 %63
  %65 = load i8, ptr %64, align 1, !tbaa !9
  %66 = zext i8 %65 to i64
  %67 = call i64 %49(i64 noundef %58, i64 noundef %66)
  %68 = trunc i64 %67 to i8
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #2
  %69 = load i64, ptr %7, align 8, !tbaa !5
  store i64 %69, ptr %14, align 8, !tbaa !5
  %70 = load i64, ptr %14, align 8, !tbaa !5
  %71 = inttoptr i64 %70 to ptr
  store ptr %71, ptr %15, align 8, !tbaa !10
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #2
  %72 = load ptr, ptr %15, align 8, !tbaa !10
  %73 = load i32, ptr %11, align 4, !tbaa !12
  %74 = add nsw i32 %73, 1
  %75 = sext i32 %74 to i64
  %76 = getelementptr inbounds i8, ptr %72, i64 %75
  store i8 %68, ptr %76, align 1, !tbaa !9
  br label %77

77:                                               ; preds = %46
  %78 = load i32, ptr %11, align 4, !tbaa !12
  %79 = add nsw i32 %78, 1
  store i32 %79, ptr %11, align 4, !tbaa !12
  br label %42, !llvm.loop !14

80:                                               ; preds = %42
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  %81 = load i64, ptr %7, align 8, !tbaa !5
  store i64 %81, ptr %16, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  %82 = load i64, ptr %16, align 8, !tbaa !5
  store i64 %82, ptr %6, align 8, !tbaa !5
  %83 = load i64, ptr %4, align 8, !tbaa !5
  %84 = call i64 @_r(i64 noundef %83)
  %85 = load i64, ptr %6, align 8, !tbaa !5
  store i64 %85, ptr %17, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  %86 = load i64, ptr %17, align 8, !tbaa !5
  br label %87

87:                                               ; preds = %80, %20
  %88 = phi i64 [ %21, %20 ], [ %86, %80 ]
  store i64 %88, ptr %5, align 8, !tbaa !5
  %89 = load i64, ptr %5, align 8, !tbaa !5
  ret i64 %89
}

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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !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"

@F = external dso_local local_unnamed_addr global [12 x ptr], align 16

; 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 @Scn(i64 noundef %0, i64 noundef %1) local_unnamed_addr #0 {
  %3 = icmp ult i64 %1, 256
  br i1 %3, label %28, label %4

4:                                                ; preds = %2
  %5 = inttoptr i64 %1 to ptr
  %6 = getelementptr inbounds i8, ptr %5, i64 -1
  %7 = load i8, ptr %6, align 1, !tbaa !5
  %8 = zext i8 %7 to i64
  %9 = tail call i64 @a(i64 noundef %8)
  %10 = load i8, ptr %5, align 1, !tbaa !5
  %11 = inttoptr i64 %9 to ptr
  store i8 %10, ptr %11, align 1, !tbaa !5
  %12 = load i8, ptr %6, align 1, !tbaa !5
  %13 = icmp ugt i8 %12, 1
  br i1 %13, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %4
  %14 = zext i8 %12 to i64
  %15 = add nuw nsw i64 %14, 4294967295
  %16 = getelementptr inbounds [12 x ptr], ptr @F, i64 0, i64 %0
  %wide.trip.count = and i64 %15, 4294967295
  br label %17

17:                                               ; preds = %.lr.ph, %17
  %18 = phi i8 [ %10, %.lr.ph ], [ %25, %17 ]
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %17 ]
  %19 = load ptr, ptr %16, align 8, !tbaa !8
  %20 = zext i8 %18 to i64
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %21 = getelementptr inbounds i8, ptr %5, i64 %indvars.iv.next
  %22 = load i8, ptr %21, align 1, !tbaa !5
  %23 = zext i8 %22 to i64
  %24 = tail call i64 %19(i64 noundef %20, i64 noundef %23) #1
  %25 = trunc i64 %24 to i8
  %26 = getelementptr inbounds i8, ptr %11, i64 %indvars.iv.next
  store i8 %25, ptr %26, align 1, !tbaa !5
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %17, !llvm.loop !10

._crit_edge:                                      ; preds = %17, %4
  %27 = tail call i64 @_r(i64 noundef %1)
  br label %28

28:                                               ; preds = %2, %._crit_edge
  %29 = phi i64 [ %9, %._crit_edge ], [ %1, %2 ]
  ret i64 %29
}

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


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass