; LLVM IR from holzschu/ios_system :: curl/curl/docs/examples (http2-pushinmemory)

; 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.Memory = type { ptr, i64 }
%struct.CURLMsg = type { i32, ptr, %union.anon }
%union.anon = type { ptr }

@pushindex = external hidden global i32, align 4
@files = external hidden global [10 x %struct.Memory], align 16

; Function Attrs: nounwind uwtable
define dso_local i32 @main() #0 {
  %1 = alloca i32, align 4
  %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 ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 1, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %13 = call ptr @curl_multi_init()
  store ptr %13, ptr %3, align 8, !tbaa !9
  %14 = call ptr @curl_easy_init()
  store ptr %14, ptr %2, align 8, !tbaa !9
  %15 = load ptr, ptr %2, align 8, !tbaa !9
  call void @setup(ptr noundef %15)
  %16 = load ptr, ptr %3, align 8, !tbaa !9
  %17 = load ptr, ptr %2, align 8, !tbaa !9
  %18 = call i32 @curl_multi_add_handle(ptr noundef %16, ptr noundef %17)
  %19 = load ptr, ptr %3, align 8, !tbaa !9
  %20 = call i32 (ptr, i32, ...) @curl_multi_setopt(ptr noundef %19, i32 noundef 3, i64 noundef 2)
  %21 = load ptr, ptr %3, align 8, !tbaa !9
  %22 = call i32 (ptr, i32, ...) @curl_multi_setopt(ptr noundef %21, i32 noundef 20014, ptr noundef @server_push_callback)
  %23 = load ptr, ptr %3, align 8, !tbaa !9
  %24 = call i32 (ptr, i32, ...) @curl_multi_setopt(ptr noundef %23, i32 noundef 10015, ptr noundef %5)
  br label %25

25:                                               ; preds = %68, %0
  %26 = load i32, ptr %5, align 4, !tbaa !5
  %27 = icmp ne i32 %26, 0
  br i1 %27, label %28, label %69

28:                                               ; preds = %25
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  %29 = load ptr, ptr %3, align 8, !tbaa !9
  %30 = call i32 @curl_multi_perform(ptr noundef %29, ptr noundef %4)
  store i32 %30, ptr %9, align 4, !tbaa !5
  %31 = load i32, ptr %9, align 4, !tbaa !5
  %32 = icmp ne i32 %31, 0
  br i1 %32, label %33, label %34

33:                                               ; preds = %28
  store i32 3, ptr %10, align 4
  br label %66

34:                                               ; preds = %28
  %35 = load ptr, ptr %3, align 8, !tbaa !9
  %36 = call i32 @curl_multi_wait(ptr noundef %35, ptr noundef null, i32 noundef 0, i32 noundef 1000, ptr noundef %8)
  store i32 %36, ptr %9, align 4, !tbaa !5
  %37 = load i32, ptr %9, align 4, !tbaa !5
  %38 = icmp ne i32 %37, 0
  br i1 %38, label %39, label %40

39:                                               ; preds = %34
  store i32 3, ptr %10, align 4
  br label %66

40:                                               ; preds = %34
  br label %41

41:                                               ; preds = %62, %40
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  store i32 0, ptr %11, align 4, !tbaa !5
  %42 = load ptr, ptr %3, align 8, !tbaa !9
  %43 = call ptr @curl_multi_info_read(ptr noundef %42, ptr noundef %11)
  store ptr %43, ptr %7, align 8, !tbaa !9
  %44 = load ptr, ptr %7, align 8, !tbaa !9
  %45 = icmp ne ptr %44, null
  br i1 %45, label %46, label %61

46:                                               ; preds = %41
  %47 = load ptr, ptr %7, align 8, !tbaa !9
  %48 = getelementptr inbounds %struct.CURLMsg, ptr %47, i32 0, i32 0
  %49 = load i32, ptr %48, align 8, !tbaa !11
  %50 = icmp eq i32 %49, 1
  br i1 %50, label %51, label %61

51:                                               ; preds = %46
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %52 = load ptr, ptr %7, align 8, !tbaa !9
  %53 = getelementptr inbounds %struct.CURLMsg, ptr %52, i32 0, i32 1
  %54 = load ptr, ptr %53, align 8, !tbaa !13
  store ptr %54, ptr %12, align 8, !tbaa !9
  %55 = load i32, ptr %5, align 4, !tbaa !5
  %56 = add nsw i32 %55, -1
  store i32 %56, ptr %5, align 4, !tbaa !5
  %57 = load ptr, ptr %3, align 8, !tbaa !9
  %58 = load ptr, ptr %12, align 8, !tbaa !9
  %59 = call i32 @curl_multi_remove_handle(ptr noundef %57, ptr noundef %58)
  %60 = load ptr, ptr %12, align 8, !tbaa !9
  call void @curl_easy_cleanup(ptr noundef %60)
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  br label %61

61:                                               ; preds = %51, %46, %41
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  br label %62

62:                                               ; preds = %61
  %63 = load ptr, ptr %7, align 8, !tbaa !9
  %64 = icmp ne ptr %63, null
  br i1 %64, label %41, label %65, !llvm.loop !14

65:                                               ; preds = %62
  store i32 0, ptr %10, align 4
  br label %66

66:                                               ; preds = %65, %39, %33
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  %67 = load i32, ptr %10, align 4
  switch i32 %67, label %87 [
    i32 0, label %68
    i32 3, label %69
  ]

68:                                               ; preds = %66
  br label %25, !llvm.loop !16

69:                                               ; preds = %66, %25
  %70 = load ptr, ptr %3, align 8, !tbaa !9
  %71 = call i32 @curl_multi_cleanup(ptr noundef %70)
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %72

72:                                               ; preds = %82, %69
  %73 = load i32, ptr %6, align 4, !tbaa !5
  %74 = load i32, ptr @pushindex, align 4, !tbaa !5
  %75 = icmp slt i32 %73, %74
  br i1 %75, label %76, label %85

76:                                               ; preds = %72
  %77 = load i32, ptr %6, align 4, !tbaa !5
  %78 = sext i32 %77 to i64
  %79 = getelementptr inbounds [10 x %struct.Memory], ptr @files, i64 0, i64 %78
  %80 = getelementptr inbounds %struct.Memory, ptr %79, i32 0, i32 0
  %81 = load ptr, ptr %80, align 16, !tbaa !17
  call void @free(ptr noundef %81) #4
  br label %82

82:                                               ; preds = %76
  %83 = load i32, ptr %6, align 4, !tbaa !5
  %84 = add nsw i32 %83, 1
  store i32 %84, ptr %6, align 4, !tbaa !5
  br label %72, !llvm.loop !20

85:                                               ; preds = %72
  store i32 0, ptr %1, align 4
  store i32 1, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #4
  %86 = load i32, ptr %1, align 4
  ret i32 %86

87:                                               ; preds = %66
  unreachable
}

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

declare ptr @curl_multi_init() #2

declare ptr @curl_easy_init() #2

; Function Attrs: nounwind uwtable
declare hidden void @setup(ptr noundef) #0

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

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

; Function Attrs: nounwind uwtable
declare hidden i32 @server_push_callback(ptr noundef, ptr noundef, i64 noundef, ptr noundef, ptr noundef) #0

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

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

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

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

declare void @curl_easy_cleanup(ptr noundef) #2

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

declare i32 @curl_multi_cleanup(ptr noundef) #2

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

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 = { 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 = !{!"CURLMsg", !6, i64 0, !10, i64 8, !7, i64 16}
!13 = !{!12, !10, i64 8}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}
!17 = !{!18, !10, i64 0}
!18 = !{!"Memory", !10, i64 0, !19, i64 8}
!19 = !{!"long", !7, i64 0}
!20 = distinct !{!20, !15}


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

@pushindex = external hidden local_unnamed_addr global i32, align 4
@files = external hidden local_unnamed_addr global [10 x %struct.Memory], align 16

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #4
  store i32 1, ptr %2, align 4, !tbaa !5
  %5 = tail call ptr @curl_multi_init() #4
  %6 = tail call ptr @curl_easy_init() #4
  tail call void @setup(ptr noundef %6)
  %7 = tail call i32 @curl_multi_add_handle(ptr noundef %5, ptr noundef %6) #4
  %8 = tail call i32 (ptr, i32, ...) @curl_multi_setopt(ptr noundef %5, i32 noundef 3, i64 noundef 2) #4
  %9 = tail call i32 (ptr, i32, ...) @curl_multi_setopt(ptr noundef %5, i32 noundef 20014, ptr noundef nonnull @server_push_callback) #4
  %10 = call i32 (ptr, i32, ...) @curl_multi_setopt(ptr noundef %5, i32 noundef 10015, ptr noundef nonnull %2) #4
  %.old = load i32, ptr %2, align 4, !tbaa !5
  %.not.old = icmp eq i32 %.old, 0
  br i1 %.not.old, label %.loopexit, label %.preheader32

.preheader32:                                     ; preds = %0, %._crit_edge
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #4
  %11 = call i32 @curl_multi_perform(ptr noundef %5, ptr noundef nonnull %1) #4
  %.not25 = icmp eq i32 %11, 0
  br i1 %.not25, label %12, label %.thread

12:                                               ; preds = %.preheader32
  %13 = call i32 @curl_multi_wait(ptr noundef %5, ptr noundef null, i32 noundef 0, i32 noundef 1000, ptr noundef nonnull %3) #4
  %.not26 = icmp eq i32 %13, 0
  br i1 %.not26, label %.preheader, label %.thread

.preheader:                                       ; preds = %12
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #4
  store i32 0, ptr %4, align 4, !tbaa !5
  %14 = call ptr @curl_multi_info_read(ptr noundef %5, ptr noundef nonnull %4) #4
  %.not2733 = icmp eq ptr %14, null
  br i1 %.not2733, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader, %24
  %15 = phi ptr [ %25, %24 ], [ %14, %.preheader ]
  %16 = load i32, ptr %15, align 8, !tbaa !9
  %17 = icmp eq i32 %16, 1
  br i1 %17, label %18, label %24

18:                                               ; preds = %.lr.ph
  %19 = getelementptr inbounds i8, ptr %15, i64 8
  %20 = load ptr, ptr %19, align 8, !tbaa !12
  %21 = load i32, ptr %2, align 4, !tbaa !5
  %22 = add nsw i32 %21, -1
  store i32 %22, ptr %2, align 4, !tbaa !5
  %23 = call i32 @curl_multi_remove_handle(ptr noundef %5, ptr noundef %20) #4
  call void @curl_easy_cleanup(ptr noundef %20) #4
  br label %24

24:                                               ; preds = %18, %.lr.ph
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #4
  store i32 0, ptr %4, align 4, !tbaa !5
  %25 = call ptr @curl_multi_info_read(ptr noundef %5, ptr noundef nonnull %4) #4
  %.not27 = icmp eq ptr %25, null
  br i1 %.not27, label %._crit_edge, label %.lr.ph, !llvm.loop !13

.thread:                                          ; preds = %.preheader32, %12
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #4
  br label %.loopexit

._crit_edge:                                      ; preds = %24, %.preheader
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #4
  %26 = load i32, ptr %2, align 4
  %.not = icmp eq i32 %26, 0
  br i1 %.not, label %.loopexit, label %.preheader32

.loopexit:                                        ; preds = %._crit_edge, %.thread, %0
  %27 = call i32 @curl_multi_cleanup(ptr noundef %5) #4
  %28 = load i32, ptr @pushindex, align 4, !tbaa !5
  %29 = icmp sgt i32 %28, 0
  br i1 %29, label %.lr.ph36, label %._crit_edge37

.lr.ph36:                                         ; preds = %.loopexit, %.lr.ph36
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph36 ], [ 0, %.loopexit ]
  %30 = getelementptr inbounds [10 x %struct.Memory], ptr @files, i64 0, i64 %indvars.iv
  %31 = load ptr, ptr %30, align 16, !tbaa !15
  call void @free(ptr noundef %31) #4
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %32 = load i32, ptr @pushindex, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = icmp slt i64 %indvars.iv.next, %33
  br i1 %34, label %.lr.ph36, label %._crit_edge37, !llvm.loop !18

._crit_edge37:                                    ; preds = %.lr.ph36, %.loopexit
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #4
  ret i32 0
}

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

declare ptr @curl_multi_init() local_unnamed_addr #2

declare ptr @curl_easy_init() local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare hidden void @setup(ptr noundef) local_unnamed_addr #0

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

declare i32 @curl_multi_setopt(ptr noundef, i32 noundef, ...) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare hidden i32 @server_push_callback(ptr noundef, ptr noundef, i64 noundef, ptr noundef, ptr noundef) #0

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

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

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

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

declare void @curl_easy_cleanup(ptr noundef) local_unnamed_addr #2

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

declare i32 @curl_multi_cleanup(ptr noundef) local_unnamed_addr #2

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

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 = { 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 #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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 0}
!10 = !{!"CURLMsg", !6, i64 0, !11, i64 8, !7, i64 16}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!10, !11, i64 8}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!16, !11, i64 0}
!16 = !{!"Memory", !11, i64 0, !17, i64 8}
!17 = !{!"long", !7, i64 0}
!18 = distinct !{!18, !14}


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