; LLVM IR from InductiveComputerScience/infracore :: BPU (prog)

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

%struct.F = type { ptr, i8, i8, i32, i32 }

; Function Attrs: nounwind uwtable
define dso_local void @f(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %4 = getelementptr inbounds %struct.F, ptr %3, i32 0, i32 2
  store i8 0, ptr %4, align 1, !tbaa !9
  %5 = load ptr, ptr %2, align 8, !tbaa !5
  %6 = getelementptr inbounds %struct.F, ptr %5, i32 0, i32 4
  store i32 0, ptr %6, align 8, !tbaa !13
  br label %7

7:                                                ; preds = %52, %1
  %8 = load ptr, ptr %2, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.F, ptr %8, i32 0, i32 0
  %10 = load ptr, ptr %9, align 8, !tbaa !14
  %11 = load ptr, ptr %2, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.F, ptr %11, i32 0, i32 4
  %13 = load i32, ptr %12, align 8, !tbaa !13
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds i8, ptr %10, i64 %14
  %16 = load i8, ptr %15, align 1, !tbaa !15
  %17 = sext i8 %16 to i32
  %18 = icmp ne i32 %17, 0
  br i1 %18, label %19, label %25

19:                                               ; preds = %7
  %20 = load ptr, ptr %2, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.F, ptr %20, i32 0, i32 2
  %22 = load i8, ptr %21, align 1, !tbaa !9, !range !16, !noundef !17
  %23 = trunc i8 %22 to i1
  %24 = xor i1 %23, true
  br label %25

25:                                               ; preds = %19, %7
  %26 = phi i1 [ false, %7 ], [ %24, %19 ]
  br i1 %26, label %27, label %57

27:                                               ; preds = %25
  %28 = load ptr, ptr %2, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.F, ptr %28, i32 0, i32 0
  %30 = load ptr, ptr %29, align 8, !tbaa !14
  %31 = load ptr, ptr %2, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.F, ptr %31, i32 0, i32 4
  %33 = load i32, ptr %32, align 8, !tbaa !13
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds i8, ptr %30, i64 %34
  %36 = load i8, ptr %35, align 1, !tbaa !15
  %37 = sext i8 %36 to i32
  %38 = load ptr, ptr %2, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.F, ptr %38, i32 0, i32 1
  %40 = load i8, ptr %39, align 8, !tbaa !18
  %41 = sext i8 %40 to i32
  %42 = icmp eq i32 %37, %41
  br i1 %42, label %43, label %51

43:                                               ; preds = %27
  %44 = load ptr, ptr %2, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.F, ptr %44, i32 0, i32 2
  store i8 1, ptr %45, align 1, !tbaa !9
  %46 = load ptr, ptr %2, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.F, ptr %46, i32 0, i32 4
  %48 = load i32, ptr %47, align 8, !tbaa !13
  %49 = load ptr, ptr %2, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.F, ptr %49, i32 0, i32 3
  store i32 %48, ptr %50, align 4, !tbaa !19
  br label %51

51:                                               ; preds = %43, %27
  br label %52

52:                                               ; preds = %51
  %53 = load ptr, ptr %2, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.F, ptr %53, i32 0, i32 4
  %55 = load i32, ptr %54, align 8, !tbaa !13
  %56 = add nsw i32 %55, 1
  store i32 %56, ptr %54, align 8, !tbaa !13
  br label %7, !llvm.loop !20

57:                                               ; preds = %25
  ret void
}

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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 9}
!10 = !{!"F", !6, i64 0, !7, i64 8, !11, i64 9, !12, i64 12, !12, i64 16}
!11 = !{!"_Bool", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!10, !12, i64 16}
!14 = !{!10, !6, i64 0}
!15 = !{!7, !7, i64 0}
!16 = !{i8 0, i8 2}
!17 = !{}
!18 = !{!10, !7, i64 8}
!19 = !{!10, !12, i64 12}
!20 = distinct !{!20, !21}
!21 = !{!"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: nofree norecurse nosync nounwind memory(read, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local void @f(ptr nocapture noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 9
  store i8 0, ptr %2, align 1, !tbaa !5
  %3 = getelementptr inbounds i8, ptr %0, i64 16
  %4 = load ptr, ptr %0, align 8, !tbaa !12
  store i32 0, ptr %3, align 8, !tbaa !13
  %5 = load i8, ptr %4, align 1, !tbaa !14
  %.not12 = icmp eq i8 %5, 0
  br i1 %.not12, label %.critedge, label %.lr.ph

.lr.ph:                                           ; preds = %1
  %6 = getelementptr inbounds i8, ptr %0, i64 8
  %7 = getelementptr inbounds i8, ptr %0, i64 12
  br label %8

8:                                                ; preds = %.lr.ph, %17
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %17 ]
  %9 = phi i8 [ 0, %.lr.ph ], [ %18, %17 ]
  %10 = phi i8 [ %5, %.lr.ph ], [ %21, %17 ]
  %11 = trunc nuw i8 %9 to i1
  br i1 %11, label %.critedge, label %12

12:                                               ; preds = %8
  %13 = load i8, ptr %6, align 8, !tbaa !15
  %14 = icmp eq i8 %10, %13
  br i1 %14, label %15, label %17

15:                                               ; preds = %12
  store i8 1, ptr %2, align 1, !tbaa !5
  %16 = trunc nuw nsw i64 %indvars.iv to i32
  store i32 %16, ptr %7, align 4, !tbaa !16
  br label %17

17:                                               ; preds = %12, %15
  %18 = phi i8 [ %9, %12 ], [ 1, %15 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %19 = trunc nuw i64 %indvars.iv.next to i32
  store i32 %19, ptr %3, align 8, !tbaa !13
  %20 = getelementptr inbounds i8, ptr %4, i64 %indvars.iv.next
  %21 = load i8, ptr %20, align 1, !tbaa !14
  %.not = icmp eq i8 %21, 0
  br i1 %.not, label %.critedge, label %8, !llvm.loop !17

.critedge:                                        ; preds = %8, %17, %1
  ret void
}

attributes #0 = { nofree norecurse nosync nounwind memory(read, argmem: readwrite, inaccessiblemem: none) 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, !10, i64 9}
!6 = !{!"F", !7, i64 0, !8, i64 8, !10, i64 9, !11, i64 12, !11, i64 16}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"_Bool", !8, i64 0}
!11 = !{!"int", !8, i64 0}
!12 = !{!6, !7, i64 0}
!13 = !{!6, !11, i64 16}
!14 = !{!8, !8, i64 0}
!15 = !{!6, !8, i64 8}
!16 = !{!6, !11, i64 12}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass