; LLVM IR from pmwkaa/monotone :: monotone/cloud/cloud (cloud_mgr)

; 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.Runtime = type { %struct.ExceptionMgr, %struct.Error, ptr }
%struct.ExceptionMgr = type { ptr }
%struct.Error = type { [256 x i8], i32, ptr, ptr, i32, ptr, ptr }
%struct.Guard = type { ptr, ptr, ptr }
%struct.Context = type { ptr, ptr, ptr }
%struct.Global = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.Config = type { %struct.Var, %struct.Var, %struct.Var, %struct.Var, %struct.Var, %struct.Var, %struct.Var, %struct.Var, %struct.Var, %struct.Var, %struct.Var, %struct.Var, %struct.Var, %struct.Var, %struct.Var, %struct.Var, %struct.Var, %struct.Var, %struct.Var, %struct.Var, %struct.Var, %struct.Var, %struct.Var, %struct.Var, %struct.Var, %struct.Var, %struct.Var, %struct.Var, %struct.Var, %struct.Var, %struct.Var, %struct.Var, %struct.Var, %struct.Var, %struct.Var, %struct.Var, %struct.Var, %struct.Var, %struct.Var, %struct.List, %struct.List, i32, i32, i32, i32 }
%struct.Var = type { i32, i32, %struct.Str, %struct.List, %struct.List, %union.anon }
%struct.Str = type { ptr, ptr, i8 }
%union.anon = type { %struct.Str }
%struct.List = type { ptr, ptr }
%struct.Exception = type { ptr, i8, ptr, [1 x %struct.__jmp_buf_tag] }
%struct.__jmp_buf_tag = type { [8 x i64], i32, %struct.__sigset_t }
%struct.__sigset_t = type { [16 x i64] }

@mn_runtime = external thread_local global %struct.Runtime, align 8

; 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 @cloud_mgr_open(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca %struct.Guard, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #6
  %13 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @mn_runtime)
  %14 = getelementptr inbounds %struct.Runtime, ptr %13, i32 0, i32 2
  %15 = load ptr, ptr %14, align 8, !tbaa !9
  %16 = getelementptr inbounds %struct.Context, ptr %15, i32 0, i32 2
  %17 = load ptr, ptr %16, align 8, !tbaa !14
  %18 = getelementptr inbounds %struct.Global, ptr %17, i32 0, i32 0
  %19 = load ptr, ptr %18, align 8, !tbaa !16
  %20 = getelementptr inbounds %struct.Config, ptr %19, i32 0, i32 26
  store ptr %20, ptr %3, align 8, !tbaa !5
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = call zeroext i1 @var_data_is_set(ptr noundef %21)
  br i1 %22, label %24, label %23

23:                                               ; preds = %1
  store i32 1, ptr %4, align 4
  br label %61

24:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #6
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = call ptr @var_data_of(ptr noundef %25)
  store ptr %26, ptr %5, align 8, !tbaa !5
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = call zeroext i1 @data_is_null(ptr noundef %27) #7
  br i1 %28, label %29, label %30

29:                                               ; preds = %24
  store i32 1, ptr %4, align 4
  br label %60

30:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #6
  call void @data_read_array(ptr noundef %5, ptr noundef %6) #7
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #6
  store i32 0, ptr %7, align 4, !tbaa !18
  br label %31

31:                                               ; preds = %56, %30
  %32 = load i32, ptr %7, align 4, !tbaa !18
  %33 = load i32, ptr %6, align 4, !tbaa !18
  %34 = icmp slt i32 %32, %33
  br i1 %34, label %36, label %35

35:                                               ; preds = %31
  store i32 2, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #6
  br label %59

36:                                               ; preds = %31
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #6
  %37 = call ptr @cloud_config_read(ptr noundef %5)
  store ptr %37, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 24, ptr %9) #6
  %38 = getelementptr inbounds %struct.Guard, ptr %9, i32 0, i32 0
  store ptr @cloud_config_free, ptr %38, align 8, !tbaa !19
  %39 = getelementptr inbounds %struct.Guard, ptr %9, i32 0, i32 1
  %40 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %40, ptr %39, align 8, !tbaa !21
  %41 = getelementptr inbounds %struct.Guard, ptr %9, i32 0, i32 2
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #6
  %42 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @mn_runtime)
  %43 = getelementptr inbounds %struct.Runtime, ptr %42, i32 0, i32 0
  %44 = getelementptr inbounds %struct.ExceptionMgr, ptr %43, i32 0, i32 0
  %45 = load ptr, ptr %44, align 8, !tbaa !22
  store ptr %45, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #6
  %46 = load ptr, ptr %10, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.Exception, ptr %46, i32 0, i32 2
  %48 = load ptr, ptr %47, align 8, !tbaa !23
  store ptr %48, ptr %11, align 8, !tbaa !5
  %49 = load ptr, ptr %10, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.Exception, ptr %49, i32 0, i32 2
  store ptr %9, ptr %50, align 8, !tbaa !23
  %51 = load ptr, ptr %11, align 8, !tbaa !5
  store ptr %51, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #6
  %52 = load ptr, ptr %12, align 8, !tbaa !5
  store ptr %52, ptr %41, align 8, !tbaa !26
  %53 = load ptr, ptr %2, align 8, !tbaa !5
  %54 = load ptr, ptr %8, align 8, !tbaa !5
  %55 = call ptr @cloud_mgr_create_object(ptr noundef %53, ptr noundef %54)
  call void @guard_runner(ptr noundef %9)
  call void @llvm.lifetime.end.p0(i64 24, ptr %9) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #6
  br label %56

56:                                               ; preds = %36
  %57 = load i32, ptr %7, align 4, !tbaa !18
  %58 = add nsw i32 %57, 1
  store i32 %58, ptr %7, align 4, !tbaa !18
  br label %31, !llvm.loop !27

59:                                               ; preds = %35
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #6
  store i32 0, ptr %4, align 4
  br label %60

60:                                               ; preds = %59, %29
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #6
  br label %61

61:                                               ; preds = %60, %23
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #6
  %62 = load i32, ptr %4, align 4
  switch i32 %62, label %64 [
    i32 0, label %63
    i32 1, label %63
  ]

63:                                               ; preds = %61, %61
  ret void

64:                                               ; preds = %61
  unreachable
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare nonnull ptr @llvm.threadlocal.address.p0(ptr nonnull) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i1 @var_data_is_set(ptr noundef) #3

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @var_data_of(ptr noundef) #3

; Function Attrs: alwaysinline hot nounwind uwtable
declare hidden zeroext i1 @data_is_null(ptr noundef) #4

; Function Attrs: alwaysinline hot nounwind uwtable
declare hidden void @data_read_array(ptr noundef, ptr noundef) #4

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @cloud_config_read(ptr noundef) #3

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @cloud_config_free(ptr noundef) #3

; Function Attrs: alwaysinline nounwind uwtable
declare hidden void @guard_runner(ptr noundef) #5

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

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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { inlinehint 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 = { alwaysinline hot 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 #5 = { alwaysinline 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 #6 = { nounwind }
attributes #7 = { hot }

!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 312}
!10 = !{!"Runtime", !11, i64 0, !12, i64 8, !6, i64 312}
!11 = !{!"ExceptionMgr", !6, i64 0}
!12 = !{!"Error", !7, i64 0, !13, i64 256, !6, i64 264, !6, i64 272, !13, i64 280, !6, i64 288, !6, i64 296}
!13 = !{!"int", !7, i64 0}
!14 = !{!15, !6, i64 16}
!15 = !{!"Context", !6, i64 0, !6, i64 8, !6, i64 16}
!16 = !{!17, !6, i64 0}
!17 = !{!"Global", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48}
!18 = !{!13, !13, i64 0}
!19 = !{!20, !6, i64 0}
!20 = !{!"Guard", !6, i64 0, !6, i64 8, !6, i64 16}
!21 = !{!20, !6, i64 8}
!22 = !{!10, !6, i64 0}
!23 = !{!24, !6, i64 16}
!24 = !{!"Exception", !6, i64 0, !25, i64 8, !6, i64 16, !7, i64 24}
!25 = !{!"_Bool", !7, i64 0}
!26 = !{!20, !6, i64 16}
!27 = distinct !{!27, !28}
!28 = !{!"llvm.loop.mustprogress"}


; 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.Runtime = type { %struct.ExceptionMgr, %struct.Error, ptr }
%struct.ExceptionMgr = type { ptr }
%struct.Error = type { [256 x i8], i32, ptr, ptr, i32, ptr, ptr }
%struct.Guard = type { ptr, ptr, ptr }

@mn_runtime = external thread_local local_unnamed_addr global %struct.Runtime, align 8

; 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 @cloud_mgr_open(ptr noundef %0) local_unnamed_addr #1 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca %struct.Guard, align 8
  %5 = tail call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @mn_runtime)
  %6 = getelementptr inbounds i8, ptr %5, i64 312
  %7 = load ptr, ptr %6, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %7, i64 16
  %9 = load ptr, ptr %8, align 8, !tbaa !13
  %10 = load ptr, ptr %9, align 8, !tbaa !15
  %11 = getelementptr inbounds i8, ptr %10, i64 2288
  %12 = tail call zeroext i1 @var_data_is_set(ptr noundef nonnull %11)
  br i1 %12, label %13, label %31

13:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #6
  %14 = tail call ptr @var_data_of(ptr noundef nonnull %11)
  store ptr %14, ptr %2, align 8, !tbaa !17
  %15 = tail call zeroext i1 @data_is_null(ptr noundef %14) #7
  br i1 %15, label %30, label %16

16:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #6
  call void @data_read_array(ptr noundef nonnull %2, ptr noundef nonnull %3) #7
  %17 = load i32, ptr %3, align 4, !tbaa !18
  %18 = icmp sgt i32 %17, 0
  br i1 %18, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %16
  %19 = getelementptr inbounds i8, ptr %4, i64 8
  %20 = getelementptr inbounds i8, ptr %4, i64 16
  br label %21

._crit_edge:                                      ; preds = %21, %16
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #6
  br label %30

21:                                               ; preds = %.lr.ph, %21
  %.010 = phi i32 [ 0, %.lr.ph ], [ %27, %21 ]
  %22 = call ptr @cloud_config_read(ptr noundef nonnull %2)
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %4) #6
  store ptr @cloud_config_free, ptr %4, align 8, !tbaa !19
  store ptr %22, ptr %19, align 8, !tbaa !21
  %23 = load ptr, ptr %5, align 8, !tbaa !22
  %24 = getelementptr inbounds i8, ptr %23, i64 16
  %25 = load ptr, ptr %24, align 8, !tbaa !23
  store ptr %4, ptr %24, align 8, !tbaa !23
  store ptr %25, ptr %20, align 8, !tbaa !26
  %26 = call ptr @cloud_mgr_create_object(ptr noundef %0, ptr noundef %22)
  call void @guard_runner(ptr noundef nonnull %4)
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %4) #6
  %27 = add nuw nsw i32 %.010, 1
  %28 = load i32, ptr %3, align 4, !tbaa !18
  %29 = icmp slt i32 %27, %28
  br i1 %29, label %21, label %._crit_edge, !llvm.loop !27

30:                                               ; preds = %13, %._crit_edge
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #6
  br label %31

31:                                               ; preds = %1, %30
  ret void
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare nonnull ptr @llvm.threadlocal.address.p0(ptr nonnull) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i1 @var_data_is_set(ptr noundef) local_unnamed_addr #3

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @var_data_of(ptr noundef) local_unnamed_addr #3

; Function Attrs: alwaysinline hot nounwind uwtable
declare hidden zeroext i1 @data_is_null(ptr noundef) local_unnamed_addr #4

; Function Attrs: alwaysinline hot nounwind uwtable
declare hidden void @data_read_array(ptr noundef, ptr noundef) local_unnamed_addr #4

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @cloud_config_read(ptr noundef) local_unnamed_addr #3

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @cloud_config_free(ptr noundef) #3

; Function Attrs: alwaysinline nounwind uwtable
declare hidden void @guard_runner(ptr noundef) local_unnamed_addr #5

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

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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { inlinehint 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 = { alwaysinline hot 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 #5 = { alwaysinline 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 #6 = { nounwind }
attributes #7 = { hot }

!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, !8, i64 312}
!6 = !{!"Runtime", !7, i64 0, !11, i64 8, !8, i64 312}
!7 = !{!"ExceptionMgr", !8, i64 0}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"Error", !9, i64 0, !12, i64 256, !8, i64 264, !8, i64 272, !12, i64 280, !8, i64 288, !8, i64 296}
!12 = !{!"int", !9, i64 0}
!13 = !{!14, !8, i64 16}
!14 = !{!"Context", !8, i64 0, !8, i64 8, !8, i64 16}
!15 = !{!16, !8, i64 0}
!16 = !{!"Global", !8, i64 0, !8, i64 8, !8, i64 16, !8, i64 24, !8, i64 32, !8, i64 40, !8, i64 48}
!17 = !{!8, !8, i64 0}
!18 = !{!12, !12, i64 0}
!19 = !{!20, !8, i64 0}
!20 = !{!"Guard", !8, i64 0, !8, i64 8, !8, i64 16}
!21 = !{!20, !8, i64 8}
!22 = !{!6, !8, i64 0}
!23 = !{!24, !8, i64 16}
!24 = !{!"Exception", !8, i64 0, !25, i64 8, !8, i64 16, !9, i64 24}
!25 = !{!"_Bool", !9, i64 0}
!26 = !{!20, !8, i64 16}
!27 = distinct !{!27, !28}
!28 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass