; LLVM IR from alexzheng42/sDMD :: src (REMD)

; 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.REMDTempStr = type { i32, double }

@ReplicaExchange.is_initialized = external hidden global i32, align 4
@ReplicaExchange.sock = external hidden global i32, align 4
@.str.3 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [61 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(none)
declare i64 @llvm.expect.i64(i64, i64) #1

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

; 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 @ReplicaExchange(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) #3 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca double, align 8
  %11 = alloca %struct.REMDTempStr, align 8
  %12 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  store ptr %3, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #6
  call void @llvm.lifetime.start.p0(i64 16, ptr %11) #6
  %13 = load i32, ptr @ReplicaExchange.is_initialized, align 4, !tbaa !9
  %14 = icmp ne i32 %13, 0
  br i1 %14, label %20, label %15

15:                                               ; preds = %4
  %16 = load ptr, ptr %7, align 8, !tbaa !5
  %17 = load ptr, ptr %8, align 8, !tbaa !5
  %18 = load i32, ptr %17, align 4, !tbaa !9
  %19 = call i32 @client_open(ptr noundef %16, i32 noundef %18)
  store i32 %19, ptr @ReplicaExchange.sock, align 4, !tbaa !9
  store i32 1, ptr @ReplicaExchange.is_initialized, align 4, !tbaa !9
  br label %20

20:                                               ; preds = %15, %4
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = load double, ptr %21, align 8, !tbaa !11
  store double %22, ptr %10, align 8, !tbaa !11
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %11, ptr align 8 %23, i64 16, i1 false), !tbaa.struct !13
  %24 = load i32, ptr @ReplicaExchange.sock, align 4, !tbaa !9
  %25 = call i64 @write(i32 noundef %24, ptr noundef %10, i64 noundef 8)
  store i64 %25, ptr %9, align 8, !tbaa !14
  %26 = load i64, ptr %9, align 8, !tbaa !14
  %27 = icmp ne i64 %26, 8
  %28 = xor i1 %27, true
  %29 = xor i1 %28, true
  %30 = zext i1 %29 to i32
  %31 = sext i32 %30 to i64
  %32 = call i64 @llvm.expect.i64(i64 %31, i64 0)
  %33 = icmp ne i64 %32, 0
  br i1 %33, label %34, label %35

34:                                               ; preds = %20
  call void @perror(ptr noundef @.str.3)
  call void @exit(i32 noundef 1) #7
  unreachable

35:                                               ; preds = %20
  %36 = load i32, ptr @ReplicaExchange.sock, align 4, !tbaa !9
  %37 = call i64 @write(i32 noundef %36, ptr noundef %11, i64 noundef 16)
  store i64 %37, ptr %9, align 8, !tbaa !14
  %38 = load i64, ptr %9, align 8, !tbaa !14
  %39 = icmp ne i64 %38, 16
  %40 = xor i1 %39, true
  %41 = xor i1 %40, true
  %42 = zext i1 %41 to i32
  %43 = sext i32 %42 to i64
  %44 = call i64 @llvm.expect.i64(i64 %43, i64 0)
  %45 = icmp ne i64 %44, 0
  br i1 %45, label %46, label %47

46:                                               ; preds = %35
  call void @perror(ptr noundef @.str.3)
  call void @exit(i32 noundef 1) #7
  unreachable

47:                                               ; preds = %35
  %48 = load ptr, ptr %5, align 8, !tbaa !5
  %49 = load double, ptr %48, align 8, !tbaa !11
  %50 = fcmp oeq double %49, 0.000000e+00
  br i1 %50, label %51, label %56

51:                                               ; preds = %47
  %52 = load ptr, ptr %6, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.REMDTempStr, ptr %52, i32 0, i32 1
  %54 = load double, ptr %53, align 8, !tbaa !16
  %55 = fcmp oeq double %54, 0.000000e+00
  br label %56

56:                                               ; preds = %51, %47
  %57 = phi i1 [ false, %47 ], [ %55, %51 ]
  %58 = xor i1 %57, true
  %59 = xor i1 %58, true
  %60 = zext i1 %59 to i32
  %61 = sext i32 %60 to i64
  %62 = call i64 @llvm.expect.i64(i64 %61, i64 0)
  %63 = icmp ne i64 %62, 0
  br i1 %63, label %64, label %67

64:                                               ; preds = %56
  %65 = load i32, ptr @ReplicaExchange.sock, align 4, !tbaa !9
  %66 = call i32 @close(i32 noundef %65)
  store i32 1, ptr %12, align 4
  br label %89

67:                                               ; preds = %56
  %68 = getelementptr inbounds %struct.REMDTempStr, ptr %11, i32 0, i32 1
  store double 0.000000e+00, ptr %68, align 8, !tbaa !16
  %69 = load i32, ptr @ReplicaExchange.sock, align 4, !tbaa !9
  %70 = call i64 @read(i32 noundef %69, ptr noundef %11, i64 noundef 16)
  store i64 %70, ptr %9, align 8, !tbaa !14
  %71 = load i64, ptr %9, align 8, !tbaa !14
  %72 = icmp ne i64 %71, 16
  br i1 %72, label %73, label %77

73:                                               ; preds = %67
  %74 = getelementptr inbounds %struct.REMDTempStr, ptr %11, i32 0, i32 1
  %75 = load double, ptr %74, align 8, !tbaa !16
  %76 = fcmp une double %75, 0.000000e+00
  br label %77

77:                                               ; preds = %73, %67
  %78 = phi i1 [ false, %67 ], [ %76, %73 ]
  %79 = xor i1 %78, true
  %80 = xor i1 %79, true
  %81 = zext i1 %80 to i32
  %82 = sext i32 %81 to i64
  %83 = call i64 @llvm.expect.i64(i64 %82, i64 0)
  %84 = icmp ne i64 %83, 0
  br i1 %84, label %85, label %87

85:                                               ; preds = %77
  call void @perror(ptr noundef @.str.4)
  %86 = call i32 (ptr, ...) @printf(ptr noundef @.str.5, ptr noundef @.str.6, i32 noundef 185)
  call void @exit(i32 noundef 1) #7
  unreachable

87:                                               ; preds = %77
  %88 = load ptr, ptr %6, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %88, ptr align 8 %11, i64 16, i1 false), !tbaa.struct !13
  store i32 1, ptr %12, align 4
  br label %89

89:                                               ; preds = %87, %64
  call void @llvm.lifetime.end.p0(i64 16, ptr %11) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #6
  ret void
}

; Function Attrs: nounwind uwtable
declare dso_local i32 @client_open(ptr noundef, i32 noundef) #3

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #4

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

declare void @perror(ptr noundef) #2

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) #5

declare i32 @close(i32 noundef) #2

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(none) }
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 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 #4 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { noreturn 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 }
attributes #7 = { noreturn 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, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = !{i64 0, i64 4, !9, i64 8, i64 8, !11}
!14 = !{!15, !15, i64 0}
!15 = !{!"long", !7, i64 0}
!16 = !{!17, !12, i64 8}
!17 = !{!"REMDTempStr", !10, i64 0, !12, i64 8}


; 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.REMDTempStr = type { i32, double }

@ReplicaExchange.is_initialized = external hidden local_unnamed_addr global i32, align 4
@ReplicaExchange.sock = external hidden local_unnamed_addr global i32, align 4
@.str.3 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [61 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: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) 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 void @ReplicaExchange(ptr nocapture noundef readonly %0, ptr nocapture noundef %1, ptr noundef %2, ptr nocapture noundef readonly %3) local_unnamed_addr #2 {
  %5 = alloca double, align 8
  %6 = alloca %struct.REMDTempStr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #7
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %6) #7
  %7 = load i32, ptr @ReplicaExchange.is_initialized, align 4, !tbaa !5
  %.not = icmp eq i32 %7, 0
  br i1 %.not, label %8, label %._crit_edge

._crit_edge:                                      ; preds = %4
  %.pre = load i32, ptr @ReplicaExchange.sock, align 4, !tbaa !5
  br label %11

8:                                                ; preds = %4
  %9 = load i32, ptr %3, align 4, !tbaa !5
  %10 = tail call i32 @client_open(ptr noundef %2, i32 noundef %9)
  store i32 %10, ptr @ReplicaExchange.sock, align 4, !tbaa !5
  store i32 1, ptr @ReplicaExchange.is_initialized, align 4, !tbaa !5
  br label %11

11:                                               ; preds = %._crit_edge, %8
  %12 = phi i32 [ %.pre, %._crit_edge ], [ %10, %8 ]
  %13 = load double, ptr %0, align 8, !tbaa !9
  store double %13, ptr %5, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %6, ptr noundef nonnull align 8 dereferenceable(16) %1, i64 16, i1 false), !tbaa.struct !11
  %14 = call i64 @write(i32 noundef %12, ptr noundef nonnull %5, i64 noundef 8) #7
  %.not9 = icmp eq i64 %14, 8
  br i1 %.not9, label %16, label %15, !prof !12

15:                                               ; preds = %11
  tail call void @perror(ptr noundef nonnull @.str.3) #8
  tail call void @exit(i32 noundef 1) #9
  unreachable

16:                                               ; preds = %11
  %17 = load i32, ptr @ReplicaExchange.sock, align 4, !tbaa !5
  %18 = call i64 @write(i32 noundef %17, ptr noundef nonnull %6, i64 noundef 16) #7
  %.not10 = icmp eq i64 %18, 16
  br i1 %.not10, label %20, label %19, !prof !12

19:                                               ; preds = %16
  tail call void @perror(ptr noundef nonnull @.str.3) #8
  tail call void @exit(i32 noundef 1) #9
  unreachable

20:                                               ; preds = %16
  %21 = load double, ptr %0, align 8, !tbaa !9
  %22 = fcmp oeq double %21, 0.000000e+00
  br i1 %22, label %23, label %.critedge

23:                                               ; preds = %20
  %24 = getelementptr inbounds i8, ptr %1, i64 8
  %25 = load double, ptr %24, align 8, !tbaa !13
  %26 = fcmp oeq double %25, 0.000000e+00
  br i1 %26, label %27, label %.critedge, !prof !15

27:                                               ; preds = %23
  %28 = load i32, ptr @ReplicaExchange.sock, align 4, !tbaa !5
  %29 = tail call i32 @close(i32 noundef %28) #7
  br label %40

.critedge:                                        ; preds = %20, %23
  %30 = getelementptr inbounds i8, ptr %6, i64 8
  store double 0.000000e+00, ptr %30, align 8, !tbaa !13
  %31 = load i32, ptr @ReplicaExchange.sock, align 4, !tbaa !5
  %32 = call i64 @read(i32 noundef %31, ptr noundef nonnull %6, i64 noundef 16) #7
  %33 = icmp ne i64 %32, 16
  %34 = load double, ptr %30, align 8
  %35 = fcmp une double %34, 0.000000e+00
  %36 = select i1 %33, i1 %35, i1 false
  br i1 %36, label %37, label %39, !prof !15

37:                                               ; preds = %.critedge
  tail call void @perror(ptr noundef nonnull @.str.4) #8
  %38 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.5, ptr noundef nonnull @.str.6, i32 noundef 185)
  tail call void @exit(i32 noundef 1) #9
  unreachable

39:                                               ; preds = %.critedge
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %1, ptr noundef nonnull align 8 dereferenceable(16) %6, i64 16, i1 false), !tbaa.struct !11
  br label %40

40:                                               ; preds = %39, %27
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %6) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #7
  ret void
}

; Function Attrs: nounwind uwtable
declare dso_local i32 @client_open(ptr noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

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

; Function Attrs: nofree nounwind
declare void @perror(ptr nocapture noundef readonly) local_unnamed_addr #1

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) local_unnamed_addr #5

declare i32 @close(i32 noundef) local_unnamed_addr #6

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = { noreturn 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 = { "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 }
attributes #9 = { noreturn 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 = !{!"double", !7, i64 0}
!11 = !{i64 0, i64 4, !5, i64 8, i64 8, !9}
!12 = !{!"branch_weights", !"expected", i32 2000, i32 1}
!13 = !{!14, !10, i64 8}
!14 = !{!"REMDTempStr", !6, i64 0, !10, i64 8}
!15 = !{!"branch_weights", !"expected", i32 1, i32 2000}


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