; LLVM IR from thepowersgang/mrustc :: Notes (20241102-TimeCodegenError)

; 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.e_ZRG2cE9core0_0_06result6Result2gG2cE18time0_3_29_H40000d4date4Date0gG3c_D5error15component_range14ComponentRange0g = type { %union.anon }
%union.anon = type { %struct.s_ZRG2cE9core0_0_06resultG9ResultErr2gG2cE18time0_3_29_H40000d4date4Date0gG3c_D5error15component_range14ComponentRange0g }
%struct.s_ZRG2cE9core0_0_06resultG9ResultErr2gG2cE18time0_3_29_H40000d4date4Date0gG3c_D5error15component_range14ComponentRange0g = type { i8, i64 }
%struct.s_ZRG2cE18time0_3_29_H40000d4date4Date0g = type { i32 }
%struct.s_ZRG2cE9core0_0_06resultG8ResultOk2gG2cE18time0_3_29_H40000d4date4Date0gG3c_D5error15component_range14ComponentRange0g = type { i8, %struct.s_ZRG2cE18time0_3_29_H40000d4date4Date0g }

; Function Attrs: nounwind uwtable
declare dso_local i32 @ZRIG2cI17deranged0_3_8_H8110ranged_i329RangedI320v2gV4_0989e2ffV4_2cfe51003new0g_OP(i32 noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @ZRIG2cE18time0_3_29_H40000d4date4Date0g25from_julian_day_unchecked0g(i32 noundef) #0

; Function Attrs: nounwind uwtable
define dso_local { i64, i64 } @ZRIG2cE18time0_3_29_H40000d4date4Date0g15from_julian_day0g(i32 noundef %0) #0 {
  %2 = alloca %struct.e_ZRG2cE9core0_0_06result6Result2gG2cE18time0_3_29_H40000d4date4Date0gG3c_D5error15component_range14ComponentRange0g, align 8
  %3 = alloca i32, align 4
  %4 = alloca %struct.s_ZRG2cE9core0_0_06resultG9ResultErr2gG2cE18time0_3_29_H40000d4date4Date0gG3c_D5error15component_range14ComponentRange0g, align 8
  %5 = alloca %struct.s_ZRG2cE18time0_3_29_H40000d4date4Date0g, align 4
  %6 = alloca i32, align 4
  %7 = alloca %struct.s_ZRG2cE18time0_3_29_H40000d4date4Date0g, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 16, ptr %4) #4
  call void @llvm.memset.p0.i64(ptr align 8 %4, i8 0, i64 16, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  %8 = load i32, ptr %3, align 4, !tbaa !5
  %9 = call i32 @ZRIG2cI17deranged0_3_8_H8110ranged_i329RangedI320v2gV4_0989e2ffV4_2cfe51003new0g_OP(i32 noundef %8)
  %10 = icmp ne i32 %9, 0
  br i1 %10, label %11, label %13

11:                                               ; preds = %1
  %12 = getelementptr inbounds %struct.e_ZRG2cE9core0_0_06result6Result2gG2cE18time0_3_29_H40000d4date4Date0gG3c_D5error15component_range14ComponentRange0g, ptr %2, i32 0, i32 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %12, ptr align 8 %4, i64 16, i1 false), !tbaa.struct !9
  store i32 1, ptr %6, align 4
  br label %21

13:                                               ; preds = %1
  %14 = getelementptr inbounds %struct.e_ZRG2cE9core0_0_06result6Result2gG2cE18time0_3_29_H40000d4date4Date0gG3c_D5error15component_range14ComponentRange0g, ptr %2, i32 0, i32 0
  %15 = getelementptr inbounds %struct.s_ZRG2cE9core0_0_06resultG8ResultOk2gG2cE18time0_3_29_H40000d4date4Date0gG3c_D5error15component_range14ComponentRange0g, ptr %14, i32 0, i32 0
  store i8 2, ptr %15, align 8, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %16 = load i32, ptr %3, align 4, !tbaa !5
  %17 = call i32 @ZRIG2cE18time0_3_29_H40000d4date4Date0g25from_julian_day_unchecked0g(i32 noundef %16)
  %18 = getelementptr inbounds %struct.s_ZRG2cE18time0_3_29_H40000d4date4Date0g, ptr %7, i32 0, i32 0
  store i32 %17, ptr %18, align 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %5, ptr align 4 %7, i64 4, i1 false), !tbaa.struct !13
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  %19 = getelementptr inbounds %struct.e_ZRG2cE9core0_0_06result6Result2gG2cE18time0_3_29_H40000d4date4Date0gG3c_D5error15component_range14ComponentRange0g, ptr %2, i32 0, i32 0
  %20 = getelementptr inbounds %struct.s_ZRG2cE9core0_0_06resultG8ResultOk2gG2cE18time0_3_29_H40000d4date4Date0gG3c_D5error15component_range14ComponentRange0g, ptr %19, i32 0, i32 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %20, ptr align 4 %5, i64 4, i1 false), !tbaa.struct !13
  store i32 1, ptr %6, align 4
  br label %21

21:                                               ; preds = %13, %11
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr %4) #4
  %22 = getelementptr inbounds %struct.e_ZRG2cE9core0_0_06result6Result2gG2cE18time0_3_29_H40000d4date4Date0gG3c_D5error15component_range14ComponentRange0g, ptr %2, i32 0, i32 0
  %23 = getelementptr inbounds %union.anon, ptr %22, i32 0, i32 0
  %24 = load { i64, i64 }, ptr %23, align 8
  ret { i64, i64 } %24
}

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

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

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" }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{i64 0, i64 1, !10, i64 8, i64 8, !11}
!10 = !{!7, !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{i64 0, i64 4, !5}


; 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: nounwind uwtable
declare dso_local i32 @ZRIG2cI17deranged0_3_8_H8110ranged_i329RangedI320v2gV4_0989e2ffV4_2cfe51003new0g_OP(i32 noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local { i64, i64 } @ZRIG2cE18time0_3_29_H40000d4date4Date0g15from_julian_day0g(i32 noundef %0) local_unnamed_addr #0 {
  %2 = tail call i32 @ZRIG2cI17deranged0_3_8_H8110ranged_i329RangedI320v2gV4_0989e2ffV4_2cfe51003new0g_OP(i32 noundef %0)
  %.not = icmp eq i32 %2, 0
  br i1 %.not, label %3, label %8

3:                                                ; preds = %1
  %4 = tail call i32 @ZRIG2cE18time0_3_29_H40000d4date4Date0g25from_julian_day_unchecked0g(i32 noundef %0)
  %5 = zext i32 %4 to i64
  %6 = shl nuw i64 %5, 32
  %7 = or disjoint i64 %6, 2
  br label %8

8:                                                ; preds = %1, %3
  %.sroa.03.sroa.0.0.insert.insert = phi i64 [ %7, %3 ], [ 0, %1 ]
  %.fca.0.insert = insertvalue { i64, i64 } poison, i64 %.sroa.03.sroa.0.0.insert.insert, 0
  %.fca.1.insert = insertvalue { i64, i64 } %.fca.0.insert, i64 0, 1
  ret { i64, i64 } %.fca.1.insert
}

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)"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass