; LLVM IR from buzz-lang/Buzz :: src/buzz (buzzstrman)

; 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.buzzstrman_s = type { ptr, ptr, i16, ptr }
%struct.buzzid2strdata_s = type { ptr, i32 }

; 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
define dso_local zeroext i16 @buzzstrman_register(ptr noundef %0, ptr noundef %1, i32 noundef %2) #1 {
  %4 = alloca i16, align 2
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i16, align 2
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.buzzstrman_s, ptr %14, i32 0, i32 0
  %16 = load ptr, ptr %15, align 8, !tbaa !11
  %17 = call ptr @buzzdict_rawget(ptr noundef %16, ptr noundef %6)
  store ptr %17, ptr %8, align 8, !tbaa !5
  %18 = load ptr, ptr %8, align 8, !tbaa !5
  %19 = icmp ne ptr %18, null
  br i1 %19, label %20, label %35

20:                                               ; preds = %3
  %21 = load i32, ptr %7, align 4, !tbaa !9
  %22 = icmp ne i32 %21, 0
  br i1 %22, label %23, label %32

23:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.buzzstrman_s, ptr %24, i32 0, i32 1
  %26 = load ptr, ptr %25, align 8, !tbaa !14
  %27 = load ptr, ptr %8, align 8, !tbaa !5
  %28 = call ptr @buzzdict_rawget(ptr noundef %26, ptr noundef %27)
  %29 = load ptr, ptr %28, align 8, !tbaa !5
  store ptr %29, ptr %9, align 8, !tbaa !5
  %30 = load ptr, ptr %9, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.buzzid2strdata_s, ptr %30, i32 0, i32 1
  store i32 1, ptr %31, align 8, !tbaa !15
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  br label %32

32:                                               ; preds = %23, %20
  %33 = load ptr, ptr %8, align 8, !tbaa !5
  %34 = load i16, ptr %33, align 2, !tbaa !17
  store i16 %34, ptr %4, align 2
  store i32 1, ptr %10, align 4
  br label %79

35:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 2, ptr %11) #4
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.buzzstrman_s, ptr %36, i32 0, i32 2
  %38 = load i16, ptr %37, align 8, !tbaa !18
  store i16 %38, ptr %11, align 2, !tbaa !17
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.buzzstrman_s, ptr %39, i32 0, i32 2
  %41 = load i16, ptr %40, align 8, !tbaa !18
  %42 = add i16 %41, 1
  store i16 %42, ptr %40, align 8, !tbaa !18
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.buzzstrman_s, ptr %43, i32 0, i32 2
  %45 = load i16, ptr %44, align 8, !tbaa !18
  %46 = icmp ne i16 %45, 0
  br i1 %46, label %52, label %47

47:                                               ; preds = %35
  %48 = load ptr, ptr %5, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.buzzstrman_s, ptr %48, i32 0, i32 2
  %50 = load i16, ptr %49, align 8, !tbaa !18
  %51 = add i16 %50, 1
  store i16 %51, ptr %49, align 8, !tbaa !18
  br label %52

52:                                               ; preds = %47, %35
  br label %53

53:                                               ; preds = %61, %52
  %54 = load ptr, ptr %5, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.buzzstrman_s, ptr %54, i32 0, i32 1
  %56 = load ptr, ptr %55, align 8, !tbaa !14
  %57 = load ptr, ptr %5, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.buzzstrman_s, ptr %57, i32 0, i32 2
  %59 = call ptr @buzzdict_rawget(ptr noundef %56, ptr noundef %58)
  %60 = icmp ne ptr %59, null
  br i1 %60, label %61, label %66

61:                                               ; preds = %53
  %62 = load ptr, ptr %5, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.buzzstrman_s, ptr %62, i32 0, i32 2
  %64 = load i16, ptr %63, align 8, !tbaa !18
  %65 = add i16 %64, 1
  store i16 %65, ptr %63, align 8, !tbaa !18
  br label %53, !llvm.loop !19

66:                                               ; preds = %53
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %67 = load ptr, ptr %6, align 8, !tbaa !5
  %68 = call noalias ptr @strdup(ptr noundef %67) #4
  store ptr %68, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  %69 = load ptr, ptr %12, align 8, !tbaa !5
  %70 = load i32, ptr %7, align 4, !tbaa !9
  %71 = call ptr @buzzid2strdata_new(ptr noundef %69, i32 noundef %70)
  store ptr %71, ptr %13, align 8, !tbaa !5
  %72 = load ptr, ptr %5, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.buzzstrman_s, ptr %72, i32 0, i32 0
  %74 = load ptr, ptr %73, align 8, !tbaa !11
  call void @buzzdict_set(ptr noundef %74, ptr noundef %12, ptr noundef %11)
  %75 = load ptr, ptr %5, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.buzzstrman_s, ptr %75, i32 0, i32 1
  %77 = load ptr, ptr %76, align 8, !tbaa !14
  call void @buzzdict_set(ptr noundef %77, ptr noundef %11, ptr noundef %13)
  %78 = load i16, ptr %11, align 2, !tbaa !17
  store i16 %78, ptr %4, align 2
  store i32 1, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 2, ptr %11) #4
  br label %79

79:                                               ; preds = %66, %32
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  %80 = load i16, ptr %4, align 2
  ret i16 %80
}

declare ptr @buzzdict_rawget(ptr noundef, ptr noundef) #2

; Function Attrs: nounwind
declare noalias ptr @strdup(ptr noundef) #3

; Function Attrs: nounwind uwtable
declare hidden ptr @buzzid2strdata_new(ptr noundef, i32 noundef) #1

declare void @buzzdict_set(ptr noundef, ptr noundef, ptr noundef) #2

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 = { "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 "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 #4 = { 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 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"buzzstrman_s", !6, i64 0, !6, i64 8, !13, i64 16, !6, i64 24}
!13 = !{!"short", !7, i64 0}
!14 = !{!12, !6, i64 8}
!15 = !{!16, !10, i64 8}
!16 = !{!"buzzid2strdata_s", !6, i64 0, !10, i64 8}
!17 = !{!13, !13, i64 0}
!18 = !{!12, !13, i64 16}
!19 = distinct !{!19, !20}
!20 = !{!"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: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind uwtable
define dso_local zeroext i16 @buzzstrman_register(ptr noundef %0, ptr noundef %1, i32 noundef %2) local_unnamed_addr #1 {
  %4 = alloca ptr, align 8
  %5 = alloca i16, align 2
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  store ptr %1, ptr %4, align 8, !tbaa !5
  %8 = load ptr, ptr %0, align 8, !tbaa !9
  %9 = call ptr @buzzdict_rawget(ptr noundef %8, ptr noundef nonnull %4) #5
  %.not = icmp eq ptr %9, null
  br i1 %.not, label %19, label %10

10:                                               ; preds = %3
  %.not22 = icmp eq i32 %2, 0
  br i1 %.not22, label %17, label %11

11:                                               ; preds = %10
  %12 = getelementptr inbounds i8, ptr %0, i64 8
  %13 = load ptr, ptr %12, align 8, !tbaa !12
  %14 = call ptr @buzzdict_rawget(ptr noundef %13, ptr noundef nonnull %9) #5
  %15 = load ptr, ptr %14, align 8, !tbaa !5
  %16 = getelementptr inbounds i8, ptr %15, i64 8
  store i32 1, ptr %16, align 8, !tbaa !13
  br label %17

17:                                               ; preds = %11, %10
  %18 = load i16, ptr %9, align 2, !tbaa !16
  br label %36

19:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 2, ptr nonnull %5) #5
  %20 = getelementptr inbounds i8, ptr %0, i64 16
  %21 = load i16, ptr %20, align 8, !tbaa !17
  store i16 %21, ptr %5, align 2, !tbaa !16
  %22 = add i16 %21, 1
  %spec.select = call i16 @llvm.umax.i16(i16 %22, i16 1)
  %23 = getelementptr inbounds i8, ptr %0, i64 8
  store i16 %spec.select, ptr %20, align 8, !tbaa !17
  %24 = load ptr, ptr %23, align 8, !tbaa !12
  %25 = call ptr @buzzdict_rawget(ptr noundef %24, ptr noundef nonnull %20) #5
  %.not2123 = icmp eq ptr %25, null
  br i1 %.not2123, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %19, %.lr.ph
  %26 = load i16, ptr %20, align 8, !tbaa !17
  %27 = add i16 %26, 1
  store i16 %27, ptr %20, align 8, !tbaa !17
  %28 = load ptr, ptr %23, align 8, !tbaa !12
  %29 = call ptr @buzzdict_rawget(ptr noundef %28, ptr noundef nonnull %20) #5
  %.not21 = icmp eq ptr %29, null
  br i1 %.not21, label %._crit_edge, label %.lr.ph, !llvm.loop !18

._crit_edge:                                      ; preds = %.lr.ph, %19
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #5
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = call noalias ptr @strdup(ptr noundef %30) #5
  store ptr %31, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %7) #5
  %32 = call ptr @buzzid2strdata_new(ptr noundef %31, i32 noundef %2)
  store ptr %32, ptr %7, align 8, !tbaa !5
  %33 = load ptr, ptr %0, align 8, !tbaa !9
  call void @buzzdict_set(ptr noundef %33, ptr noundef nonnull %6, ptr noundef nonnull %5) #5
  %34 = load ptr, ptr %23, align 8, !tbaa !12
  call void @buzzdict_set(ptr noundef %34, ptr noundef nonnull %5, ptr noundef nonnull %7) #5
  %35 = load i16, ptr %5, align 2, !tbaa !16
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #5
  call void @llvm.lifetime.end.p0(i64 2, ptr nonnull %5) #5
  br label %36

36:                                               ; preds = %._crit_edge, %17
  %.0 = phi i16 [ %18, %17 ], [ %35, %._crit_edge ]
  ret i16 %.0
}

declare ptr @buzzdict_rawget(ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: readwrite, inaccessiblemem: readwrite)
declare noalias ptr @strdup(ptr nocapture noundef readonly) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
declare hidden ptr @buzzid2strdata_new(ptr noundef, i32 noundef) local_unnamed_addr #1

declare void @buzzdict_set(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i16 @llvm.umax.i16(i16, i16) #4

attributes #0 = { mustprogress 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 = { "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 = { mustprogress nofree nounwind willreturn memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 #4 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { 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, !6, i64 0}
!10 = !{!"buzzstrman_s", !6, i64 0, !6, i64 8, !11, i64 16, !6, i64 24}
!11 = !{!"short", !7, i64 0}
!12 = !{!10, !6, i64 8}
!13 = !{!14, !15, i64 8}
!14 = !{!"buzzid2strdata_s", !6, i64 0, !15, i64 8}
!15 = !{!"int", !7, i64 0}
!16 = !{!11, !11, i64 0}
!17 = !{!10, !11, i64 16}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}


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