; LLVM IR from BartoszMilewski/Okasaki :: TripleC (triple)

; 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 [12 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @triples(i32 noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store i32 %0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 0, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store i32 1, ptr %4, align 4, !tbaa !5
  br label %8

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

9:                                                ; preds = %51, %8
  %10 = load i32, ptr %5, align 4, !tbaa !5
  %11 = load i32, ptr %4, align 4, !tbaa !5
  %12 = icmp sle i32 %10, %11
  br i1 %12, label %14, label %13

13:                                               ; preds = %9
  store i32 5, ptr %6, align 4
  br label %54

14:                                               ; preds = %9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %15 = load i32, ptr %5, align 4, !tbaa !5
  store i32 %15, ptr %7, align 4, !tbaa !5
  br label %16

16:                                               ; preds = %45, %14
  %17 = load i32, ptr %7, align 4, !tbaa !5
  %18 = load i32, ptr %4, align 4, !tbaa !5
  %19 = icmp sle i32 %17, %18
  br i1 %19, label %21, label %20

20:                                               ; preds = %16
  store i32 8, ptr %6, align 4
  br label %48

21:                                               ; preds = %16
  %22 = load i32, ptr %5, align 4, !tbaa !5
  %23 = load i32, ptr %5, align 4, !tbaa !5
  %24 = mul nsw i32 %22, %23
  %25 = load i32, ptr %7, align 4, !tbaa !5
  %26 = load i32, ptr %7, align 4, !tbaa !5
  %27 = mul nsw i32 %25, %26
  %28 = add nsw i32 %24, %27
  %29 = load i32, ptr %4, align 4, !tbaa !5
  %30 = load i32, ptr %4, align 4, !tbaa !5
  %31 = mul nsw i32 %29, %30
  %32 = icmp eq i32 %28, %31
  br i1 %32, label %33, label %44

33:                                               ; preds = %21
  %34 = load i32, ptr %5, align 4, !tbaa !5
  %35 = load i32, ptr %7, align 4, !tbaa !5
  %36 = load i32, ptr %4, align 4, !tbaa !5
  %37 = call i32 (ptr, ...) @printf(ptr noundef @.str, i32 noundef %34, i32 noundef %35, i32 noundef %36)
  %38 = load i32, ptr %3, align 4, !tbaa !5
  %39 = add nsw i32 %38, 1
  store i32 %39, ptr %3, align 4, !tbaa !5
  %40 = load i32, ptr %2, align 4, !tbaa !5
  %41 = icmp eq i32 %39, %40
  br i1 %41, label %42, label %43

42:                                               ; preds = %33
  store i32 1, ptr %6, align 4
  br label %48

43:                                               ; preds = %33
  br label %44

44:                                               ; preds = %43, %21
  br label %45

45:                                               ; preds = %44
  %46 = load i32, ptr %7, align 4, !tbaa !5
  %47 = add nsw i32 %46, 1
  store i32 %47, ptr %7, align 4, !tbaa !5
  br label %16, !llvm.loop !9

48:                                               ; preds = %42, %20
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  %49 = load i32, ptr %6, align 4
  switch i32 %49, label %54 [
    i32 8, label %50
  ]

50:                                               ; preds = %48
  br label %51

51:                                               ; preds = %50
  %52 = load i32, ptr %5, align 4, !tbaa !5
  %53 = add nsw i32 %52, 1
  store i32 %53, ptr %5, align 4, !tbaa !5
  br label %9, !llvm.loop !11

54:                                               ; preds = %48, %13
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  %55 = load i32, ptr %6, align 4
  switch i32 %55, label %60 [
    i32 5, label %56
  ]

56:                                               ; preds = %54
  br label %57

57:                                               ; preds = %56
  %58 = load i32, ptr %4, align 4, !tbaa !5
  %59 = add nsw i32 %58, 1
  store i32 %59, ptr %4, align 4, !tbaa !5
  br label %8

60:                                               ; preds = %54
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  ret void
}

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


; 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 [12 x i8], align 1

; Function Attrs: nofree nounwind uwtable
define dso_local void @triples(i32 noundef %0) local_unnamed_addr #0 {
  br label %2

2:                                                ; preds = %.thread32, %1
  %indvars.iv = phi i32 [ %indvars.iv.next, %.thread32 ], [ 2, %1 ]
  %.025 = phi i32 [ %.3, %.thread32 ], [ 0, %1 ]
  %.024 = phi i32 [ %17, %.thread32 ], [ 1, %1 ]
  %3 = mul nuw nsw i32 %.024, %.024
  br label %.preheader

.preheader:                                       ; preds = %2, %15
  %.02340 = phi i32 [ 1, %2 ], [ %16, %15 ]
  %.12639 = phi i32 [ %.025, %2 ], [ %.3, %15 ]
  %4 = mul nuw nsw i32 %.02340, %.02340
  br label %5

5:                                                ; preds = %.preheader, %13
  %.038 = phi i32 [ %.02340, %.preheader ], [ %14, %13 ]
  %.237 = phi i32 [ %.12639, %.preheader ], [ %.3, %13 ]
  %6 = mul nuw nsw i32 %.038, %.038
  %7 = add nuw nsw i32 %6, %4
  %8 = icmp eq i32 %7, %3
  br i1 %8, label %9, label %13

9:                                                ; preds = %5
  %10 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %.02340, i32 noundef %.038, i32 noundef %.024)
  %11 = add nsw i32 %.237, 1
  %12 = icmp eq i32 %11, %0
  br i1 %12, label %18, label %13

13:                                               ; preds = %5, %9
  %.3 = phi i32 [ %11, %9 ], [ %.237, %5 ]
  %14 = add nuw i32 %.038, 1
  %exitcond.not = icmp eq i32 %14, %indvars.iv
  br i1 %exitcond.not, label %15, label %5, !llvm.loop !5

15:                                               ; preds = %13
  %16 = add nuw i32 %.02340, 1
  %exitcond41.not = icmp eq i32 %16, %indvars.iv
  br i1 %exitcond41.not, label %.thread32, label %.preheader, !llvm.loop !7

.thread32:                                        ; preds = %15
  %17 = add nuw nsw i32 %.024, 1
  %indvars.iv.next = add nuw i32 %indvars.iv, 1
  br label %2

18:                                               ; preds = %9
  ret void
}

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

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

!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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = distinct !{!7, !6}


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