; LLVM IR from Nonoum/ECL :: ECL_common (ECL_JH_RInit)

; 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.ECL_JH_RState = type { ptr, ptr, ptr, i8, i8 }

@ECL_JH_dummy_buffer = external hidden global i8, align 1

; 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 void @ECL_JH_RInit(ptr noundef %0, ptr noundef %1, i32 noundef %2, i32 noundef %3) #1 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i8, align 1
  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
  store i32 %3, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 1, ptr %9) #2
  store i8 1, ptr %9, align 1, !tbaa !11
  %10 = load ptr, ptr %6, align 8, !tbaa !5
  %11 = icmp ne ptr %10, null
  br i1 %11, label %12, label %15

12:                                               ; preds = %4
  %13 = load i32, ptr %7, align 4, !tbaa !9
  %14 = icmp ne i32 %13, 0
  br i1 %14, label %16, label %15

15:                                               ; preds = %12, %4
  store i8 0, ptr %9, align 1, !tbaa !11
  store ptr @ECL_JH_dummy_buffer, ptr %6, align 8, !tbaa !5
  store i32 1, ptr %7, align 4, !tbaa !9
  br label %16

16:                                               ; preds = %15, %12
  %17 = load i8, ptr %9, align 1, !tbaa !11
  %18 = zext i8 %17 to i32
  %19 = load i32, ptr %8, align 4, !tbaa !9
  %20 = load i32, ptr %7, align 4, !tbaa !9
  %21 = icmp ult i32 %19, %20
  %22 = zext i1 %21 to i64
  %23 = select i1 %21, i32 1, i32 0
  %24 = mul nsw i32 %18, %23
  %25 = trunc i32 %24 to i8
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.ECL_JH_RState, ptr %26, i32 0, i32 4
  store i8 %25, ptr %27, align 1, !tbaa !12
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = load i32, ptr %7, align 4, !tbaa !9
  %30 = zext i32 %29 to i64
  %31 = getelementptr inbounds i8, ptr %28, i64 %30
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.ECL_JH_RState, ptr %32, i32 0, i32 2
  store ptr %31, ptr %33, align 8, !tbaa !14
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.ECL_JH_RState, ptr %34, i32 0, i32 4
  %36 = load i8, ptr %35, align 1, !tbaa !12
  %37 = icmp ne i8 %36, 0
  br i1 %37, label %38, label %51

38:                                               ; preds = %16
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  %40 = load i32, ptr %8, align 4, !tbaa !9
  %41 = zext i32 %40 to i64
  %42 = getelementptr inbounds i8, ptr %39, i64 %41
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.ECL_JH_RState, ptr %43, i32 0, i32 0
  store ptr %42, ptr %44, align 8, !tbaa !15
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.ECL_JH_RState, ptr %45, i32 0, i32 0
  %47 = load ptr, ptr %46, align 8, !tbaa !15
  %48 = getelementptr inbounds i8, ptr %47, i64 1
  %49 = load ptr, ptr %5, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.ECL_JH_RState, ptr %49, i32 0, i32 1
  store ptr %48, ptr %50, align 8, !tbaa !16
  br label %60

51:                                               ; preds = %16
  %52 = load ptr, ptr %6, align 8, !tbaa !5
  %53 = load ptr, ptr %5, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.ECL_JH_RState, ptr %53, i32 0, i32 0
  store ptr %52, ptr %54, align 8, !tbaa !15
  %55 = load ptr, ptr %5, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.ECL_JH_RState, ptr %55, i32 0, i32 2
  %57 = load ptr, ptr %56, align 8, !tbaa !14
  %58 = load ptr, ptr %5, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.ECL_JH_RState, ptr %58, i32 0, i32 1
  store ptr %57, ptr %59, align 8, !tbaa !16
  br label %60

60:                                               ; preds = %51, %38
  %61 = load ptr, ptr %5, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.ECL_JH_RState, ptr %61, i32 0, i32 3
  store i8 8, ptr %62, align 8, !tbaa !17
  call void @llvm.lifetime.end.p0(i64 1, ptr %9) #2
  ret void
}

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 = !{!"int", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !7, i64 25}
!13 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16, !7, i64 24, !7, i64 25}
!14 = !{!13, !6, i64 16}
!15 = !{!13, !6, i64 0}
!16 = !{!13, !6, i64 8}
!17 = !{!13, !7, i64 24}


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

@ECL_JH_dummy_buffer = external hidden global i8, align 1

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: write) uwtable
define dso_local void @ECL_JH_RInit(ptr nocapture noundef writeonly %0, ptr noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = icmp ne ptr %1, null
  %6 = icmp ne i32 %2, 0
  %or.cond = and i1 %5, %6
  %.021 = select i1 %or.cond, i32 %2, i32 1
  %.020 = select i1 %or.cond, ptr %1, ptr @ECL_JH_dummy_buffer
  %7 = icmp ugt i32 %.021, %3
  %narrow = and i1 %or.cond, %7
  %8 = zext i1 %narrow to i8
  %9 = getelementptr inbounds i8, ptr %0, i64 25
  store i8 %8, ptr %9, align 1, !tbaa !5
  %10 = zext i32 %.021 to i64
  %11 = getelementptr inbounds i8, ptr %.020, i64 %10
  %12 = getelementptr inbounds i8, ptr %0, i64 16
  store ptr %11, ptr %12, align 8, !tbaa !10
  %13 = zext i32 %3 to i64
  %14 = getelementptr inbounds i8, ptr %.020, i64 %13
  %15 = getelementptr inbounds i8, ptr %14, i64 1
  %.020.sink = select i1 %narrow, ptr %14, ptr %.020
  %.sink = select i1 %narrow, ptr %15, ptr %11
  store ptr %.020.sink, ptr %0, align 8
  %16 = getelementptr inbounds i8, ptr %0, i64 8
  store ptr %.sink, ptr %16, align 8
  %17 = getelementptr inbounds i8, ptr %0, i64 24
  store i8 8, ptr %17, align 8, !tbaa !11
  ret void
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: write) 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, !8, i64 25}
!6 = !{!"", !7, i64 0, !7, i64 8, !7, i64 16, !8, i64 24, !8, i64 25}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!6, !7, i64 16}
!11 = !{!6, !8, i64 24}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,MergedLoadStoreMotionPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass