; LLVM IR from ponylang/ponyc :: src/libponyrt/lang (time)

; 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.tm = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i64, ptr }

@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [3 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: nounwind uwtable
declare hidden void @date_to_tm(ptr noundef, ptr noundef) #1

; 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 ptr @ponyint_formattime(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i8, align 1
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca %struct.tm, align 8
  %14 = alloca i64, align 8
  %15 = alloca i64, align 8
  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) #5
  %16 = call ptr (...) @pony_ctx()
  store ptr %16, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %17, i64 0
  %19 = load i8, ptr %18, align 1, !tbaa !9
  %20 = sext i8 %19 to i32
  %21 = icmp eq i32 %20, 0
  br i1 %21, label %38, label %22

22:                                               ; preds = %2
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = call i32 @strcmp(ptr noundef %23, ptr noundef @.str) #6
  %25 = icmp ne i32 %24, 0
  br i1 %25, label %26, label %38

26:                                               ; preds = %22
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = call i32 @strcmp(ptr noundef %27, ptr noundef @.str.1) #6
  %29 = icmp ne i32 %28, 0
  br i1 %29, label %30, label %38

30:                                               ; preds = %26
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = call i32 @strcmp(ptr noundef %31, ptr noundef @.str.2) #6
  %33 = icmp ne i32 %32, 0
  br i1 %33, label %34, label %38

34:                                               ; preds = %30
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = call i32 @strcmp(ptr noundef %35, ptr noundef @.str.3) #6
  %37 = icmp ne i32 %36, 0
  br i1 %37, label %44, label %38

38:                                               ; preds = %34, %30, %26, %22, %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  %40 = call noalias ptr @pony_alloc(ptr noundef %39, i64 noundef 1)
  store ptr %40, ptr %8, align 8, !tbaa !5
  %41 = load ptr, ptr %8, align 8, !tbaa !5
  %42 = getelementptr inbounds i8, ptr %41, i64 0
  store i8 0, ptr %42, align 1, !tbaa !9
  %43 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %43, ptr %3, align 8
  store i32 1, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  br label %117

44:                                               ; preds = %34
  call void @llvm.lifetime.start.p0(i64 1, ptr %10) #5
  store i8 1, ptr %10, align 1, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %45, ptr %11, align 8, !tbaa !5
  br label %46

46:                                               ; preds = %89, %44
  %47 = load ptr, ptr %11, align 8, !tbaa !5
  %48 = load i8, ptr %47, align 1, !tbaa !9
  %49 = sext i8 %48 to i32
  %50 = icmp ne i32 %49, 0
  br i1 %50, label %51, label %54

51:                                               ; preds = %46
  %52 = load i8, ptr %10, align 1, !tbaa !10, !range !12, !noundef !13
  %53 = trunc i8 %52 to i1
  br label %54

54:                                               ; preds = %51, %46
  %55 = phi i1 [ false, %46 ], [ %53, %51 ]
  br i1 %55, label %56, label %90

56:                                               ; preds = %54
  %57 = load ptr, ptr %11, align 8, !tbaa !5
  %58 = load i8, ptr %57, align 1, !tbaa !9
  %59 = sext i8 %58 to i32
  %60 = icmp ne i32 %59, 37
  br i1 %60, label %85, label %61

61:                                               ; preds = %56
  %62 = load ptr, ptr %11, align 8, !tbaa !5
  %63 = getelementptr inbounds i8, ptr %62, i64 1
  %64 = load i8, ptr %63, align 1, !tbaa !9
  %65 = sext i8 %64 to i32
  %66 = icmp ne i32 %65, 112
  br i1 %66, label %67, label %86

67:                                               ; preds = %61
  %68 = load ptr, ptr %11, align 8, !tbaa !5
  %69 = getelementptr inbounds i8, ptr %68, i64 1
  %70 = load i8, ptr %69, align 1, !tbaa !9
  %71 = sext i8 %70 to i32
  %72 = icmp ne i32 %71, 80
  br i1 %72, label %73, label %86

73:                                               ; preds = %67
  %74 = load ptr, ptr %11, align 8, !tbaa !5
  %75 = getelementptr inbounds i8, ptr %74, i64 1
  %76 = load i8, ptr %75, align 1, !tbaa !9
  %77 = sext i8 %76 to i32
  %78 = icmp ne i32 %77, 122
  br i1 %78, label %79, label %86

79:                                               ; preds = %73
  %80 = load ptr, ptr %11, align 8, !tbaa !5
  %81 = getelementptr inbounds i8, ptr %80, i64 1
  %82 = load i8, ptr %81, align 1, !tbaa !9
  %83 = sext i8 %82 to i32
  %84 = icmp ne i32 %83, 90
  br i1 %84, label %85, label %86

85:                                               ; preds = %79, %56
  store i8 0, ptr %10, align 1, !tbaa !10
  br label %89

86:                                               ; preds = %79, %73, %67, %61
  %87 = load ptr, ptr %11, align 8, !tbaa !5
  %88 = getelementptr inbounds i8, ptr %87, i64 2
  store ptr %88, ptr %11, align 8, !tbaa !5
  br label %89

89:                                               ; preds = %86, %85
  br label %46, !llvm.loop !14

90:                                               ; preds = %54
  %91 = load i8, ptr %10, align 1, !tbaa !10, !range !12, !noundef !13
  %92 = trunc i8 %91 to i1
  br i1 %92, label %93, label %99

93:                                               ; preds = %90
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  %94 = load ptr, ptr %6, align 8, !tbaa !5
  %95 = call noalias ptr @pony_alloc(ptr noundef %94, i64 noundef 1)
  store ptr %95, ptr %12, align 8, !tbaa !5
  %96 = load ptr, ptr %12, align 8, !tbaa !5
  %97 = getelementptr inbounds i8, ptr %96, i64 0
  store i8 0, ptr %97, align 1, !tbaa !9
  %98 = load ptr, ptr %12, align 8, !tbaa !5
  store ptr %98, ptr %3, align 8
  store i32 1, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  br label %116

99:                                               ; preds = %90
  call void @llvm.lifetime.start.p0(i64 56, ptr %13) #5
  %100 = load ptr, ptr %4, align 8, !tbaa !5
  call void @date_to_tm(ptr noundef %100, ptr noundef %13)
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #5
  store i64 64, ptr %14, align 8, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #5
  store i64 0, ptr %15, align 8, !tbaa !16
  br label %101

101:                                              ; preds = %104, %99
  %102 = load i64, ptr %15, align 8, !tbaa !16
  %103 = icmp eq i64 %102, 0
  br i1 %103, label %104, label %114

104:                                              ; preds = %101
  %105 = load ptr, ptr %6, align 8, !tbaa !5
  %106 = load i64, ptr %14, align 8, !tbaa !16
  %107 = call noalias ptr @pony_alloc(ptr noundef %105, i64 noundef %106)
  store ptr %107, ptr %7, align 8, !tbaa !5
  %108 = load ptr, ptr %7, align 8, !tbaa !5
  %109 = load i64, ptr %14, align 8, !tbaa !16
  %110 = load ptr, ptr %5, align 8, !tbaa !5
  %111 = call i64 @strftime(ptr noundef %108, i64 noundef %109, ptr noundef %110, ptr noundef %13) #5
  store i64 %111, ptr %15, align 8, !tbaa !16
  %112 = load i64, ptr %14, align 8, !tbaa !16
  %113 = shl i64 %112, 1
  store i64 %113, ptr %14, align 8, !tbaa !16
  br label %101, !llvm.loop !18

114:                                              ; preds = %101
  %115 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %115, ptr %3, align 8
  store i32 1, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #5
  call void @llvm.lifetime.end.p0(i64 56, ptr %13) #5
  br label %116

116:                                              ; preds = %114, %93
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 1, ptr %10) #5
  br label %117

117:                                              ; preds = %116, %38
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  %118 = load ptr, ptr %3, align 8
  ret ptr %118
}

declare ptr @pony_ctx(...) #2

; Function Attrs: nounwind willreturn memory(read)
declare i32 @strcmp(ptr noundef, ptr noundef) #3

declare noalias ptr @pony_alloc(ptr noundef, i64 noundef) #2

; Function Attrs: nounwind
declare i64 @strftime(ptr noundef, i64 noundef, ptr noundef, ptr noundef) #4

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 = { "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 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 #4 = { 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" }
attributes #5 = { nounwind }
attributes #6 = { 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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"_Bool", !7, i64 0}
!12 = !{i8 0, i8 2}
!13 = !{}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!17, !17, i64 0}
!17 = !{!"long", !7, i64 0}
!18 = distinct !{!18, !15}


; 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.tm = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i64, ptr }

@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [3 x i8], align 1

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

; Function Attrs: nounwind uwtable
declare hidden void @date_to_tm(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress 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 noundef ptr @ponyint_formattime(ptr noundef %0, ptr noundef %1) local_unnamed_addr #1 {
  %3 = alloca %struct.tm, align 8
  %4 = tail call ptr (...) @pony_ctx() #5
  %5 = load i8, ptr %1, align 1, !tbaa !5
  %6 = icmp eq i8 %5, 0
  br i1 %6, label %15, label %7

7:                                                ; preds = %2
  %8 = tail call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %1, ptr noundef nonnull dereferenceable(1) @.str) #6
  %.not = icmp eq i32 %8, 0
  br i1 %.not, label %15, label %9

9:                                                ; preds = %7
  %10 = tail call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %1, ptr noundef nonnull dereferenceable(1) @.str.1) #6
  %.not39 = icmp eq i32 %10, 0
  br i1 %.not39, label %15, label %11

11:                                               ; preds = %9
  %12 = tail call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %1, ptr noundef nonnull dereferenceable(1) @.str.2) #6
  %.not40 = icmp eq i32 %12, 0
  br i1 %.not40, label %15, label %13

13:                                               ; preds = %11
  %14 = tail call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %1, ptr noundef nonnull dereferenceable(1) @.str.3) #6
  %.not41 = icmp eq i32 %14, 0
  br i1 %.not41, label %15, label %.lr.ph

15:                                               ; preds = %13, %11, %9, %7, %2
  %16 = tail call noalias ptr @pony_alloc(ptr noundef %4, i64 noundef 1) #5
  store i8 0, ptr %16, align 1, !tbaa !5
  br label %30

.lr.ph:                                           ; preds = %13, %21
  %17 = phi i8 [ %.pre, %21 ], [ %5, %13 ]
  %.03248 = phi ptr [ %22, %21 ], [ %1, %13 ]
  %.not42 = icmp eq i8 %17, 37
  br i1 %.not42, label %18, label %._crit_edge

18:                                               ; preds = %.lr.ph
  %19 = getelementptr inbounds i8, ptr %.03248, i64 1
  %20 = load i8, ptr %19, align 1, !tbaa !5
  switch i8 %20, label %._crit_edge [
    i8 112, label %21
    i8 80, label %21
    i8 122, label %21
    i8 90, label %21
  ]

21:                                               ; preds = %18, %18, %18, %18
  %22 = getelementptr inbounds i8, ptr %.03248, i64 2
  %.pre = load i8, ptr %22, align 1, !tbaa !5
  %.not55 = icmp eq i8 %.pre, 0
  br i1 %.not55, label %.critedge, label %.lr.ph, !llvm.loop !8

.critedge:                                        ; preds = %21
  %23 = tail call noalias ptr @pony_alloc(ptr noundef %4, i64 noundef 1) #5
  store i8 0, ptr %23, align 1, !tbaa !5
  br label %30

._crit_edge:                                      ; preds = %.lr.ph, %18
  call void @llvm.lifetime.start.p0(i64 56, ptr nonnull %3) #5
  call void @date_to_tm(ptr noundef %0, ptr noundef nonnull %3)
  br label %24

24:                                               ; preds = %._crit_edge, %24
  %.03049 = phi i64 [ 64, %._crit_edge ], [ %27, %24 ]
  %25 = call noalias ptr @pony_alloc(ptr noundef %4, i64 noundef %.03049) #5
  %26 = call i64 @strftime(ptr noundef %25, i64 noundef %.03049, ptr noundef nonnull %1, ptr noundef nonnull %3) #5
  %27 = shl i64 %.03049, 1
  %28 = icmp eq i64 %26, 0
  br i1 %28, label %24, label %29, !llvm.loop !10

29:                                               ; preds = %24
  call void @llvm.lifetime.end.p0(i64 56, ptr nonnull %3) #5
  br label %30

30:                                               ; preds = %.critedge, %29, %15
  %.1 = phi ptr [ %16, %15 ], [ %23, %.critedge ], [ %25, %29 ]
  ret ptr %.1
}

declare ptr @pony_ctx(...) local_unnamed_addr #2

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i32 @strcmp(ptr nocapture noundef, ptr nocapture noundef) local_unnamed_addr #3

declare noalias ptr @pony_alloc(ptr noundef, i64 noundef) local_unnamed_addr #2

; Function Attrs: nounwind
declare i64 @strftime(ptr noundef, i64 noundef, ptr noundef, ptr noundef) local_unnamed_addr #4

attributes #0 = { mustprogress 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 = { "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 = { 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 #4 = { 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" }
attributes #5 = { nounwind }
attributes #6 = { 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}
!10 = distinct !{!10, !9}


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