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

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

@.str.8 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [5 x i8], align 1
@ke_opstr = external hidden global [25 x ptr], align 16
@.str.12 = external hidden unnamed_addr constant [7 x 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 @ke_print(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  %6 = load ptr, ptr %2, align 8, !tbaa !5
  %7 = icmp eq ptr %6, null
  br i1 %7, label %8, label %9

8:                                                ; preds = %1
  store i32 1, ptr %4, align 4
  br label %122

9:                                                ; preds = %1
  store i32 0, ptr %3, align 4, !tbaa !9
  br label %10

10:                                               ; preds = %117, %9
  %11 = load i32, ptr %3, align 4, !tbaa !9
  %12 = load ptr, ptr %2, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.kexpr_s, ptr %12, i32 0, i32 0
  %14 = load i32, ptr %13, align 8, !tbaa !11
  %15 = icmp slt i32 %11, %14
  br i1 %15, label %16, label %120

16:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %17 = load ptr, ptr %2, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.kexpr_s, ptr %17, i32 0, i32 1
  %19 = load ptr, ptr %18, align 8, !tbaa !13
  %20 = load i32, ptr %3, align 4, !tbaa !9
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds %struct.ke1_s, ptr %19, i64 %21
  store ptr %22, ptr %5, align 8, !tbaa !5
  %23 = load i32, ptr %3, align 4, !tbaa !9
  %24 = icmp ne i32 %23, 0
  br i1 %24, label %25, label %27

25:                                               ; preds = %16
  %26 = call i32 @putchar(i32 noundef 32)
  br label %27

27:                                               ; preds = %25, %16
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = load i64, ptr %28, align 8
  %30 = and i64 %29, 65535
  %31 = trunc i64 %30 to i32
  %32 = icmp eq i32 %31, 1
  br i1 %32, label %33, label %83

33:                                               ; preds = %27
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.ke1_s, ptr %34, i32 0, i32 1
  %36 = load ptr, ptr %35, align 8, !tbaa !14
  %37 = icmp ne ptr %36, null
  br i1 %37, label %38, label %43

38:                                               ; preds = %33
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.ke1_s, ptr %39, i32 0, i32 1
  %41 = load ptr, ptr %40, align 8, !tbaa !14
  %42 = call i32 (ptr, ...) @printf(ptr noundef @.str.8, ptr noundef %41)
  br label %82

43:                                               ; preds = %33
  %44 = load ptr, ptr %5, align 8, !tbaa !5
  %45 = load i64, ptr %44, align 8
  %46 = lshr i64 %45, 16
  %47 = and i64 %46, 1023
  %48 = trunc i64 %47 to i32
  %49 = icmp eq i32 %48, 1
  br i1 %49, label %50, label %55

50:                                               ; preds = %43
  %51 = load ptr, ptr %5, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.ke1_s, ptr %51, i32 0, i32 3
  %53 = load double, ptr %52, align 8, !tbaa !18
  %54 = call i32 (ptr, ...) @printf(ptr noundef @.str.9, double noundef %53)
  br label %81

55:                                               ; preds = %43
  %56 = load ptr, ptr %5, align 8, !tbaa !5
  %57 = load i64, ptr %56, align 8
  %58 = lshr i64 %57, 16
  %59 = and i64 %58, 1023
  %60 = trunc i64 %59 to i32
  %61 = icmp eq i32 %60, 2
  br i1 %61, label %62, label %67

62:                                               ; preds = %55
  %63 = load ptr, ptr %5, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.ke1_s, ptr %63, i32 0, i32 4
  %65 = load i64, ptr %64, align 8, !tbaa !19
  %66 = call i32 (ptr, ...) @printf(ptr noundef @.str.10, i64 noundef %65)
  br label %80

67:                                               ; preds = %55
  %68 = load ptr, ptr %5, align 8, !tbaa !5
  %69 = load i64, ptr %68, align 8
  %70 = lshr i64 %69, 16
  %71 = and i64 %70, 1023
  %72 = trunc i64 %71 to i32
  %73 = icmp eq i32 %72, 3
  br i1 %73, label %74, label %79

74:                                               ; preds = %67
  %75 = load ptr, ptr %5, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.ke1_s, ptr %75, i32 0, i32 5
  %77 = load ptr, ptr %76, align 8, !tbaa !20
  %78 = call i32 (ptr, ...) @printf(ptr noundef @.str.11, ptr noundef %77)
  br label %79

79:                                               ; preds = %74, %67
  br label %80

80:                                               ; preds = %79, %62
  br label %81

81:                                               ; preds = %80, %50
  br label %82

82:                                               ; preds = %81, %38
  br label %116

83:                                               ; preds = %27
  %84 = load ptr, ptr %5, align 8, !tbaa !5
  %85 = load i64, ptr %84, align 8
  %86 = and i64 %85, 65535
  %87 = trunc i64 %86 to i32
  %88 = icmp eq i32 %87, 2
  br i1 %88, label %89, label %99

89:                                               ; preds = %83
  %90 = load ptr, ptr %5, align 8, !tbaa !5
  %91 = load i64, ptr %90, align 8
  %92 = shl i64 %91, 24
  %93 = ashr i64 %92, 56
  %94 = trunc i64 %93 to i32
  %95 = sext i32 %94 to i64
  %96 = getelementptr inbounds [25 x ptr], ptr @ke_opstr, i64 0, i64 %95
  %97 = load ptr, ptr %96, align 8, !tbaa !5
  %98 = call i32 (ptr, ...) @printf(ptr noundef @.str.8, ptr noundef %97)
  br label %115

99:                                               ; preds = %83
  %100 = load ptr, ptr %5, align 8, !tbaa !5
  %101 = load i64, ptr %100, align 8
  %102 = and i64 %101, 65535
  %103 = trunc i64 %102 to i32
  %104 = icmp eq i32 %103, 3
  br i1 %104, label %105, label %114

105:                                              ; preds = %99
  %106 = load ptr, ptr %5, align 8, !tbaa !5
  %107 = getelementptr inbounds %struct.ke1_s, ptr %106, i32 0, i32 1
  %108 = load ptr, ptr %107, align 8, !tbaa !14
  %109 = load ptr, ptr %5, align 8, !tbaa !5
  %110 = load i64, ptr %109, align 8
  %111 = ashr i64 %110, 40
  %112 = trunc i64 %111 to i32
  %113 = call i32 (ptr, ...) @printf(ptr noundef @.str.12, ptr noundef %108, i32 noundef %112)
  br label %114

114:                                              ; preds = %105, %99
  br label %115

115:                                              ; preds = %114, %89
  br label %116

116:                                              ; preds = %115, %82
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  br label %117

117:                                              ; preds = %116
  %118 = load i32, ptr %3, align 4, !tbaa !9
  %119 = add nsw i32 %118, 1
  store i32 %119, ptr %3, align 4, !tbaa !9
  br label %10, !llvm.loop !21

120:                                              ; preds = %10
  %121 = call i32 @putchar(i32 noundef 10)
  store i32 0, ptr %4, align 4
  br label %122

122:                                              ; preds = %120, %8
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  %123 = load i32, ptr %4, align 4
  switch i32 %123, label %125 [
    i32 0, label %124
    i32 1, label %124
  ]

124:                                              ; preds = %122, %122
  ret void

125:                                              ; preds = %122
  unreachable
}

; Function Attrs: inlinehint nounwind uwtable
declare i32 @putchar(i32 noundef) #2

declare i32 @printf(ptr noundef, ...) #3

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

@.str.8 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [5 x i8], align 1
@ke_opstr = external hidden local_unnamed_addr global [25 x ptr], align 16
@.str.12 = external hidden unnamed_addr constant [7 x i8], align 1

; Function Attrs: nofree nounwind uwtable
define dso_local void @ke_print(ptr noundef readonly %0) local_unnamed_addr #0 {
  %2 = icmp eq ptr %0, null
  br i1 %2, label %86, label %.preheader

.preheader:                                       ; preds = %1
  %3 = load i32, ptr %0, align 8, !tbaa !5
  %4 = icmp sgt i32 %3, 0
  br i1 %4, label %5, label %._crit_edge

5:                                                ; preds = %.preheader
  %6 = getelementptr inbounds i8, ptr %0, i64 8
  %7 = load ptr, ptr %6, align 8, !tbaa !11
  %.pre = load i64, ptr %7, align 8
  %8 = trunc i64 %.pre to i32
  %trunc.peel = trunc i64 %.pre to i16
  switch i16 %trunc.peel, label %41 [
    i16 1, label %21
    i16 2, label %15
    i16 3, label %9
  ]

9:                                                ; preds = %5
  %10 = getelementptr inbounds i8, ptr %7, i64 8
  %11 = load ptr, ptr %10, align 8, !tbaa !12
  %12 = ashr i64 %.pre, 40
  %13 = trunc nsw i64 %12 to i32
  %14 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.12, ptr noundef %11, i32 noundef %13)
  br label %41

15:                                               ; preds = %5
  %16 = shl i64 %.pre, 24
  %17 = ashr i64 %16, 56
  %18 = getelementptr inbounds [25 x ptr], ptr @ke_opstr, i64 0, i64 %17
  %19 = load ptr, ptr %18, align 8, !tbaa !16
  %20 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.8, ptr noundef %19)
  br label %41

21:                                               ; preds = %5
  %22 = getelementptr inbounds i8, ptr %7, i64 8
  %23 = load ptr, ptr %22, align 8, !tbaa !12
  %.not24.peel = icmp eq ptr %23, null
  br i1 %.not24.peel, label %26, label %24

24:                                               ; preds = %21
  %25 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.8, ptr noundef nonnull %23)
  br label %41

26:                                               ; preds = %21
  %27 = lshr i32 %8, 16
  %28 = and i32 %27, 1023
  switch i32 %28, label %41 [
    i32 1, label %37
    i32 2, label %33
    i32 3, label %29
  ]

29:                                               ; preds = %26
  %30 = getelementptr inbounds i8, ptr %7, i64 40
  %31 = load ptr, ptr %30, align 8, !tbaa !17
  %32 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.11, ptr noundef %31)
  br label %41

33:                                               ; preds = %26
  %34 = getelementptr inbounds i8, ptr %7, i64 32
  %35 = load i64, ptr %34, align 8, !tbaa !18
  %36 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.10, i64 noundef %35)
  br label %41

37:                                               ; preds = %26
  %38 = getelementptr inbounds i8, ptr %7, i64 24
  %39 = load double, ptr %38, align 8, !tbaa !19
  %40 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.9, double noundef %39)
  br label %41

41:                                               ; preds = %37, %33, %29, %26, %24, %15, %9, %5
  %42 = load i32, ptr %0, align 8, !tbaa !5
  %43 = icmp sgt i32 %42, 1
  br i1 %43, label %.peel.next, label %._crit_edge

.peel.next:                                       ; preds = %41, %81
  %indvars.iv = phi i64 [ %indvars.iv.next, %81 ], [ 1, %41 ]
  %44 = load ptr, ptr %6, align 8, !tbaa !11
  %45 = getelementptr inbounds %struct.ke1_s, ptr %44, i64 %indvars.iv
  %46 = tail call i32 @putchar(i32 noundef 32)
  %47 = load i64, ptr %45, align 8
  %48 = trunc i64 %47 to i32
  %trunc = trunc i64 %47 to i16
  switch i16 %trunc, label %81 [
    i16 1, label %49
    i16 2, label %69
    i16 3, label %75
  ]

49:                                               ; preds = %.peel.next
  %50 = getelementptr inbounds i8, ptr %45, i64 8
  %51 = load ptr, ptr %50, align 8, !tbaa !12
  %.not24 = icmp eq ptr %51, null
  br i1 %.not24, label %54, label %52

52:                                               ; preds = %49
  %53 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.8, ptr noundef nonnull %51)
  br label %81

54:                                               ; preds = %49
  %55 = lshr i32 %48, 16
  %56 = and i32 %55, 1023
  switch i32 %56, label %81 [
    i32 1, label %57
    i32 2, label %61
    i32 3, label %65
  ]

57:                                               ; preds = %54
  %58 = getelementptr inbounds i8, ptr %45, i64 24
  %59 = load double, ptr %58, align 8, !tbaa !19
  %60 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.9, double noundef %59)
  br label %81

61:                                               ; preds = %54
  %62 = getelementptr inbounds i8, ptr %45, i64 32
  %63 = load i64, ptr %62, align 8, !tbaa !18
  %64 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.10, i64 noundef %63)
  br label %81

65:                                               ; preds = %54
  %66 = getelementptr inbounds i8, ptr %45, i64 40
  %67 = load ptr, ptr %66, align 8, !tbaa !17
  %68 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.11, ptr noundef %67)
  br label %81

69:                                               ; preds = %.peel.next
  %70 = shl i64 %47, 24
  %71 = ashr i64 %70, 56
  %72 = getelementptr inbounds [25 x ptr], ptr @ke_opstr, i64 0, i64 %71
  %73 = load ptr, ptr %72, align 8, !tbaa !16
  %74 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.8, ptr noundef %73)
  br label %81

75:                                               ; preds = %.peel.next
  %76 = getelementptr inbounds i8, ptr %45, i64 8
  %77 = load ptr, ptr %76, align 8, !tbaa !12
  %78 = ashr i64 %47, 40
  %79 = trunc nsw i64 %78 to i32
  %80 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.12, ptr noundef %77, i32 noundef %79)
  br label %81

81:                                               ; preds = %.peel.next, %54, %69, %75, %52, %61, %65, %57
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %82 = load i32, ptr %0, align 8, !tbaa !5
  %83 = sext i32 %82 to i64
  %84 = icmp slt i64 %indvars.iv.next, %83
  br i1 %84, label %.peel.next, label %._crit_edge, !llvm.loop !20

._crit_edge:                                      ; preds = %81, %41, %.preheader
  %85 = tail call i32 @putchar(i32 noundef 10)
  br label %86

86:                                               ; preds = %1, %._crit_edge
  ret void
}

; Function Attrs: inlinehint nofree nounwind uwtable
declare noundef i32 @putchar(i32 noundef) local_unnamed_addr #1

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

attributes #0 = { nofree 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 = { inlinehint nofree 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 = { nofree 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" }

!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 = !{!10, !10, i64 0}
!17 = !{!13, !10, i64 40}
!18 = !{!13, !15, i64 32}
!19 = !{!13, !14, i64 24}
!20 = distinct !{!20, !21, !22}
!21 = !{!"llvm.loop.mustprogress"}
!22 = !{!"llvm.loop.peeled.count", i32 1}


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