; LLVM IR from jingweizhanghuai/Morn :: src/ptc (morn_message)

; 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.HandleProcTopic = type { [256 x i8], i32, i32, i32, i32, ptr, i64 }
%struct.ProcTopicInfo = type { i32, i32, i32, i32, i32, i32, i64, [128 x %struct.ProcCommunicateState], [0 x i8] }
%struct.ProcCommunicateState = type { i32, i32 }

@.str = external hidden unnamed_addr constant [78 x i8], align 1
@__FUNCTION__.endProcTopic = external hidden unnamed_addr constant [13 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [22 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @endProcTopic(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.HandleProcTopic, ptr %9, i32 0, i32 5
  %11 = load ptr, ptr %10, align 8, !tbaa !9
  %12 = icmp eq ptr %11, null
  br i1 %12, label %13, label %14

13:                                               ; preds = %1
  br label %113

14:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  %15 = load ptr, ptr %2, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.HandleProcTopic, ptr %15, i32 0, i32 5
  %17 = load ptr, ptr %16, align 8, !tbaa !9
  store ptr %17, ptr %3, align 8, !tbaa !5
  %18 = load ptr, ptr %2, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.HandleProcTopic, ptr %18, i32 0, i32 2
  %20 = load i32, ptr %19, align 4, !tbaa !13
  %21 = call i32 @flock(i32 noundef %20, i32 noundef 2) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  br label %22

22:                                               ; preds = %14
  br label %23

23:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  %24 = load ptr, ptr %2, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.HandleProcTopic, ptr %24, i32 0, i32 2
  %26 = load i32, ptr %25, align 4, !tbaa !13
  %27 = call i64 @lseek(i32 noundef %26, i64 noundef 4, i32 noundef 0) #4
  %28 = icmp ne i64 %27, 4
  %29 = zext i1 %28 to i32
  store i32 %29, ptr %5, align 4, !tbaa !14
  %30 = load i32, ptr %5, align 4, !tbaa !14
  %31 = icmp ne i32 %30, 0
  br i1 %31, label %32, label %34

32:                                               ; preds = %23
  %33 = load i32, ptr %5, align 4, !tbaa !14
  call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef %33, i32 noundef -1, ptr noundef @.str, i32 noundef 119, ptr noundef @__FUNCTION__.endProcTopic, ptr noundef @.str.1)
  br label %34

34:                                               ; preds = %32, %23
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  br label %35

35:                                               ; preds = %34
  br label %36

36:                                               ; preds = %35
  br label %37

37:                                               ; preds = %36
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %38 = load ptr, ptr %2, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.HandleProcTopic, ptr %38, i32 0, i32 2
  %40 = load i32, ptr %39, align 4, !tbaa !13
  %41 = call i64 @read(i32 noundef %40, ptr noundef %4, i64 noundef 4)
  %42 = icmp ne i64 %41, 4
  %43 = zext i1 %42 to i32
  store i32 %43, ptr %6, align 4, !tbaa !14
  %44 = load i32, ptr %6, align 4, !tbaa !14
  %45 = icmp ne i32 %44, 0
  br i1 %45, label %46, label %48

46:                                               ; preds = %37
  %47 = load i32, ptr %6, align 4, !tbaa !14
  call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef %47, i32 noundef -1, ptr noundef @.str, i32 noundef 119, ptr noundef @__FUNCTION__.endProcTopic, ptr noundef @.str.2)
  br label %48

48:                                               ; preds = %46, %37
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  br label %49

49:                                               ; preds = %48
  br label %50

50:                                               ; preds = %49
  br label %51

51:                                               ; preds = %50
  br label %52

52:                                               ; preds = %51
  %53 = load i32, ptr %4, align 4, !tbaa !14
  %54 = add nsw i32 %53, -1
  store i32 %54, ptr %4, align 4, !tbaa !14
  br label %55

55:                                               ; preds = %52
  br label %56

56:                                               ; preds = %55
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %57 = load ptr, ptr %2, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.HandleProcTopic, ptr %57, i32 0, i32 2
  %59 = load i32, ptr %58, align 4, !tbaa !13
  %60 = call i64 @lseek(i32 noundef %59, i64 noundef 4, i32 noundef 0) #4
  %61 = icmp ne i64 %60, 4
  %62 = zext i1 %61 to i32
  store i32 %62, ptr %7, align 4, !tbaa !14
  %63 = load i32, ptr %7, align 4, !tbaa !14
  %64 = icmp ne i32 %63, 0
  br i1 %64, label %65, label %67

65:                                               ; preds = %56
  %66 = load i32, ptr %7, align 4, !tbaa !14
  call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef %66, i32 noundef -1, ptr noundef @.str, i32 noundef 120, ptr noundef @__FUNCTION__.endProcTopic, ptr noundef @.str.1)
  br label %67

67:                                               ; preds = %65, %56
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %68

68:                                               ; preds = %67
  br label %69

69:                                               ; preds = %68
  br label %70

70:                                               ; preds = %69
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %71 = load ptr, ptr %2, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.HandleProcTopic, ptr %71, i32 0, i32 2
  %73 = load i32, ptr %72, align 4, !tbaa !13
  %74 = call i64 @write(i32 noundef %73, ptr noundef %4, i64 noundef 4)
  %75 = icmp ne i64 %74, 4
  %76 = zext i1 %75 to i32
  store i32 %76, ptr %8, align 4, !tbaa !14
  %77 = load i32, ptr %8, align 4, !tbaa !14
  %78 = icmp ne i32 %77, 0
  br i1 %78, label %79, label %81

79:                                               ; preds = %70
  %80 = load i32, ptr %8, align 4, !tbaa !14
  call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef %80, i32 noundef -1, ptr noundef @.str, i32 noundef 120, ptr noundef @__FUNCTION__.endProcTopic, ptr noundef @.str.3)
  br label %81

81:                                               ; preds = %79, %70
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  br label %82

82:                                               ; preds = %81
  br label %83

83:                                               ; preds = %82
  br label %84

84:                                               ; preds = %83
  br label %85

85:                                               ; preds = %84
  %86 = load i32, ptr %4, align 4, !tbaa !14
  %87 = load ptr, ptr %3, align 8, !tbaa !5
  %88 = getelementptr inbounds %struct.ProcTopicInfo, ptr %87, i32 0, i32 1
  store volatile i32 %86, ptr %88, align 4, !tbaa !15
  %89 = load ptr, ptr %2, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.HandleProcTopic, ptr %89, i32 0, i32 2
  %91 = load i32, ptr %90, align 4, !tbaa !13
  %92 = call i32 @flock(i32 noundef %91, i32 noundef 8) #4
  %93 = load ptr, ptr %3, align 8, !tbaa !5
  %94 = load ptr, ptr %2, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct.HandleProcTopic, ptr %94, i32 0, i32 3
  %96 = load i32, ptr %95, align 8, !tbaa !17
  %97 = sext i32 %96 to i64
  %98 = add i64 %97, 1056
  %99 = call i32 @munmap(ptr noundef %93, i64 noundef %98) #4
  %100 = load ptr, ptr %2, align 8, !tbaa !5
  %101 = getelementptr inbounds %struct.HandleProcTopic, ptr %100, i32 0, i32 2
  %102 = load i32, ptr %101, align 4, !tbaa !13
  %103 = call i32 @close(i32 noundef %102)
  %104 = load i32, ptr %4, align 4, !tbaa !14
  %105 = icmp eq i32 %104, 0
  br i1 %105, label %106, label %112

106:                                              ; preds = %85
  %107 = call i32 @usleep(i32 noundef 10000)
  %108 = load ptr, ptr %2, align 8, !tbaa !5
  %109 = getelementptr inbounds %struct.HandleProcTopic, ptr %108, i32 0, i32 0
  %110 = getelementptr inbounds [256 x i8], ptr %109, i64 0, i64 0
  %111 = call i32 @remove(ptr noundef %110) #4
  br label %112

112:                                              ; preds = %106, %85
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  br label %113

113:                                              ; preds = %112, %13
  ret void
}

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

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

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

declare void @m_Exception(i32 noundef, i32 noundef, ptr noundef, i32 noundef, ptr noundef, ptr noundef, ...) #3

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

declare i64 @read(i32 noundef, ptr noundef, i64 noundef) #3

declare i64 @write(i32 noundef, ptr noundef, i64 noundef) #3

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

declare i32 @close(i32 noundef) #3

declare i32 @usleep(i32 noundef) #3

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

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 = { 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, !6, i64 272}
!10 = !{!"HandleProcTopic", !7, i64 0, !11, i64 256, !11, i64 260, !11, i64 264, !11, i64 268, !6, i64 272, !12, i64 280}
!11 = !{!"int", !7, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!10, !11, i64 260}
!14 = !{!11, !11, i64 0}
!15 = !{!16, !11, i64 4}
!16 = !{!"ProcTopicInfo", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !12, i64 24, !7, i64 32, !7, i64 1056}
!17 = !{!10, !11, i64 264}


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

@.str = external hidden unnamed_addr constant [78 x i8], align 1
@__FUNCTION__.endProcTopic = external hidden unnamed_addr constant [13 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [22 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @endProcTopic(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
  %2 = alloca i32, align 4
  %3 = getelementptr inbounds i8, ptr %0, i64 272
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = icmp eq ptr %4, null
  br i1 %5, label %43, label %6

6:                                                ; preds = %1
  %7 = getelementptr inbounds i8, ptr %0, i64 260
  %8 = load i32, ptr %7, align 4, !tbaa !12
  %9 = tail call i32 @flock(i32 noundef %8, i32 noundef 2) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #6
  %10 = load i32, ptr %7, align 4, !tbaa !12
  %11 = tail call i64 @lseek(i32 noundef %10, i64 noundef 4, i32 noundef 0) #6
  %.not = icmp eq i64 %11, 4
  br i1 %.not, label %13, label %12

12:                                               ; preds = %6
  tail call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef 1, i32 noundef -1, ptr noundef nonnull @.str, i32 noundef 119, ptr noundef nonnull @__FUNCTION__.endProcTopic, ptr noundef nonnull @.str.1) #6
  br label %13

13:                                               ; preds = %12, %6
  %14 = load i32, ptr %7, align 4, !tbaa !12
  %15 = call i64 @read(i32 noundef %14, ptr noundef nonnull %2, i64 noundef 4) #6
  %.not20 = icmp eq i64 %15, 4
  br i1 %.not20, label %17, label %16

16:                                               ; preds = %13
  tail call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef 1, i32 noundef -1, ptr noundef nonnull @.str, i32 noundef 119, ptr noundef nonnull @__FUNCTION__.endProcTopic, ptr noundef nonnull @.str.2) #6
  br label %17

17:                                               ; preds = %16, %13
  %18 = load i32, ptr %2, align 4, !tbaa !13
  %19 = add nsw i32 %18, -1
  store i32 %19, ptr %2, align 4, !tbaa !13
  %20 = load i32, ptr %7, align 4, !tbaa !12
  %21 = tail call i64 @lseek(i32 noundef %20, i64 noundef 4, i32 noundef 0) #6
  %.not21 = icmp eq i64 %21, 4
  br i1 %.not21, label %23, label %22

22:                                               ; preds = %17
  tail call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef 1, i32 noundef -1, ptr noundef nonnull @.str, i32 noundef 120, ptr noundef nonnull @__FUNCTION__.endProcTopic, ptr noundef nonnull @.str.1) #6
  br label %23

23:                                               ; preds = %22, %17
  %24 = load i32, ptr %7, align 4, !tbaa !12
  %25 = call i64 @write(i32 noundef %24, ptr noundef nonnull %2, i64 noundef 4) #6
  %.not22 = icmp eq i64 %25, 4
  br i1 %.not22, label %27, label %26

26:                                               ; preds = %23
  tail call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef 1, i32 noundef -1, ptr noundef nonnull @.str, i32 noundef 120, ptr noundef nonnull @__FUNCTION__.endProcTopic, ptr noundef nonnull @.str.3) #6
  br label %27

27:                                               ; preds = %26, %23
  %28 = getelementptr inbounds i8, ptr %4, i64 4
  store volatile i32 %19, ptr %28, align 4, !tbaa !14
  %29 = load i32, ptr %7, align 4, !tbaa !12
  %30 = tail call i32 @flock(i32 noundef %29, i32 noundef 8) #6
  %31 = getelementptr inbounds i8, ptr %0, i64 264
  %32 = load i32, ptr %31, align 8, !tbaa !16
  %33 = sext i32 %32 to i64
  %34 = add nsw i64 %33, 1056
  %35 = tail call i32 @munmap(ptr noundef nonnull %4, i64 noundef %34) #6
  %36 = load i32, ptr %7, align 4, !tbaa !12
  %37 = tail call i32 @close(i32 noundef %36) #6
  %38 = icmp eq i32 %19, 0
  br i1 %38, label %39, label %42

39:                                               ; preds = %27
  %40 = tail call i32 @usleep(i32 noundef 10000) #6
  %41 = tail call i32 @remove(ptr noundef nonnull %0) #6
  br label %42

42:                                               ; preds = %39, %27
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #6
  br label %43

43:                                               ; preds = %1, %42
  ret void
}

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

; Function Attrs: nounwind
declare i32 @flock(i32 noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: nounwind
declare i64 @lseek(i32 noundef, i64 noundef, i32 noundef) local_unnamed_addr #2

declare void @m_Exception(i32 noundef, i32 noundef, ptr noundef, i32 noundef, ptr noundef, ptr noundef, ...) local_unnamed_addr #3

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

; Function Attrs: nofree
declare noundef i64 @read(i32 noundef, ptr nocapture noundef, i64 noundef) local_unnamed_addr #4

; Function Attrs: nofree
declare noundef i64 @write(i32 noundef, ptr nocapture noundef readonly, i64 noundef) local_unnamed_addr #4

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

declare i32 @close(i32 noundef) local_unnamed_addr #3

declare i32 @usleep(i32 noundef) local_unnamed_addr #3

; Function Attrs: nofree nounwind
declare noundef i32 @remove(ptr nocapture noundef readonly) local_unnamed_addr #5

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 = { 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 = { nofree "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 = { 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 #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, !10, i64 272}
!6 = !{!"HandleProcTopic", !7, i64 0, !9, i64 256, !9, i64 260, !9, i64 264, !9, i64 268, !10, i64 272, !11, i64 280}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"int", !7, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!"long", !7, i64 0}
!12 = !{!6, !9, i64 260}
!13 = !{!9, !9, i64 0}
!14 = !{!15, !9, i64 4}
!15 = !{!"ProcTopicInfo", !9, i64 0, !9, i64 4, !9, i64 8, !9, i64 12, !9, i64 16, !9, i64 20, !11, i64 24, !7, i64 32, !7, i64 1056}
!16 = !{!6, !9, i64 264}


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