; 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.type = type { [32 x i8], i32, ptr, i32, [64 x %struct.var], i32 }
%struct.var = type { [32 x i8], [32 x i8], i32, i8, i8, i32, i32, i32, i32, i32, ptr, i32, [64 x ptr], i32, %struct.rename_t, %struct.ref_block_list, ptr, ptr, ptr, i32, i8, i8, i8 }
%struct.rename_t = type { i32, [64 x i32], i32 }
%struct.ref_block_list = type { ptr, ptr }

@types_idx = external dso_local global i32, align 4
@TYPES = 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 willreturn memory(read)
declare i32 @strcmp(ptr noundef, ptr noundef) #1

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

8:                                                ; preds = %85, %2
  %9 = load i32, ptr %6, align 4, !tbaa !9
  %10 = load i32, ptr @types_idx, align 4, !tbaa !9
  %11 = icmp slt i32 %9, %10
  br i1 %11, label %13, label %12

12:                                               ; preds = %8
  store i32 2, ptr %7, align 4
  br label %88

13:                                               ; preds = %8
  %14 = load ptr, ptr @TYPES, align 8, !tbaa !5
  %15 = load i32, ptr %6, align 4, !tbaa !9
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds %struct.type, ptr %14, i64 %16
  %18 = getelementptr inbounds %struct.type, ptr %17, i32 0, i32 1
  %19 = load i32, ptr %18, align 8, !tbaa !11
  %20 = icmp eq i32 %19, 3
  br i1 %20, label %21, label %41

21:                                               ; preds = %13
  %22 = load i32, ptr %5, align 4, !tbaa !9
  %23 = icmp eq i32 %22, 1
  br i1 %23, label %24, label %25

24:                                               ; preds = %21
  br label %85

25:                                               ; preds = %21
  %26 = load ptr, ptr @TYPES, align 8, !tbaa !5
  %27 = load i32, ptr %6, align 4, !tbaa !9
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds %struct.type, ptr %26, i64 %28
  %30 = getelementptr inbounds %struct.type, ptr %29, i32 0, i32 0
  %31 = getelementptr inbounds [32 x i8], ptr %30, i64 0, i64 0
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = call i32 @strcmp(ptr noundef %31, ptr noundef %32) #4
  %34 = icmp ne i32 %33, 0
  br i1 %34, label %40, label %35

35:                                               ; preds = %25
  %36 = load ptr, ptr @TYPES, align 8, !tbaa !5
  %37 = load i32, ptr %6, align 4, !tbaa !9
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds %struct.type, ptr %36, i64 %38
  store ptr %39, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %88

40:                                               ; preds = %25
  br label %84

41:                                               ; preds = %13
  %42 = load i32, ptr %5, align 4, !tbaa !9
  %43 = icmp eq i32 %42, 2
  br i1 %43, label %44, label %45

44:                                               ; preds = %41
  br label %85

45:                                               ; preds = %41
  %46 = load ptr, ptr @TYPES, align 8, !tbaa !5
  %47 = load i32, ptr %6, align 4, !tbaa !9
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds %struct.type, ptr %46, i64 %48
  %50 = getelementptr inbounds %struct.type, ptr %49, i32 0, i32 0
  %51 = getelementptr inbounds [32 x i8], ptr %50, i64 0, i64 0
  %52 = load ptr, ptr %4, align 8, !tbaa !5
  %53 = call i32 @strcmp(ptr noundef %51, ptr noundef %52) #4
  %54 = icmp ne i32 %53, 0
  br i1 %54, label %83, label %55

55:                                               ; preds = %45
  %56 = load ptr, ptr @TYPES, align 8, !tbaa !5
  %57 = load i32, ptr %6, align 4, !tbaa !9
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds %struct.type, ptr %56, i64 %58
  %60 = getelementptr inbounds %struct.type, ptr %59, i32 0, i32 1
  %61 = load i32, ptr %60, align 8, !tbaa !11
  %62 = icmp eq i32 %61, 4
  br i1 %62, label %63, label %78

63:                                               ; preds = %55
  %64 = load ptr, ptr @TYPES, align 8, !tbaa !5
  %65 = load i32, ptr %6, align 4, !tbaa !9
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds %struct.type, ptr %64, i64 %66
  %68 = getelementptr inbounds %struct.type, ptr %67, i32 0, i32 3
  %69 = load i32, ptr %68, align 8, !tbaa !13
  %70 = icmp eq i32 %69, 0
  br i1 %70, label %71, label %78

71:                                               ; preds = %63
  %72 = load ptr, ptr @TYPES, align 8, !tbaa !5
  %73 = load i32, ptr %6, align 4, !tbaa !9
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds %struct.type, ptr %72, i64 %74
  %76 = getelementptr inbounds %struct.type, ptr %75, i32 0, i32 2
  %77 = load ptr, ptr %76, align 8, !tbaa !14
  store ptr %77, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %88

78:                                               ; preds = %63, %55
  %79 = load ptr, ptr @TYPES, align 8, !tbaa !5
  %80 = load i32, ptr %6, align 4, !tbaa !9
  %81 = sext i32 %80 to i64
  %82 = getelementptr inbounds %struct.type, ptr %79, i64 %81
  store ptr %82, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %88

83:                                               ; preds = %45
  br label %84

84:                                               ; preds = %83, %40
  br label %85

85:                                               ; preds = %84, %44, %24
  %86 = load i32, ptr %6, align 4, !tbaa !9
  %87 = add nsw i32 %86, 1
  store i32 %87, ptr %6, align 4, !tbaa !9
  br label %8, !llvm.loop !15

88:                                               ; preds = %78, %71, %35, %12
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  %89 = load i32, ptr %7, align 4
  switch i32 %89, label %93 [
    i32 2, label %90
    i32 1, label %91
  ]

90:                                               ; preds = %88
  store ptr null, ptr %3, align 8
  br label %91

91:                                               ; preds = %90, %88
  %92 = load ptr, ptr %3, align 8
  ret ptr %92

93:                                               ; preds = %88
  unreachable
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind willreturn memory(read) "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 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 #3 = { nounwind }
attributes #4 = { nounwind willreturn memory(read) }

!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 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 32}
!12 = !{!"type", !7, i64 0, !10, i64 32, !6, i64 40, !10, i64 48, !7, i64 56, !10, i64 60472}
!13 = !{!12, !10, i64 48}
!14 = !{!12, !6, i64 40}
!15 = distinct !{!15, !16}
!16 = !{!"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"

%struct.type = type { [32 x i8], i32, ptr, i32, [64 x %struct.var], i32 }
%struct.var = type { [32 x i8], [32 x i8], i32, i8, i8, i32, i32, i32, i32, i32, ptr, i32, [64 x ptr], i32, %struct.rename_t, %struct.ref_block_list, ptr, ptr, ptr, i32, i8, i8, i8 }
%struct.rename_t = type { i32, [64 x i32], i32 }
%struct.ref_block_list = type { ptr, ptr }

@types_idx = external dso_local local_unnamed_addr global i32, align 4
@TYPES = external dso_local local_unnamed_addr global ptr, align 8

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i32 @strcmp(ptr nocapture noundef, ptr nocapture noundef) local_unnamed_addr #0

; Function Attrs: nofree nounwind memory(read, inaccessiblemem: none) uwtable
define dso_local ptr @find_type(ptr nocapture noundef readonly %0, i32 noundef %1) local_unnamed_addr #1 {
  %3 = load i32, ptr @types_idx, align 4, !tbaa !5
  %.not1921 = icmp sgt i32 %3, 0
  br i1 %.not1921, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %2
  %4 = load ptr, ptr @TYPES, align 8, !tbaa !9
  %wide.trip.count53 = zext nneg i32 %3 to i64
  switch i32 %1, label %.lr.ph.split.split [
    i32 2, label %.lr.ph.split.us.split
    i32 1, label %.lr.ph.split.split.us
  ]

.lr.ph.split.us.split:                            ; preds = %.lr.ph, %11
  %indvars.iv45 = phi i64 [ %indvars.iv.next46, %11 ], [ 0, %.lr.ph ]
  %5 = getelementptr inbounds %struct.type, ptr %4, i64 %indvars.iv45
  %6 = getelementptr inbounds i8, ptr %5, i64 32
  %7 = load i32, ptr %6, align 8, !tbaa !11
  %8 = icmp eq i32 %7, 3
  br i1 %8, label %9, label %11

9:                                                ; preds = %.lr.ph.split.us.split
  %10 = tail call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %5, ptr noundef nonnull dereferenceable(1) %0) #2
  %.not18.us = icmp eq i32 %10, 0
  br i1 %.not18.us, label %.loopexit, label %11

11:                                               ; preds = %.lr.ph.split.us.split, %9
  %indvars.iv.next46 = add nuw nsw i64 %indvars.iv45, 1
  %exitcond49.not = icmp eq i64 %indvars.iv.next46, %wide.trip.count53
  br i1 %exitcond49.not, label %.loopexit, label %.lr.ph.split.us.split, !llvm.loop !13

.lr.ph.split.split.us:                            ; preds = %.lr.ph, %18
  %indvars.iv = phi i64 [ %indvars.iv.next, %18 ], [ 0, %.lr.ph ]
  %12 = getelementptr inbounds %struct.type, ptr %4, i64 %indvars.iv
  %13 = getelementptr inbounds i8, ptr %12, i64 32
  %14 = load i32, ptr %13, align 8, !tbaa !11
  %15 = icmp eq i32 %14, 3
  br i1 %15, label %18, label %16

16:                                               ; preds = %.lr.ph.split.split.us
  %17 = tail call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %12, ptr noundef nonnull dereferenceable(1) %0) #2
  %.not.us = icmp eq i32 %17, 0
  br i1 %.not.us, label %.split.us, label %18

18:                                               ; preds = %.lr.ph.split.split.us, %16
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count53
  br i1 %exitcond.not, label %.loopexit, label %.lr.ph.split.split.us, !llvm.loop !13

.lr.ph.split.split:                               ; preds = %.lr.ph, %34
  %indvars.iv50 = phi i64 [ %indvars.iv.next51, %34 ], [ 0, %.lr.ph ]
  %19 = getelementptr inbounds %struct.type, ptr %4, i64 %indvars.iv50
  %20 = getelementptr inbounds i8, ptr %19, i64 32
  %21 = load i32, ptr %20, align 8, !tbaa !11
  %22 = icmp eq i32 %21, 3
  %23 = tail call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %19, ptr noundef nonnull dereferenceable(1) %0) #2
  %.not18 = icmp eq i32 %23, 0
  br i1 %22, label %24, label %25

24:                                               ; preds = %.lr.ph.split.split
  br i1 %.not18, label %.loopexit, label %34

25:                                               ; preds = %.lr.ph.split.split
  br i1 %.not18, label %.split.us, label %34

.split.us:                                        ; preds = %16, %25
  %.us-phi28 = phi ptr [ %19, %25 ], [ %12, %16 ]
  %.us-phi29 = phi i32 [ %21, %25 ], [ %14, %16 ]
  %26 = icmp eq i32 %.us-phi29, 4
  br i1 %26, label %27, label %.loopexit

27:                                               ; preds = %.split.us
  %28 = getelementptr inbounds i8, ptr %.us-phi28, i64 48
  %29 = load i32, ptr %28, align 8, !tbaa !15
  %30 = icmp eq i32 %29, 0
  br i1 %30, label %31, label %.loopexit

31:                                               ; preds = %27
  %32 = getelementptr inbounds i8, ptr %.us-phi28, i64 40
  %33 = load ptr, ptr %32, align 8, !tbaa !16
  br label %.loopexit

34:                                               ; preds = %24, %25
  %indvars.iv.next51 = add nuw nsw i64 %indvars.iv50, 1
  %exitcond54.not = icmp eq i64 %indvars.iv.next51, %wide.trip.count53
  br i1 %exitcond54.not, label %.loopexit, label %.lr.ph.split.split, !llvm.loop !13

.loopexit:                                        ; preds = %18, %11, %9, %34, %24, %2, %.split.us, %27, %31
  %spec.select = phi ptr [ %33, %31 ], [ %.us-phi28, %27 ], [ %.us-phi28, %.split.us ], [ null, %2 ], [ null, %34 ], [ %19, %24 ], [ null, %11 ], [ %5, %9 ], [ null, %18 ]
  ret ptr %spec.select
}

attributes #0 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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 memory(read, 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" }
attributes #2 = { nounwind willreturn memory(read) }

!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 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !6, i64 32}
!12 = !{!"type", !7, i64 0, !6, i64 32, !10, i64 40, !6, i64 48, !7, i64 56, !6, i64 60472}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!12, !6, i64 48}
!16 = !{!12, !10, i64 40}


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