; LLVM IR from sysprog21/shecc :: src (ssa)

; 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.basic_block = type { %struct.insn_list_t, %struct.ph2_ir_list_t, [128 x %struct.bb_connection_t], ptr, ptr, ptr, ptr, ptr, ptr, ptr, [800 x ptr], i32, [800 x ptr], i32, [800 x ptr], i32, [800 x ptr], i32, i32, i32, [64 x ptr], [64 x ptr], i32, i32, i32, i8, [64 x ptr], ptr, [256 x ptr], ptr, ptr, ptr, %struct.symbol_list_t, i32 }
%struct.insn_list_t = type { ptr, ptr }
%struct.ph2_ir_list_t = type { ptr, ptr }
%struct.bb_connection_t = type { ptr, i32 }
%struct.symbol_list_t = type { ptr, ptr }
%struct.insn = type { ptr, ptr, i32, i32, ptr, ptr, ptr, i32, i8, ptr, ptr, [64 x i8] }

@INSN_ARENA = external dso_local global ptr, align 8

; 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 ptr @arena_alloc(ptr noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @insert_phi_insn(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca i1, align 1
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i8, align 1
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %6) #2
  store i8 0, ptr %6, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.basic_block, ptr %11, i32 0, i32 0
  %13 = getelementptr inbounds %struct.insn_list_t, ptr %12, i32 0, i32 0
  %14 = load ptr, ptr %13, align 8, !tbaa !11
  store ptr %14, ptr %7, align 8, !tbaa !5
  br label %15

15:                                               ; preds = %32, %2
  %16 = load ptr, ptr %7, align 8, !tbaa !5
  %17 = icmp ne ptr %16, null
  br i1 %17, label %19, label %18

18:                                               ; preds = %15
  store i32 2, ptr %8, align 4
  br label %36

19:                                               ; preds = %15
  %20 = load ptr, ptr %7, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.insn, ptr %20, i32 0, i32 3
  %22 = load i32, ptr %21, align 4, !tbaa !15
  %23 = icmp eq i32 %22, 1
  br i1 %23, label %24, label %31

24:                                               ; preds = %19
  %25 = load ptr, ptr %7, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.insn, ptr %25, i32 0, i32 4
  %27 = load ptr, ptr %26, align 8, !tbaa !17
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = icmp eq ptr %27, %28
  br i1 %29, label %30, label %31

30:                                               ; preds = %24
  store i8 1, ptr %6, align 1, !tbaa !9
  store i32 2, ptr %8, align 4
  br label %36

31:                                               ; preds = %24, %19
  br label %32

32:                                               ; preds = %31
  %33 = load ptr, ptr %7, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.insn, ptr %33, i32 0, i32 0
  %35 = load ptr, ptr %34, align 8, !tbaa !18
  store ptr %35, ptr %7, align 8, !tbaa !5
  br label %15, !llvm.loop !19

36:                                               ; preds = %30, %18
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  br label %37

37:                                               ; preds = %36
  %38 = load i8, ptr %6, align 1, !tbaa !9, !range !21, !noundef !22
  %39 = trunc i8 %38 to i1
  br i1 %39, label %40, label %41

40:                                               ; preds = %37
  store i1 false, ptr %3, align 1
  store i32 1, ptr %8, align 4
  br label %82

41:                                               ; preds = %37
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.basic_block, ptr %42, i32 0, i32 0
  %44 = getelementptr inbounds %struct.insn_list_t, ptr %43, i32 0, i32 0
  %45 = load ptr, ptr %44, align 8, !tbaa !11
  store ptr %45, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  %46 = load ptr, ptr @INSN_ARENA, align 8, !tbaa !5
  %47 = call ptr @arena_alloc(ptr noundef %46, i32 noundef 136)
  store ptr %47, ptr %10, align 8, !tbaa !5
  %48 = load ptr, ptr %10, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.insn, ptr %48, i32 0, i32 3
  store i32 1, ptr %49, align 4, !tbaa !15
  %50 = load ptr, ptr %5, align 8, !tbaa !5
  %51 = load ptr, ptr %10, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.insn, ptr %51, i32 0, i32 4
  store ptr %50, ptr %52, align 8, !tbaa !17
  %53 = load ptr, ptr %5, align 8, !tbaa !5
  %54 = load ptr, ptr %10, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.insn, ptr %54, i32 0, i32 5
  store ptr %53, ptr %55, align 8, !tbaa !23
  %56 = load ptr, ptr %5, align 8, !tbaa !5
  %57 = load ptr, ptr %10, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.insn, ptr %57, i32 0, i32 6
  store ptr %56, ptr %58, align 8, !tbaa !24
  %59 = load ptr, ptr %9, align 8, !tbaa !5
  %60 = icmp ne ptr %59, null
  br i1 %60, label %70, label %61

61:                                               ; preds = %41
  %62 = load ptr, ptr %10, align 8, !tbaa !5
  %63 = load ptr, ptr %4, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.basic_block, ptr %63, i32 0, i32 0
  %65 = getelementptr inbounds %struct.insn_list_t, ptr %64, i32 0, i32 0
  store ptr %62, ptr %65, align 8, !tbaa !11
  %66 = load ptr, ptr %10, align 8, !tbaa !5
  %67 = load ptr, ptr %4, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.basic_block, ptr %67, i32 0, i32 0
  %69 = getelementptr inbounds %struct.insn_list_t, ptr %68, i32 0, i32 1
  store ptr %66, ptr %69, align 8, !tbaa !25
  br label %81

70:                                               ; preds = %41
  %71 = load ptr, ptr %10, align 8, !tbaa !5
  %72 = load ptr, ptr %9, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.insn, ptr %72, i32 0, i32 1
  store ptr %71, ptr %73, align 8, !tbaa !26
  %74 = load ptr, ptr %9, align 8, !tbaa !5
  %75 = load ptr, ptr %10, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.insn, ptr %75, i32 0, i32 0
  store ptr %74, ptr %76, align 8, !tbaa !18
  %77 = load ptr, ptr %10, align 8, !tbaa !5
  %78 = load ptr, ptr %4, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.basic_block, ptr %78, i32 0, i32 0
  %80 = getelementptr inbounds %struct.insn_list_t, ptr %79, i32 0, i32 0
  store ptr %77, ptr %80, align 8, !tbaa !11
  br label %81

81:                                               ; preds = %70, %61
  store i1 true, ptr %3, align 1
  store i32 1, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  br label %82

82:                                               ; preds = %81, %40
  call void @llvm.lifetime.end.p0(i64 1, ptr %6) #2
  %83 = load i1, ptr %3, align 1
  ret i1 %83
}

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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"_Bool", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"basic_block", !13, i64 0, !13, i64 16, !7, i64 32, !6, i64 2080, !6, i64 2088, !6, i64 2096, !6, i64 2104, !6, i64 2112, !6, i64 2120, !6, i64 2128, !7, i64 2136, !14, i64 8536, !7, i64 8544, !14, i64 14944, !7, i64 14952, !14, i64 21352, !7, i64 21360, !14, i64 27760, !14, i64 27764, !14, i64 27768, !7, i64 27776, !7, i64 28288, !14, i64 28800, !14, i64 28804, !14, i64 28808, !10, i64 28812, !7, i64 28816, !6, i64 29328, !7, i64 29336, !6, i64 31384, !6, i64 31392, !6, i64 31400, !13, i64 31408, !14, i64 31424}
!13 = !{!"", !6, i64 0, !6, i64 8}
!14 = !{!"int", !7, i64 0}
!15 = !{!16, !14, i64 20}
!16 = !{!"insn", !6, i64 0, !6, i64 8, !14, i64 16, !14, i64 20, !6, i64 24, !6, i64 32, !6, i64 40, !14, i64 48, !10, i64 52, !6, i64 56, !6, i64 64, !7, i64 72}
!17 = !{!16, !6, i64 24}
!18 = !{!16, !6, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = !{i8 0, i8 2}
!22 = !{}
!23 = !{!16, !6, i64 32}
!24 = !{!16, !6, i64 40}
!25 = !{!12, !6, i64 8}
!26 = !{!16, !6, i64 8}


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

@INSN_ARENA = external dso_local local_unnamed_addr global ptr, align 8

; Function Attrs: nounwind uwtable
declare dso_local ptr @arena_alloc(ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local noundef zeroext i1 @insert_phi_insn(ptr nocapture noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %.02731 = load ptr, ptr %0, align 8, !tbaa !5
  %.not.not32 = icmp eq ptr %.02731, null
  br i1 %.not.not32, label %.critedge, label %.lr.ph

.lr.ph:                                           ; preds = %2, %10
  %.02733 = phi ptr [ %.027, %10 ], [ %.02731, %2 ]
  %3 = getelementptr inbounds i8, ptr %.02733, i64 20
  %4 = load i32, ptr %3, align 4, !tbaa !9
  %5 = icmp eq i32 %4, 1
  br i1 %5, label %6, label %10

6:                                                ; preds = %.lr.ph
  %7 = getelementptr inbounds i8, ptr %.02733, i64 24
  %8 = load ptr, ptr %7, align 8, !tbaa !13
  %9 = icmp eq ptr %8, %1
  br i1 %9, label %.loopexit, label %10

10:                                               ; preds = %.lr.ph, %6
  %.027 = load ptr, ptr %.02733, align 8, !tbaa !5
  %.not.not = icmp eq ptr %.027, null
  br i1 %.not.not, label %.critedge, label %.lr.ph, !llvm.loop !14

.critedge:                                        ; preds = %10, %2
  %11 = load ptr, ptr @INSN_ARENA, align 8, !tbaa !5
  %12 = tail call ptr @arena_alloc(ptr noundef %11, i32 noundef 136)
  %13 = getelementptr inbounds i8, ptr %12, i64 20
  store i32 1, ptr %13, align 4, !tbaa !9
  %14 = getelementptr inbounds i8, ptr %12, i64 24
  store ptr %1, ptr %14, align 8, !tbaa !13
  %15 = getelementptr inbounds i8, ptr %12, i64 32
  store ptr %1, ptr %15, align 8, !tbaa !16
  %16 = getelementptr inbounds i8, ptr %12, i64 40
  store ptr %1, ptr %16, align 8, !tbaa !17
  br i1 %.not.not32, label %17, label %19

17:                                               ; preds = %.critedge
  store ptr %12, ptr %0, align 8, !tbaa !18
  %18 = getelementptr inbounds i8, ptr %0, i64 8
  br label %.loopexit.sink.split

19:                                               ; preds = %.critedge
  %20 = getelementptr inbounds i8, ptr %.02731, i64 8
  store ptr %12, ptr %20, align 8, !tbaa !21
  store ptr %.02731, ptr %12, align 8, !tbaa !22
  br label %.loopexit.sink.split

.loopexit.sink.split:                             ; preds = %19, %17
  %.sink = phi ptr [ %18, %17 ], [ %0, %19 ]
  store ptr %12, ptr %.sink, align 8, !tbaa !5
  br label %.loopexit

.loopexit:                                        ; preds = %6, %.loopexit.sink.split
  %.not.not30 = phi i1 [ true, %.loopexit.sink.split ], [ false, %6 ]
  ret i1 %.not.not30
}

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 20}
!10 = !{!"insn", !6, i64 0, !6, i64 8, !11, i64 16, !11, i64 20, !6, i64 24, !6, i64 32, !6, i64 40, !11, i64 48, !12, i64 52, !6, i64 56, !6, i64 64, !7, i64 72}
!11 = !{!"int", !7, i64 0}
!12 = !{!"_Bool", !7, i64 0}
!13 = !{!10, !6, i64 24}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!10, !6, i64 32}
!17 = !{!10, !6, i64 40}
!18 = !{!19, !6, i64 0}
!19 = !{!"basic_block", !20, i64 0, !20, i64 16, !7, i64 32, !6, i64 2080, !6, i64 2088, !6, i64 2096, !6, i64 2104, !6, i64 2112, !6, i64 2120, !6, i64 2128, !7, i64 2136, !11, i64 8536, !7, i64 8544, !11, i64 14944, !7, i64 14952, !11, i64 21352, !7, i64 21360, !11, i64 27760, !11, i64 27764, !11, i64 27768, !7, i64 27776, !7, i64 28288, !11, i64 28800, !11, i64 28804, !11, i64 28808, !12, i64 28812, !7, i64 28816, !6, i64 29328, !7, i64 29336, !6, i64 31384, !6, i64 31392, !6, i64 31400, !20, i64 31408, !11, i64 31424}
!20 = !{!"", !6, i64 0, !6, i64 8}
!21 = !{!10, !6, i64 8}
!22 = !{!10, !6, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass