; LLVM IR from attractivechaos/klib :: kexpr (ke_set_real)

; 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.kexpr_s = type { i32, ptr }
%struct.ke1_s = type { i64, ptr, %union.anon, double, i64, ptr }
%union.anon = type { 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: nounwind willreturn memory(read)
declare i32 @strcmp(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @ke_set_real(ptr noundef %0, ptr noundef %1, double noundef %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca double, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i64, align 8
  %10 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store double %2, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 0, ptr %8, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %11 = load double, ptr %6, align 8, !tbaa !9
  %12 = fadd double %11, 5.000000e-01
  %13 = fptosi double %12 to i64
  store i64 %13, ptr %9, align 8, !tbaa !13
  store i32 0, ptr %7, align 4, !tbaa !11
  br label %14

14:                                               ; preds = %62, %3
  %15 = load i32, ptr %7, align 4, !tbaa !11
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.kexpr_s, ptr %16, i32 0, i32 0
  %18 = load i32, ptr %17, align 8, !tbaa !15
  %19 = icmp slt i32 %15, %18
  br i1 %19, label %20, label %65

20:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.kexpr_s, ptr %21, i32 0, i32 1
  %23 = load ptr, ptr %22, align 8, !tbaa !17
  %24 = load i32, ptr %7, align 4, !tbaa !11
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds %struct.ke1_s, ptr %23, i64 %25
  store ptr %26, ptr %10, align 8, !tbaa !5
  %27 = load ptr, ptr %10, align 8, !tbaa !5
  %28 = load i64, ptr %27, align 8
  %29 = and i64 %28, 65535
  %30 = trunc i64 %29 to i32
  %31 = icmp eq i32 %30, 1
  br i1 %31, label %32, label %61

32:                                               ; preds = %20
  %33 = load ptr, ptr %10, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.ke1_s, ptr %33, i32 0, i32 1
  %35 = load ptr, ptr %34, align 8, !tbaa !18
  %36 = icmp ne ptr %35, null
  br i1 %36, label %37, label %61

37:                                               ; preds = %32
  %38 = load ptr, ptr %10, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.ke1_s, ptr %38, i32 0, i32 1
  %40 = load ptr, ptr %39, align 8, !tbaa !18
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = call i32 @strcmp(ptr noundef %40, ptr noundef %41) #4
  %43 = icmp eq i32 %42, 0
  br i1 %43, label %44, label %61

44:                                               ; preds = %37
  %45 = load double, ptr %6, align 8, !tbaa !9
  %46 = load ptr, ptr %10, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.ke1_s, ptr %46, i32 0, i32 3
  store double %45, ptr %47, align 8, !tbaa !20
  %48 = load i64, ptr %9, align 8, !tbaa !13
  %49 = load ptr, ptr %10, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.ke1_s, ptr %49, i32 0, i32 4
  store i64 %48, ptr %50, align 8, !tbaa !21
  %51 = load ptr, ptr %10, align 8, !tbaa !5
  %52 = load i64, ptr %51, align 8
  %53 = and i64 %52, -67043329
  %54 = or i64 %53, 65536
  store i64 %54, ptr %51, align 8
  %55 = load ptr, ptr %10, align 8, !tbaa !5
  %56 = load i64, ptr %55, align 8
  %57 = and i64 %56, -67108865
  %58 = or i64 %57, 67108864
  store i64 %58, ptr %55, align 8
  %59 = load i32, ptr %8, align 4, !tbaa !11
  %60 = add nsw i32 %59, 1
  store i32 %60, ptr %8, align 4, !tbaa !11
  br label %61

61:                                               ; preds = %44, %37, %32, %20
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  br label %62

62:                                               ; preds = %61
  %63 = load i32, ptr %7, align 4, !tbaa !11
  %64 = add nsw i32 %63, 1
  store i32 %64, ptr %7, align 4, !tbaa !11
  br label %14, !llvm.loop !22

65:                                               ; preds = %14
  %66 = load i32, ptr %8, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  ret i32 %66
}

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 = !{!"double", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = !{!16, !12, i64 0}
!16 = !{!"kexpr_s", !12, i64 0, !6, i64 8}
!17 = !{!16, !6, i64 8}
!18 = !{!19, !6, i64 8}
!19 = !{!"ke1_s", !12, i64 0, !12, i64 2, !12, i64 3, !12, i64 3, !12, i64 4, !12, i64 5, !6, i64 8, !7, i64 16, !10, i64 24, !14, i64 32, !6, i64 40}
!20 = !{!19, !10, i64 24}
!21 = !{!19, !14, i64 32}
!22 = distinct !{!22, !23}
!23 = !{!"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.ke1_s = type { i64, ptr, %union.anon, double, i64, ptr }
%union.anon = type { ptr }

; 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(readwrite, inaccessiblemem: none) uwtable
define dso_local i32 @ke_set_real(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1, double noundef %2) local_unnamed_addr #1 {
  %4 = fadd double %2, 5.000000e-01
  %5 = fptosi double %4 to i64
  %6 = load i32, ptr %0, align 8, !tbaa !5
  %7 = icmp sgt i32 %6, 0
  br i1 %7, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %3
  %8 = getelementptr inbounds i8, ptr %0, i64 8
  br label %9

9:                                                ; preds = %.lr.ph, %28
  %10 = phi i32 [ %6, %.lr.ph ], [ %29, %28 ]
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %28 ]
  %.01719 = phi i32 [ 0, %.lr.ph ], [ %.1, %28 ]
  %11 = load ptr, ptr %8, align 8, !tbaa !11
  %12 = getelementptr inbounds %struct.ke1_s, ptr %11, i64 %indvars.iv
  %13 = load i64, ptr %12, align 8
  %14 = and i64 %13, 65535
  %15 = icmp eq i64 %14, 1
  br i1 %15, label %16, label %28

16:                                               ; preds = %9
  %17 = getelementptr inbounds i8, ptr %12, i64 8
  %18 = load ptr, ptr %17, align 8, !tbaa !12
  %.not = icmp eq ptr %18, null
  br i1 %.not, label %28, label %19

19:                                               ; preds = %16
  %20 = tail call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %18, ptr noundef nonnull dereferenceable(1) %1) #2
  %21 = icmp eq i32 %20, 0
  br i1 %21, label %22, label %28

22:                                               ; preds = %19
  %23 = getelementptr inbounds i8, ptr %12, i64 24
  store double %2, ptr %23, align 8, !tbaa !16
  %24 = getelementptr inbounds i8, ptr %12, i64 32
  store i64 %5, ptr %24, align 8, !tbaa !17
  %25 = and i64 %13, -134217727
  %26 = or disjoint i64 %25, 67174400
  store i64 %26, ptr %12, align 8
  %27 = add nsw i32 %.01719, 1
  %.pre = load i32, ptr %0, align 8, !tbaa !5
  br label %28

28:                                               ; preds = %22, %19, %16, %9
  %29 = phi i32 [ %.pre, %22 ], [ %10, %19 ], [ %10, %16 ], [ %10, %9 ]
  %.1 = phi i32 [ %27, %22 ], [ %.01719, %19 ], [ %.01719, %16 ], [ %.01719, %9 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %30 = sext i32 %29 to i64
  %31 = icmp slt i64 %indvars.iv.next, %30
  br i1 %31, label %9, label %._crit_edge, !llvm.loop !18

._crit_edge:                                      ; preds = %28, %3
  %.017.lcssa = phi i32 [ 0, %3 ], [ %.1, %28 ]
  ret i32 %.017.lcssa
}

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


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