; LLVM IR from pmwkaa/monotone :: monotone/runtime/runtime (logger)

; 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.timeval = type { i64, i64 }
%struct.Logger = type { i8, i8, i32 }

@.str.2 = external hidden unnamed_addr constant [19 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [2 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 @logger_write(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3, ptr noundef %4, ptr noundef %5, ptr noundef %6) #1 {
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca i32, align 4
  %16 = alloca [1024 x i8], align 16
  %17 = alloca %struct.timeval, align 8
  store ptr %0, ptr %8, align 8, !tbaa !5
  store ptr %1, ptr %9, align 8, !tbaa !5
  store ptr %2, ptr %10, align 8, !tbaa !5
  store i32 %3, ptr %11, align 4, !tbaa !9
  store ptr %4, ptr %12, align 8, !tbaa !5
  store ptr %5, ptr %13, align 8, !tbaa !5
  store ptr %6, ptr %14, align 8, !tbaa !5
  %18 = load ptr, ptr %9, align 8, !tbaa !5
  %19 = load ptr, ptr %10, align 8, !tbaa !5
  %20 = load i32, ptr %11, align 4, !tbaa !9
  %21 = load ptr, ptr %8, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.Logger, ptr %21, i32 0, i32 0
  %23 = load i8, ptr %22, align 4, !tbaa !11, !range !14, !noundef !15
  %24 = trunc i8 %23 to i1
  br i1 %24, label %26, label %25

25:                                               ; preds = %7
  br label %116

26:                                               ; preds = %7
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #4
  store i32 0, ptr %15, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 1024, ptr %16) #4
  call void @llvm.lifetime.start.p0(i64 16, ptr %17) #4
  %27 = call i32 @gettimeofday(ptr noundef %17, ptr noundef null) #4
  %28 = getelementptr inbounds [1024 x i8], ptr %16, i64 0, i64 0
  %29 = load i32, ptr %15, align 4, !tbaa !9
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds i8, ptr %28, i64 %30
  %32 = load i32, ptr %15, align 4, !tbaa !9
  %33 = sext i32 %32 to i64
  %34 = sub i64 1024, %33
  %35 = getelementptr inbounds %struct.timeval, ptr %17, i32 0, i32 0
  %36 = call ptr @localtime(ptr noundef %35) #4
  %37 = call i64 @strftime(ptr noundef %31, i64 noundef %34, ptr noundef @.str.2, ptr noundef %36) #4
  %38 = load i32, ptr %15, align 4, !tbaa !9
  %39 = sext i32 %38 to i64
  %40 = add i64 %39, %37
  %41 = trunc i64 %40 to i32
  store i32 %41, ptr %15, align 4, !tbaa !9
  %42 = getelementptr inbounds [1024 x i8], ptr %16, i64 0, i64 0
  %43 = load i32, ptr %15, align 4, !tbaa !9
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds i8, ptr %42, i64 %44
  %46 = load i32, ptr %15, align 4, !tbaa !9
  %47 = sext i32 %46 to i64
  %48 = sub i64 1024, %47
  %49 = getelementptr inbounds %struct.timeval, ptr %17, i32 0, i32 1
  %50 = load i64, ptr %49, align 8, !tbaa !16
  %51 = trunc i64 %50 to i32
  %52 = sdiv i32 %51, 1000
  %53 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef %45, i64 noundef %48, ptr noundef @.str.3, i32 noundef %52) #4
  %54 = load i32, ptr %15, align 4, !tbaa !9
  %55 = add nsw i32 %54, %53
  store i32 %55, ptr %15, align 4, !tbaa !9
  %56 = load ptr, ptr %12, align 8, !tbaa !5
  %57 = icmp ne ptr %56, null
  br i1 %57, label %58, label %70

58:                                               ; preds = %26
  %59 = getelementptr inbounds [1024 x i8], ptr %16, i64 0, i64 0
  %60 = load i32, ptr %15, align 4, !tbaa !9
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds i8, ptr %59, i64 %61
  %63 = load i32, ptr %15, align 4, !tbaa !9
  %64 = sext i32 %63 to i64
  %65 = sub i64 1024, %64
  %66 = load ptr, ptr %12, align 8, !tbaa !5
  %67 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef %62, i64 noundef %65, ptr noundef @.str.4, ptr noundef %66) #4
  %68 = load i32, ptr %15, align 4, !tbaa !9
  %69 = add nsw i32 %68, %67
  store i32 %69, ptr %15, align 4, !tbaa !9
  br label %70

70:                                               ; preds = %58, %26
  %71 = getelementptr inbounds [1024 x i8], ptr %16, i64 0, i64 0
  %72 = load i32, ptr %15, align 4, !tbaa !9
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds i8, ptr %71, i64 %73
  %75 = load i32, ptr %15, align 4, !tbaa !9
  %76 = sext i32 %75 to i64
  %77 = sub i64 1024, %76
  %78 = load ptr, ptr %13, align 8, !tbaa !5
  %79 = load ptr, ptr %14, align 8, !tbaa !5
  %80 = call i32 @vsnprintf(ptr noundef %74, i64 noundef %77, ptr noundef %78, ptr noundef %79) #4
  %81 = load i32, ptr %15, align 4, !tbaa !9
  %82 = add nsw i32 %81, %80
  store i32 %82, ptr %15, align 4, !tbaa !9
  %83 = getelementptr inbounds [1024 x i8], ptr %16, i64 0, i64 0
  %84 = load i32, ptr %15, align 4, !tbaa !9
  %85 = sext i32 %84 to i64
  %86 = getelementptr inbounds i8, ptr %83, i64 %85
  %87 = load i32, ptr %15, align 4, !tbaa !9
  %88 = sext i32 %87 to i64
  %89 = sub i64 1024, %88
  %90 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef %86, i64 noundef %89, ptr noundef @.str.5) #4
  %91 = load i32, ptr %15, align 4, !tbaa !9
  %92 = add nsw i32 %91, %90
  store i32 %92, ptr %15, align 4, !tbaa !9
  %93 = load ptr, ptr %8, align 8, !tbaa !5
  %94 = getelementptr inbounds %struct.Logger, ptr %93, i32 0, i32 2
  %95 = load i32, ptr %94, align 4, !tbaa !19
  %96 = icmp ne i32 %95, -1
  br i1 %96, label %97, label %105

97:                                               ; preds = %70
  %98 = load ptr, ptr %8, align 8, !tbaa !5
  %99 = getelementptr inbounds %struct.Logger, ptr %98, i32 0, i32 2
  %100 = load i32, ptr %99, align 4, !tbaa !19
  %101 = getelementptr inbounds [1024 x i8], ptr %16, i64 0, i64 0
  %102 = load i32, ptr %15, align 4, !tbaa !9
  %103 = sext i32 %102 to i64
  %104 = call i64 @vfs_write(i32 noundef %100, ptr noundef %101, i64 noundef %103)
  br label %105

105:                                              ; preds = %97, %70
  %106 = load ptr, ptr %8, align 8, !tbaa !5
  %107 = getelementptr inbounds %struct.Logger, ptr %106, i32 0, i32 1
  %108 = load i8, ptr %107, align 1, !tbaa !20, !range !14, !noundef !15
  %109 = trunc i8 %108 to i1
  br i1 %109, label %110, label %115

110:                                              ; preds = %105
  %111 = getelementptr inbounds [1024 x i8], ptr %16, i64 0, i64 0
  %112 = load i32, ptr %15, align 4, !tbaa !9
  %113 = sext i32 %112 to i64
  %114 = call i64 @vfs_write(i32 noundef 1, ptr noundef %111, i64 noundef %113)
  br label %115

115:                                              ; preds = %110, %105
  call void @llvm.lifetime.end.p0(i64 16, ptr %17) #4
  call void @llvm.lifetime.end.p0(i64 1024, ptr %16) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #4
  br label %116

116:                                              ; preds = %115, %25
  ret void
}

; Function Attrs: nounwind
declare i32 @gettimeofday(ptr noundef, ptr noundef) #2

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

; Function Attrs: nounwind
declare ptr @localtime(ptr noundef) #2

; Function Attrs: nounwind
declare i32 @snprintf(ptr noundef, i64 noundef, ptr noundef, ...) #2

; Function Attrs: nounwind
declare i32 @vsnprintf(ptr noundef, i64 noundef, ptr noundef, ptr noundef) #2

declare i64 @vfs_write(i32 noundef, ptr noundef, i64 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 = { 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 #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, !13, i64 0}
!12 = !{!"Logger", !13, i64 0, !13, i64 1, !10, i64 4}
!13 = !{!"_Bool", !7, i64 0}
!14 = !{i8 0, i8 2}
!15 = !{}
!16 = !{!17, !18, i64 8}
!17 = !{!"timeval", !18, i64 0, !18, i64 8}
!18 = !{!"long", !7, i64 0}
!19 = !{!12, !10, i64 4}
!20 = !{!12, !13, i64 1}


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

@.str.2 = external hidden unnamed_addr constant [19 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [2 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: 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 void @logger_write(ptr nocapture noundef readonly %0, ptr nocapture noundef readnone %1, ptr nocapture noundef readnone %2, i32 noundef %3, ptr noundef %4, ptr nocapture noundef readonly %5, ptr noundef %6) local_unnamed_addr #1 {
  %8 = alloca [1024 x i8], align 16
  %9 = alloca %struct.timeval, align 8
  %10 = load i8, ptr %0, align 4, !tbaa !5, !range !11, !noundef !12
  %11 = trunc nuw i8 %10 to i1
  br i1 %11, label %12, label %56

12:                                               ; preds = %7
  call void @llvm.lifetime.start.p0(i64 1024, ptr nonnull %8) #5
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %9) #5
  %13 = call i32 @gettimeofday(ptr noundef nonnull %9, ptr noundef null) #5
  %14 = call ptr @localtime(ptr noundef nonnull %9) #5
  %15 = call i64 @strftime(ptr noundef nonnull %8, i64 noundef 1024, ptr noundef nonnull @.str.2, ptr noundef %14) #5
  %16 = trunc i64 %15 to i32
  %sext = shl i64 %15, 32
  %17 = ashr exact i64 %sext, 32
  %18 = getelementptr inbounds i8, ptr %8, i64 %17
  %19 = sub nsw i64 1024, %17
  %20 = getelementptr inbounds i8, ptr %9, i64 8
  %21 = load i64, ptr %20, align 8, !tbaa !13
  %22 = trunc i64 %21 to i32
  %23 = sdiv i32 %22, 1000
  %24 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef nonnull %18, i64 noundef %19, ptr noundef nonnull @.str.3, i32 noundef %23) #5
  %25 = add nsw i32 %24, %16
  %.not = icmp eq ptr %4, null
  br i1 %.not, label %32, label %26

26:                                               ; preds = %12
  %27 = sext i32 %25 to i64
  %28 = getelementptr inbounds i8, ptr %8, i64 %27
  %29 = sub nsw i64 1024, %27
  %30 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef nonnull %28, i64 noundef %29, ptr noundef nonnull @.str.4, ptr noundef nonnull %4) #5
  %31 = add nsw i32 %30, %25
  br label %32

32:                                               ; preds = %26, %12
  %.0 = phi i32 [ %31, %26 ], [ %25, %12 ]
  %33 = sext i32 %.0 to i64
  %34 = getelementptr inbounds i8, ptr %8, i64 %33
  %35 = sub nsw i64 1024, %33
  %36 = call i32 @vsnprintf(ptr noundef nonnull %34, i64 noundef %35, ptr noundef %5, ptr noundef %6) #5
  %37 = add nsw i32 %36, %.0
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds i8, ptr %8, i64 %38
  %40 = sub nsw i64 1024, %38
  %41 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef nonnull %39, i64 noundef %40, ptr noundef nonnull @.str.5) #5
  %42 = add nsw i32 %37, %41
  %43 = getelementptr inbounds i8, ptr %0, i64 4
  %44 = load i32, ptr %43, align 4, !tbaa !16
  %.not29 = icmp eq i32 %44, -1
  br i1 %.not29, label %48, label %45

45:                                               ; preds = %32
  %46 = sext i32 %42 to i64
  %47 = call i64 @vfs_write(i32 noundef %44, ptr noundef nonnull %8, i64 noundef %46) #5
  br label %48

48:                                               ; preds = %45, %32
  %49 = getelementptr inbounds i8, ptr %0, i64 1
  %50 = load i8, ptr %49, align 1, !tbaa !17, !range !11, !noundef !12
  %51 = trunc nuw i8 %50 to i1
  br i1 %51, label %52, label %55

52:                                               ; preds = %48
  %53 = sext i32 %42 to i64
  %54 = call i64 @vfs_write(i32 noundef 1, ptr noundef nonnull %8, i64 noundef %53) #5
  br label %55

55:                                               ; preds = %52, %48
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %9) #5
  call void @llvm.lifetime.end.p0(i64 1024, ptr nonnull %8) #5
  br label %56

56:                                               ; preds = %7, %55
  ret void
}

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

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

; Function Attrs: nounwind
declare ptr @localtime(ptr noundef) local_unnamed_addr #3

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

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

declare i64 @vfs_write(i32 noundef, ptr noundef, i64 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 = { 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" }
attributes #3 = { 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 #4 = { "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 }

!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 = !{!"Logger", !7, i64 0, !7, i64 1, !10, i64 4}
!7 = !{!"_Bool", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}
!13 = !{!14, !15, i64 8}
!14 = !{!"timeval", !15, i64 0, !15, i64 8}
!15 = !{!"long", !8, i64 0}
!16 = !{!6, !10, i64 4}
!17 = !{!6, !7, i64 1}


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