; LLVM IR from pmwkaa/monotone :: examples (write_and_read)

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

@stderr = external global ptr, align 8
@.str = external hidden unnamed_addr constant [24 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [26 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [28 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [29 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [30 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [28 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [28 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [31 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @main(i32 noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  %14 = alloca %struct.monotone_event, align 8
  %15 = alloca ptr, align 8
  %16 = alloca i32, align 4
  %17 = alloca %struct.monotone_event, align 8
  %18 = alloca ptr, align 8
  store i32 0, ptr %3, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #6
  %19 = call ptr @monotone_init()
  store ptr %19, ptr %6, align 8, !tbaa !9
  %20 = load ptr, ptr %6, align 8, !tbaa !9
  %21 = icmp eq ptr %20, null
  br i1 %21, label %22, label %25

22:                                               ; preds = %2
  %23 = load ptr, ptr @stderr, align 8, !tbaa !9
  %24 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %23, ptr noundef @.str) #6
  store i32 1, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %156

25:                                               ; preds = %2
  %26 = load ptr, ptr %6, align 8, !tbaa !9
  %27 = call i32 @monotone_execute(ptr noundef %26, ptr noundef @.str.1, ptr noundef null)
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #6
  %28 = load ptr, ptr %6, align 8, !tbaa !9
  %29 = call i32 @monotone_open(ptr noundef %28, ptr noundef @.str.2)
  store i32 %29, ptr %8, align 4, !tbaa !5
  %30 = load i32, ptr %8, align 4, !tbaa !5
  %31 = icmp eq i32 %30, -1
  br i1 %31, label %32, label %38

32:                                               ; preds = %25
  %33 = load ptr, ptr %6, align 8, !tbaa !9
  call void @monotone_free(ptr noundef %33)
  %34 = load ptr, ptr @stderr, align 8, !tbaa !9
  %35 = load ptr, ptr %6, align 8, !tbaa !9
  %36 = call ptr @monotone_error(ptr noundef %35)
  %37 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %34, ptr noundef @.str.3, ptr noundef %36) #6
  store i32 1, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %155

38:                                               ; preds = %25
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #6
  store i32 200, ptr %9, align 4, !tbaa !5
  %39 = call ptr @llvm.stacksave.p0()
  store ptr %39, ptr %10, align 8
  %40 = alloca %struct.monotone_event, i64 200, align 16
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #6
  store i32 0, ptr %11, align 4, !tbaa !5
  br label %41

41:                                               ; preds = %81, %38
  %42 = load i32, ptr %11, align 4, !tbaa !5
  %43 = icmp slt i32 %42, 5000
  br i1 %43, label %45, label %44

44:                                               ; preds = %41
  store i32 2, ptr %7, align 4
  br label %84

45:                                               ; preds = %41
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #6
  store i32 0, ptr %12, align 4, !tbaa !5
  br label %46

46:                                               ; preds = %66, %45
  %47 = load i32, ptr %12, align 4, !tbaa !5
  %48 = icmp slt i32 %47, 200
  br i1 %48, label %50, label %49

49:                                               ; preds = %46
  store i32 5, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #6
  br label %69

50:                                               ; preds = %46
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #6
  %51 = load i32, ptr %12, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds %struct.monotone_event, ptr %40, i64 %52
  store ptr %53, ptr %13, align 8, !tbaa !9
  %54 = load ptr, ptr %13, align 8, !tbaa !9
  %55 = getelementptr inbounds %struct.monotone_event, ptr %54, i32 0, i32 0
  store i32 0, ptr %55, align 8, !tbaa !11
  %56 = load ptr, ptr %13, align 8, !tbaa !9
  %57 = getelementptr inbounds %struct.monotone_event, ptr %56, i32 0, i32 1
  store i64 -1, ptr %57, align 8, !tbaa !14
  %58 = load ptr, ptr %13, align 8, !tbaa !9
  %59 = getelementptr inbounds %struct.monotone_event, ptr %58, i32 0, i32 2
  store ptr null, ptr %59, align 8, !tbaa !15
  %60 = load ptr, ptr %13, align 8, !tbaa !9
  %61 = getelementptr inbounds %struct.monotone_event, ptr %60, i32 0, i32 3
  store i64 0, ptr %61, align 8, !tbaa !16
  %62 = load ptr, ptr %13, align 8, !tbaa !9
  %63 = getelementptr inbounds %struct.monotone_event, ptr %62, i32 0, i32 4
  store ptr null, ptr %63, align 8, !tbaa !17
  %64 = load ptr, ptr %13, align 8, !tbaa !9
  %65 = getelementptr inbounds %struct.monotone_event, ptr %64, i32 0, i32 5
  store i64 0, ptr %65, align 8, !tbaa !18
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #6
  br label %66

66:                                               ; preds = %50
  %67 = load i32, ptr %12, align 4, !tbaa !5
  %68 = add nsw i32 %67, 1
  store i32 %68, ptr %12, align 4, !tbaa !5
  br label %46, !llvm.loop !19

69:                                               ; preds = %49
  %70 = load ptr, ptr %6, align 8, !tbaa !9
  %71 = call i32 @monotone_write(ptr noundef %70, ptr noundef %40, i32 noundef 200)
  store i32 %71, ptr %8, align 4, !tbaa !5
  %72 = load i32, ptr %8, align 4, !tbaa !5
  %73 = icmp eq i32 %72, -1
  br i1 %73, label %74, label %80

74:                                               ; preds = %69
  %75 = load ptr, ptr %6, align 8, !tbaa !9
  call void @monotone_free(ptr noundef %75)
  %76 = load ptr, ptr @stderr, align 8, !tbaa !9
  %77 = load ptr, ptr %6, align 8, !tbaa !9
  %78 = call ptr @monotone_error(ptr noundef %77)
  %79 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %76, ptr noundef @.str.4, ptr noundef %78) #6
  store i32 1, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %84

80:                                               ; preds = %69
  br label %81

81:                                               ; preds = %80
  %82 = load i32, ptr %11, align 4, !tbaa !5
  %83 = add nsw i32 %82, 1
  store i32 %83, ptr %11, align 4, !tbaa !5
  br label %41, !llvm.loop !21

84:                                               ; preds = %74, %44
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #6
  %85 = load i32, ptr %7, align 4
  switch i32 %85, label %153 [
    i32 2, label %86
  ]

86:                                               ; preds = %84
  call void @llvm.lifetime.start.p0(i64 48, ptr %14) #6
  call void @llvm.memset.p0.i64(ptr align 8 %14, i8 0, i64 48, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #6
  %87 = load ptr, ptr %6, align 8, !tbaa !9
  %88 = call ptr @monotone_cursor(ptr noundef %87, ptr noundef null, ptr noundef %14)
  store ptr %88, ptr %15, align 8, !tbaa !9
  %89 = load ptr, ptr %15, align 8, !tbaa !9
  %90 = icmp eq ptr %89, null
  br i1 %90, label %91, label %97

91:                                               ; preds = %86
  %92 = load ptr, ptr %6, align 8, !tbaa !9
  call void @monotone_free(ptr noundef %92)
  %93 = load ptr, ptr @stderr, align 8, !tbaa !9
  %94 = load ptr, ptr %6, align 8, !tbaa !9
  %95 = call ptr @monotone_error(ptr noundef %94)
  %96 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %93, ptr noundef @.str.5, ptr noundef %95) #6
  store i32 1, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %152

97:                                               ; preds = %86
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #6
  store i32 0, ptr %16, align 4, !tbaa !5
  br label %98

98:                                               ; preds = %127, %97
  call void @llvm.lifetime.start.p0(i64 48, ptr %17) #6
  %99 = load ptr, ptr %15, align 8, !tbaa !9
  %100 = call i32 @monotone_read(ptr noundef %99, ptr noundef %17)
  store i32 %100, ptr %8, align 4, !tbaa !5
  %101 = load i32, ptr %8, align 4, !tbaa !5
  %102 = icmp eq i32 %101, -1
  br i1 %102, label %103, label %108

103:                                              ; preds = %98
  %104 = load ptr, ptr @stderr, align 8, !tbaa !9
  %105 = load ptr, ptr %6, align 8, !tbaa !9
  %106 = call ptr @monotone_error(ptr noundef %105)
  %107 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %104, ptr noundef @.str.6, ptr noundef %106) #6
  store i32 8, ptr %7, align 4
  br label %125

108:                                              ; preds = %98
  %109 = load i32, ptr %8, align 4, !tbaa !5
  %110 = icmp eq i32 %109, 0
  br i1 %110, label %111, label %112

111:                                              ; preds = %108
  store i32 8, ptr %7, align 4
  br label %125

112:                                              ; preds = %108
  %113 = load i32, ptr %16, align 4, !tbaa !5
  %114 = add nsw i32 %113, 1
  store i32 %114, ptr %16, align 4, !tbaa !5
  %115 = load ptr, ptr %15, align 8, !tbaa !9
  %116 = call i32 @monotone_next(ptr noundef %115)
  store i32 %116, ptr %8, align 4, !tbaa !5
  %117 = load i32, ptr %8, align 4, !tbaa !5
  %118 = icmp eq i32 %117, -1
  br i1 %118, label %119, label %124

119:                                              ; preds = %112
  %120 = load ptr, ptr @stderr, align 8, !tbaa !9
  %121 = load ptr, ptr %6, align 8, !tbaa !9
  %122 = call ptr @monotone_error(ptr noundef %121)
  %123 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %120, ptr noundef @.str.7, ptr noundef %122) #6
  store i32 8, ptr %7, align 4
  br label %125

124:                                              ; preds = %112
  store i32 0, ptr %7, align 4
  br label %125

125:                                              ; preds = %124, %119, %111, %103
  call void @llvm.lifetime.end.p0(i64 48, ptr %17) #6
  %126 = load i32, ptr %7, align 4
  switch i32 %126, label %158 [
    i32 0, label %127
    i32 8, label %128
  ]

127:                                              ; preds = %125
  br label %98

128:                                              ; preds = %125
  %129 = load i32, ptr %16, align 4, !tbaa !5
  %130 = call i32 (ptr, ...) @printf(ptr noundef @.str.8, i32 noundef %129)
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #6
  store ptr null, ptr %18, align 8, !tbaa !9
  %131 = load ptr, ptr %6, align 8, !tbaa !9
  %132 = call i32 @monotone_execute(ptr noundef %131, ptr noundef @.str.9, ptr noundef %18)
  store i32 %132, ptr %8, align 4, !tbaa !5
  %133 = load i32, ptr %8, align 4, !tbaa !5
  %134 = icmp eq i32 %133, -1
  br i1 %134, label %135, label %140

135:                                              ; preds = %128
  %136 = load ptr, ptr @stderr, align 8, !tbaa !9
  %137 = load ptr, ptr %6, align 8, !tbaa !9
  %138 = call ptr @monotone_error(ptr noundef %137)
  %139 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %136, ptr noundef @.str.10, ptr noundef %138) #6
  br label %140

140:                                              ; preds = %135, %128
  %141 = load ptr, ptr %18, align 8, !tbaa !9
  %142 = icmp ne ptr %141, null
  br i1 %142, label %143, label %147

143:                                              ; preds = %140
  %144 = load ptr, ptr %18, align 8, !tbaa !9
  %145 = call i32 (ptr, ...) @printf(ptr noundef @.str.11, ptr noundef %144)
  %146 = load ptr, ptr %18, align 8, !tbaa !9
  call void @free(ptr noundef %146) #6
  br label %147

147:                                              ; preds = %143, %140
  %148 = load ptr, ptr %15, align 8, !tbaa !9
  call void @monotone_free(ptr noundef %148)
  %149 = load ptr, ptr %6, align 8, !tbaa !9
  call void @monotone_free(ptr noundef %149)
  %150 = load i32, ptr %4, align 4, !tbaa !5
  %151 = load ptr, ptr %5, align 8, !tbaa !9
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #6
  br label %152

152:                                              ; preds = %147, %91
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #6
  call void @llvm.lifetime.end.p0(i64 48, ptr %14) #6
  br label %153

153:                                              ; preds = %152, %84
  %154 = load ptr, ptr %10, align 8
  call void @llvm.stackrestore.p0(ptr %154)
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #6
  br label %155

155:                                              ; preds = %153, %32
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #6
  br label %156

156:                                              ; preds = %155, %22
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #6
  %157 = load i32, ptr %3, align 4
  ret i32 %157

158:                                              ; preds = %125
  unreachable
}

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

declare ptr @monotone_init() #2

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #3

declare i32 @monotone_execute(ptr noundef, ptr noundef, ptr noundef) #2

declare i32 @monotone_open(ptr noundef, ptr noundef) #2

declare void @monotone_free(ptr noundef) #2

declare ptr @monotone_error(ptr noundef) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #4

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

declare i32 @monotone_write(ptr noundef, ptr noundef, i32 noundef) #2

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

declare ptr @monotone_cursor(ptr noundef, ptr noundef, ptr noundef) #2

declare i32 @monotone_read(ptr noundef, ptr noundef) #2

declare i32 @monotone_next(ptr noundef) #2

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

; Function Attrs: nounwind
declare void @free(ptr noundef) #3

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #4

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 = { "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 = { nocallback nofree nosync nounwind willreturn }
attributes #5 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #6 = { 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 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"monotone_event", !6, i64 0, !13, i64 8, !10, i64 16, !13, i64 24, !10, i64 32, !13, i64 40}
!13 = !{!"long", !7, i64 0}
!14 = !{!12, !13, i64 8}
!15 = !{!12, !10, i64 16}
!16 = !{!12, !13, i64 24}
!17 = !{!12, !10, i64 32}
!18 = !{!12, !13, i64 40}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = distinct !{!21, !20}


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

@stderr = external local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [24 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [26 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [28 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [29 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [30 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [28 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [28 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [31 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @main(i32 noundef %0, ptr nocapture noundef readnone %1) local_unnamed_addr #0 {
  %3 = alloca %struct.monotone_event, align 8
  %4 = alloca %struct.monotone_event, align 8
  %5 = alloca ptr, align 8
  %6 = tail call ptr @monotone_init() #7
  %7 = icmp eq ptr %6, null
  br i1 %7, label %8, label %11

8:                                                ; preds = %2
  %9 = load ptr, ptr @stderr, align 8, !tbaa !5
  %10 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %9, ptr noundef nonnull @.str) #8
  br label %74

11:                                               ; preds = %2
  %12 = tail call i32 @monotone_execute(ptr noundef nonnull %6, ptr noundef nonnull @.str.1, ptr noundef null) #7
  %13 = tail call i32 @monotone_open(ptr noundef nonnull %6, ptr noundef nonnull @.str.2) #7
  %14 = icmp eq i32 %13, -1
  br i1 %14, label %15, label %19

15:                                               ; preds = %11
  tail call void @monotone_free(ptr noundef nonnull %6) #7
  %16 = load ptr, ptr @stderr, align 8, !tbaa !5
  %17 = tail call ptr @monotone_error(ptr noundef nonnull %6) #7
  %18 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %16, ptr noundef nonnull @.str.3, ptr noundef %17) #8
  br label %74

19:                                               ; preds = %11
  %20 = tail call ptr @llvm.stacksave.p0()
  %21 = alloca [200 x %struct.monotone_event], align 16
  br label %.preheader60

22:                                               ; preds = %24
  %23 = add nuw nsw i32 %.04964, 1
  %exitcond68 = icmp eq i32 %23, 5000
  br i1 %exitcond68, label %.thread, label %.preheader60, !llvm.loop !9

.preheader60:                                     ; preds = %19, %22
  %.04964 = phi i32 [ 0, %19 ], [ %23, %22 ]
  br label %27

24:                                               ; preds = %27
  %25 = call i32 @monotone_write(ptr noundef nonnull %6, ptr noundef nonnull %21, i32 noundef 200) #7
  %26 = icmp eq i32 %25, -1
  br i1 %26, label %40, label %22

27:                                               ; preds = %27, %.preheader60
  %indvars.iv = phi i64 [ 0, %.preheader60 ], [ %indvars.iv.next.3, %27 ]
  %28 = getelementptr inbounds %struct.monotone_event, ptr %21, i64 %indvars.iv
  store i32 0, ptr %28, align 16, !tbaa !11
  %29 = getelementptr inbounds i8, ptr %28, i64 8
  store i64 -1, ptr %29, align 8, !tbaa !15
  %30 = getelementptr inbounds i8, ptr %28, i64 16
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(32) %30, i8 0, i64 32, i1 false)
  %31 = getelementptr inbounds %struct.monotone_event, ptr %21, i64 %indvars.iv.next
  store i32 0, ptr %31, align 16, !tbaa !11
  %32 = getelementptr inbounds i8, ptr %31, i64 8
  store i64 -1, ptr %32, align 8, !tbaa !15
  %33 = getelementptr inbounds i8, ptr %31, i64 16
  %indvars.iv.next.1 = or disjoint i64 %indvars.iv, 2
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(32) %33, i8 0, i64 32, i1 false)
  %34 = getelementptr inbounds %struct.monotone_event, ptr %21, i64 %indvars.iv.next.1
  store i32 0, ptr %34, align 16, !tbaa !11
  %35 = getelementptr inbounds i8, ptr %34, i64 8
  store i64 -1, ptr %35, align 8, !tbaa !15
  %36 = getelementptr inbounds i8, ptr %34, i64 16
  %indvars.iv.next.2 = or disjoint i64 %indvars.iv, 3
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(32) %36, i8 0, i64 32, i1 false)
  %37 = getelementptr inbounds %struct.monotone_event, ptr %21, i64 %indvars.iv.next.2
  store i32 0, ptr %37, align 16, !tbaa !11
  %38 = getelementptr inbounds i8, ptr %37, i64 8
  store i64 -1, ptr %38, align 8, !tbaa !15
  %39 = getelementptr inbounds i8, ptr %37, i64 16
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %exitcond.not.3 = icmp eq i64 %indvars.iv.next.3, 200
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(32) %39, i8 0, i64 32, i1 false)
  br i1 %exitcond.not.3, label %24, label %27, !llvm.loop !16

40:                                               ; preds = %24
  call void @monotone_free(ptr noundef nonnull %6) #7
  %41 = load ptr, ptr @stderr, align 8, !tbaa !5
  %42 = call ptr @monotone_error(ptr noundef nonnull %6) #7
  %43 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %41, ptr noundef nonnull @.str.4, ptr noundef %42) #8
  br label %73

.thread:                                          ; preds = %22
  call void @llvm.lifetime.start.p0(i64 48, ptr nonnull %3) #7
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(48) %3, i8 0, i64 48, i1 false)
  %44 = call ptr @monotone_cursor(ptr noundef nonnull %6, ptr noundef null, ptr noundef nonnull %3) #7
  %45 = icmp eq ptr %44, null
  br i1 %45, label %46, label %.preheader

46:                                               ; preds = %.thread
  call void @monotone_free(ptr noundef nonnull %6) #7
  %47 = load ptr, ptr @stderr, align 8, !tbaa !5
  %48 = call ptr @monotone_error(ptr noundef nonnull %6) #7
  %49 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %47, ptr noundef nonnull @.str.5, ptr noundef %48) #8
  br label %72

.preheader:                                       ; preds = %.thread, %55
  %.0 = phi i32 [ %52, %55 ], [ 0, %.thread ]
  call void @llvm.lifetime.start.p0(i64 48, ptr nonnull %4) #7
  %50 = call i32 @monotone_read(ptr noundef nonnull %44, ptr noundef nonnull %4) #7
  switch i32 %50, label %51 [
    i32 -1, label %.loopexit.sink.split
    i32 0, label %.loopexit
  ]

51:                                               ; preds = %.preheader
  %52 = add nuw nsw i32 %.0, 1
  %53 = call i32 @monotone_next(ptr noundef nonnull %44) #7
  %54 = icmp eq i32 %53, -1
  br i1 %54, label %.loopexit.sink.split, label %55

55:                                               ; preds = %51
  call void @llvm.lifetime.end.p0(i64 48, ptr nonnull %4) #7
  br label %.preheader

.loopexit.sink.split:                             ; preds = %51, %.preheader
  %.str.6.sink = phi ptr [ @.str.6, %.preheader ], [ @.str.7, %51 ]
  %.1.ph.ph = phi i32 [ %.0, %.preheader ], [ %52, %51 ]
  %56 = load ptr, ptr @stderr, align 8, !tbaa !5
  %57 = call ptr @monotone_error(ptr noundef nonnull %6) #7
  %58 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %56, ptr noundef nonnull %.str.6.sink, ptr noundef %57) #8
  br label %.loopexit

.loopexit:                                        ; preds = %.preheader, %.loopexit.sink.split
  %.1.ph = phi i32 [ %.1.ph.ph, %.loopexit.sink.split ], [ %.0, %.preheader ]
  call void @llvm.lifetime.end.p0(i64 48, ptr nonnull %4) #7
  %59 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.8, i32 noundef %.1.ph)
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #7
  store ptr null, ptr %5, align 8, !tbaa !5
  %60 = call i32 @monotone_execute(ptr noundef nonnull %6, ptr noundef nonnull @.str.9, ptr noundef nonnull %5) #7
  %61 = icmp eq i32 %60, -1
  br i1 %61, label %62, label %66

62:                                               ; preds = %.loopexit
  %63 = load ptr, ptr @stderr, align 8, !tbaa !5
  %64 = call ptr @monotone_error(ptr noundef nonnull %6) #7
  %65 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %63, ptr noundef nonnull @.str.10, ptr noundef %64) #8
  br label %66

66:                                               ; preds = %62, %.loopexit
  %67 = load ptr, ptr %5, align 8, !tbaa !5
  %.not = icmp eq ptr %67, null
  br i1 %.not, label %71, label %68

68:                                               ; preds = %66
  %69 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.11, ptr noundef nonnull %67)
  %70 = load ptr, ptr %5, align 8, !tbaa !5
  call void @free(ptr noundef %70) #7
  br label %71

71:                                               ; preds = %68, %66
  call void @monotone_free(ptr noundef nonnull %44) #7
  call void @monotone_free(ptr noundef nonnull %6) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #7
  br label %72

72:                                               ; preds = %71, %46
  %.145 = phi i32 [ 1, %46 ], [ 0, %71 ]
  call void @llvm.lifetime.end.p0(i64 48, ptr nonnull %3) #7
  br label %73

73:                                               ; preds = %40, %72
  %.2 = phi i32 [ %.145, %72 ], [ 1, %40 ]
  call void @llvm.stackrestore.p0(ptr %20)
  br label %74

74:                                               ; preds = %15, %73, %8
  %.4 = phi i32 [ 1, %8 ], [ 1, %15 ], [ %.2, %73 ]
  ret i32 %.4
}

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

declare ptr @monotone_init() local_unnamed_addr #2

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

declare i32 @monotone_execute(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

declare i32 @monotone_open(ptr noundef, ptr noundef) local_unnamed_addr #2

declare void @monotone_free(ptr noundef) local_unnamed_addr #2

declare ptr @monotone_error(ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #4

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

declare i32 @monotone_write(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #2

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

declare ptr @monotone_cursor(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

declare i32 @monotone_read(ptr noundef, ptr noundef) local_unnamed_addr #2

declare i32 @monotone_next(ptr noundef) local_unnamed_addr #2

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

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #6

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #4

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #4 = { mustprogress nocallback nofree nosync nounwind willreturn }
attributes #5 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #6 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 #7 = { nounwind }
attributes #8 = { cold 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !13, i64 0}
!12 = !{!"monotone_event", !13, i64 0, !14, i64 8, !6, i64 16, !14, i64 24, !6, i64 32, !14, i64 40}
!13 = !{!"int", !7, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = !{!12, !14, i64 8}
!16 = distinct !{!16, !10}


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