; LLVM IR from matz/streem :: src (env)

; 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.strm_state = type { ptr, ptr, i32 }
%struct.kh_env_s = type { i32, i32, i32, i32, ptr, ptr, ptr }

; 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: inlinehint nounwind uwtable
declare hidden ptr @kh_init_env() #1

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

20:                                               ; preds = %2
  %21 = call ptr @kh_init_env()
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.strm_state, ptr %22, i32 0, i32 0
  store ptr %21, ptr %23, align 8, !tbaa !9
  store ptr %21, ptr %6, align 8, !tbaa !5
  br label %24

24:                                               ; preds = %20, %2
  %25 = load ptr, ptr %7, align 8, !tbaa !5
  %26 = icmp ne ptr %25, null
  br i1 %26, label %31, label %27

27:                                               ; preds = %24
  %28 = call ptr @kh_init_env()
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.strm_state, ptr %29, i32 0, i32 0
  store ptr %28, ptr %30, align 8, !tbaa !9
  store ptr %28, ptr %7, align 8, !tbaa !5
  br label %31

31:                                               ; preds = %27, %24
  store i32 0, ptr %8, align 4, !tbaa !12
  br label %32

32:                                               ; preds = %81, %31
  %33 = load i32, ptr %8, align 4, !tbaa !12
  %34 = load ptr, ptr %7, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.kh_env_s, ptr %34, i32 0, i32 0
  %36 = load i32, ptr %35, align 8, !tbaa !13
  %37 = icmp ne i32 %33, %36
  br i1 %37, label %38, label %84

38:                                               ; preds = %32
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.kh_env_s, ptr %39, i32 0, i32 4
  %41 = load ptr, ptr %40, align 8, !tbaa !15
  %42 = load i32, ptr %8, align 4, !tbaa !12
  %43 = lshr i32 %42, 4
  %44 = zext i32 %43 to i64
  %45 = getelementptr inbounds i32, ptr %41, i64 %44
  %46 = load i32, ptr %45, align 4, !tbaa !12
  %47 = load i32, ptr %8, align 4, !tbaa !12
  %48 = and i32 %47, 15
  %49 = shl i32 %48, 1
  %50 = lshr i32 %46, %49
  %51 = and i32 %50, 3
  %52 = icmp ne i32 %51, 0
  br i1 %52, label %80, label %53

53:                                               ; preds = %38
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  %55 = load ptr, ptr %7, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.kh_env_s, ptr %55, i32 0, i32 5
  %57 = load ptr, ptr %56, align 8, !tbaa !16
  %58 = load i32, ptr %8, align 4, !tbaa !12
  %59 = zext i32 %58 to i64
  %60 = getelementptr inbounds i64, ptr %57, i64 %59
  %61 = load i64, ptr %60, align 8, !tbaa !17
  %62 = call i32 @kh_put_env(ptr noundef %54, i64 noundef %61, ptr noundef %10)
  store i32 %62, ptr %9, align 4, !tbaa !12
  %63 = load i32, ptr %10, align 4, !tbaa !12
  %64 = icmp sle i32 %63, 0
  br i1 %64, label %65, label %66

65:                                               ; preds = %53
  store i32 1, ptr %3, align 4
  store i32 1, ptr %11, align 4
  br label %85

66:                                               ; preds = %53
  %67 = load ptr, ptr %7, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.kh_env_s, ptr %67, i32 0, i32 6
  %69 = load ptr, ptr %68, align 8, !tbaa !19
  %70 = load i32, ptr %8, align 4, !tbaa !12
  %71 = zext i32 %70 to i64
  %72 = getelementptr inbounds i64, ptr %69, i64 %71
  %73 = load i64, ptr %72, align 8, !tbaa !17
  %74 = load ptr, ptr %6, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.kh_env_s, ptr %74, i32 0, i32 6
  %76 = load ptr, ptr %75, align 8, !tbaa !19
  %77 = load i32, ptr %9, align 4, !tbaa !12
  %78 = zext i32 %77 to i64
  %79 = getelementptr inbounds i64, ptr %76, i64 %78
  store i64 %73, ptr %79, align 8, !tbaa !17
  br label %80

80:                                               ; preds = %66, %38
  br label %81

81:                                               ; preds = %80
  %82 = load i32, ptr %8, align 4, !tbaa !12
  %83 = add i32 %82, 1
  store i32 %83, ptr %8, align 4, !tbaa !12
  br label %32, !llvm.loop !20

84:                                               ; preds = %32
  store i32 0, ptr %3, align 4
  store i32 1, ptr %11, align 4
  br label %85

85:                                               ; preds = %84, %65
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %86 = load i32, ptr %3, align 4
  ret i32 %86
}

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

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

!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 = !{!"strm_state", !6, i64 0, !6, i64 8, !11, i64 16}
!11 = !{!"int", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!14, !11, i64 0}
!14 = !{!"kh_env_s", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !6, i64 16, !6, i64 24, !6, i64 32}
!15 = !{!14, !6, i64 16}
!16 = !{!14, !6, i64 24}
!17 = !{!18, !18, i64 0}
!18 = !{!"long", !7, i64 0}
!19 = !{!14, !6, i64 32}
!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: 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: inlinehint nounwind uwtable
declare hidden ptr @kh_init_env() local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @strm_env_copy(ptr nocapture noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #2 {
  %3 = alloca i32, align 4
  %4 = load ptr, ptr %0, align 8, !tbaa !5
  %5 = load ptr, ptr %1, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #3
  %.not = icmp eq ptr %4, null
  br i1 %.not, label %6, label %8

6:                                                ; preds = %2
  %7 = tail call ptr @kh_init_env()
  store ptr %7, ptr %0, align 8, !tbaa !5
  br label %8

8:                                                ; preds = %6, %2
  %.021 = phi ptr [ %4, %2 ], [ %7, %6 ]
  %.not24 = icmp eq ptr %5, null
  br i1 %.not24, label %9, label %11

9:                                                ; preds = %8
  %10 = tail call ptr @kh_init_env()
  store ptr %10, ptr %0, align 8, !tbaa !5
  br label %11

11:                                               ; preds = %9, %8
  %.020 = phi ptr [ %5, %8 ], [ %10, %9 ]
  %12 = getelementptr inbounds i8, ptr %.020, i64 24
  %13 = load i32, ptr %.020, align 8, !tbaa !11
  %.not2527 = icmp eq i32 %13, 0
  br i1 %.not2527, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %11
  %14 = getelementptr inbounds i8, ptr %.020, i64 16
  %15 = getelementptr inbounds i8, ptr %.020, i64 32
  %16 = getelementptr inbounds i8, ptr %.021, i64 32
  br label %17

17:                                               ; preds = %.lr.ph, %43
  %18 = phi i32 [ %13, %.lr.ph ], [ %44, %43 ]
  %.01928 = phi i32 [ 0, %.lr.ph ], [ %45, %43 ]
  %19 = load ptr, ptr %14, align 8, !tbaa !13
  %20 = lshr i32 %.01928, 4
  %21 = zext nneg i32 %20 to i64
  %22 = getelementptr inbounds i32, ptr %19, i64 %21
  %23 = load i32, ptr %22, align 4, !tbaa !14
  %24 = shl i32 %.01928, 1
  %25 = and i32 %24, 30
  %26 = shl nuw i32 3, %25
  %27 = and i32 %23, %26
  %.not26 = icmp eq i32 %27, 0
  br i1 %.not26, label %28, label %43

28:                                               ; preds = %17
  %29 = load ptr, ptr %12, align 8, !tbaa !15
  %30 = zext i32 %.01928 to i64
  %31 = getelementptr inbounds i64, ptr %29, i64 %30
  %32 = load i64, ptr %31, align 8, !tbaa !16
  %33 = call i32 @kh_put_env(ptr noundef %.021, i64 noundef %32, ptr noundef nonnull %3)
  %34 = load i32, ptr %3, align 4, !tbaa !14
  %35 = icmp slt i32 %34, 1
  br i1 %35, label %._crit_edge, label %36

36:                                               ; preds = %28
  %37 = load ptr, ptr %15, align 8, !tbaa !18
  %38 = getelementptr inbounds i64, ptr %37, i64 %30
  %39 = load i64, ptr %38, align 8, !tbaa !16
  %40 = load ptr, ptr %16, align 8, !tbaa !18
  %41 = zext i32 %33 to i64
  %42 = getelementptr inbounds i64, ptr %40, i64 %41
  store i64 %39, ptr %42, align 8, !tbaa !16
  %.pre = load i32, ptr %.020, align 8, !tbaa !11
  br label %43

43:                                               ; preds = %17, %36
  %44 = phi i32 [ %18, %17 ], [ %.pre, %36 ]
  %45 = add i32 %.01928, 1
  %.not25 = icmp eq i32 %45, %44
  br i1 %.not25, label %._crit_edge, label %17, !llvm.loop !19

._crit_edge:                                      ; preds = %28, %43, %11
  %.0 = phi i32 [ 0, %11 ], [ 0, %43 ], [ 1, %28 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #3
  ret i32 %.0
}

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

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

!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, !7, i64 0}
!6 = !{!"strm_state", !7, i64 0, !7, i64 8, !10, i64 16}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"kh_env_s", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !7, i64 16, !7, i64 24, !7, i64 32}
!13 = !{!12, !7, i64 16}
!14 = !{!10, !10, i64 0}
!15 = !{!12, !7, i64 24}
!16 = !{!17, !17, i64 0}
!17 = !{!"long", !8, i64 0}
!18 = !{!12, !7, i64 32}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}


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