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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local i64 @W(i64 noundef %0) #1 {
  %2 = alloca i64, align 8
  %3 = alloca i64, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i64, align 8
  store i64 %0, ptr %3, align 8, !tbaa !5
  %7 = load i64, ptr %3, align 8, !tbaa !5
  %8 = icmp eq i64 128, %7
  br i1 %8, label %9, label %10

9:                                                ; preds = %1
  store i64 128, ptr %2, align 8
  br label %54

10:                                               ; preds = %1
  %11 = load i64, ptr %3, align 8, !tbaa !5
  %12 = icmp ugt i64 256, %11
  br i1 %12, label %13, label %16

13:                                               ; preds = %10
  %14 = load i64, ptr %3, align 8, !tbaa !5
  %15 = call i64 @wi(i64 noundef %14)
  br label %51

16:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  %17 = load i64, ptr %3, align 8, !tbaa !5
  %18 = inttoptr i64 %17 to ptr
  %19 = getelementptr inbounds i8, ptr %18, i64 -1
  %20 = load i8, ptr %19, align 1, !tbaa !9
  %21 = zext i8 %20 to i32
  store i32 %21, ptr %4, align 4, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  store i32 0, ptr %5, align 4, !tbaa !10
  br label %22

22:                                               ; preds = %47, %16
  %23 = load i32, ptr %5, align 4, !tbaa !10
  %24 = load i32, ptr %4, align 4, !tbaa !10
  %25 = icmp slt i32 %23, %24
  br i1 %25, label %26, label %50

26:                                               ; preds = %22
  %27 = load i64, ptr %3, align 8, !tbaa !5
  %28 = inttoptr i64 %27 to ptr
  %29 = getelementptr inbounds i8, ptr %28, i64 -1
  %30 = load i8, ptr %29, align 1, !tbaa !9
  %31 = zext i8 %30 to i32
  %32 = load i32, ptr %5, align 4, !tbaa !10
  %33 = icmp sgt i32 %31, %32
  br i1 %33, label %34, label %42

34:                                               ; preds = %26
  %35 = load i64, ptr %3, align 8, !tbaa !5
  %36 = inttoptr i64 %35 to ptr
  %37 = load i32, ptr %5, align 4, !tbaa !10
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds i8, ptr %36, i64 %38
  %40 = load i8, ptr %39, align 1, !tbaa !9
  %41 = zext i8 %40 to i32
  br label %43

42:                                               ; preds = %26
  br label %43

43:                                               ; preds = %42, %34
  %44 = phi i32 [ %41, %34 ], [ 0, %42 ]
  %45 = sext i32 %44 to i64
  %46 = call i64 @wi(i64 noundef %45)
  br label %47

47:                                               ; preds = %43
  %48 = load i32, ptr %5, align 4, !tbaa !10
  %49 = add nsw i32 %48, 1
  store i32 %49, ptr %5, align 4, !tbaa !10
  br label %22, !llvm.loop !12

50:                                               ; preds = %22
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  br label %51

51:                                               ; preds = %50, %13
  %52 = call i64 @w(i64 noundef 10)
  store i64 %52, ptr %6, align 8, !tbaa !5
  %53 = load i64, ptr %6, align 8, !tbaa !5
  store i64 %53, ptr %2, align 8
  br label %54

54:                                               ; preds = %51, %9
  %55 = load i64, ptr %2, align 8
  ret i64 %55
}

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 = !{!"int", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"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"

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

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

; Function Attrs: nounwind uwtable
define dso_local i64 @W(i64 noundef %0) local_unnamed_addr #0 {
  %2 = icmp eq i64 %0, 128
  br i1 %2, label %22, label %3

3:                                                ; preds = %1
  %4 = icmp ult i64 %0, 256
  br i1 %4, label %5, label %7

5:                                                ; preds = %3
  %6 = tail call i64 @wi(i64 noundef %0)
  br label %.loopexit

7:                                                ; preds = %3
  %8 = inttoptr i64 %0 to ptr
  %9 = getelementptr inbounds i8, ptr %8, i64 -1
  %10 = load i8, ptr %9, align 1, !tbaa !5
  %.not = icmp eq i8 %10, 0
  br i1 %.not, label %.loopexit, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %7
  %wide.trip.count = zext i8 %10 to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %18
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %18 ]
  %11 = load i8, ptr %9, align 1, !tbaa !5
  %12 = zext i8 %11 to i64
  %13 = icmp ult i64 %indvars.iv, %12
  br i1 %13, label %14, label %18

14:                                               ; preds = %.lr.ph
  %15 = getelementptr inbounds i8, ptr %8, i64 %indvars.iv
  %16 = load i8, ptr %15, align 1, !tbaa !5
  %17 = zext i8 %16 to i64
  br label %18

18:                                               ; preds = %.lr.ph, %14
  %19 = phi i64 [ %17, %14 ], [ 0, %.lr.ph ]
  %20 = tail call i64 @wi(i64 noundef %19)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %.loopexit, label %.lr.ph, !llvm.loop !8

.loopexit:                                        ; preds = %18, %7, %5
  %21 = tail call i64 @w(i64 noundef 10)
  br label %22

22:                                               ; preds = %1, %.loopexit
  %.0 = phi i64 [ %21, %.loopexit ], [ 128, %1 ]
  ret i64 %.0
}

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

!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,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass