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

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

; 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 [1000 x %struct.transfer], align 16
  %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 i32, align 4
  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 24000, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  store i32 0, ptr %9, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  %13 = load i32, ptr %4, align 4, !tbaa !5
  %14 = icmp sgt i32 %13, 1
  br i1 %14, label %15, label %27

15:                                               ; preds = %2
  %16 = load ptr, ptr %5, align 8, !tbaa !9
  %17 = getelementptr inbounds ptr, ptr %16, i64 1
  %18 = load ptr, ptr %17, align 8, !tbaa !9
  %19 = call i32 @atoi(ptr noundef %18) #5
  store i32 %19, ptr %10, align 4, !tbaa !5
  %20 = load i32, ptr %10, align 4, !tbaa !5
  %21 = icmp slt i32 %20, 1
  br i1 %21, label %25, label %22

22:                                               ; preds = %15
  %23 = load i32, ptr %10, align 4, !tbaa !5
  %24 = icmp sgt i32 %23, 1000
  br i1 %24, label %25, label %26

25:                                               ; preds = %22, %15
  store i32 3, ptr %10, align 4, !tbaa !5
  br label %26

26:                                               ; preds = %25, %22
  br label %28

27:                                               ; preds = %2
  store i32 3, ptr %10, align 4, !tbaa !5
  br label %28

28:                                               ; preds = %27, %26
  %29 = call ptr @curl_multi_init()
  store ptr %29, ptr %7, align 8, !tbaa !9
  store i32 0, ptr %8, align 4, !tbaa !5
  br label %30

30:                                               ; preds = %46, %28
  %31 = load i32, ptr %8, align 4, !tbaa !5
  %32 = load i32, ptr %10, align 4, !tbaa !5
  %33 = icmp slt i32 %31, %32
  br i1 %33, label %34, label %49

34:                                               ; preds = %30
  %35 = load i32, ptr %8, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [1000 x %struct.transfer], ptr %6, i64 0, i64 %36
  %38 = load i32, ptr %8, align 4, !tbaa !5
  call void @setup(ptr noundef %37, i32 noundef %38)
  %39 = load ptr, ptr %7, align 8, !tbaa !9
  %40 = load i32, ptr %8, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [1000 x %struct.transfer], ptr %6, i64 0, i64 %41
  %43 = getelementptr inbounds %struct.transfer, ptr %42, i32 0, i32 0
  %44 = load ptr, ptr %43, align 8, !tbaa !11
  %45 = call i32 @curl_multi_add_handle(ptr noundef %39, ptr noundef %44)
  br label %46

46:                                               ; preds = %34
  %47 = load i32, ptr %8, align 4, !tbaa !5
  %48 = add nsw i32 %47, 1
  store i32 %48, ptr %8, align 4, !tbaa !5
  br label %30, !llvm.loop !13

49:                                               ; preds = %30
  %50 = load ptr, ptr %7, align 8, !tbaa !9
  %51 = call i32 (ptr, i32, ...) @curl_multi_setopt(ptr noundef %50, i32 noundef 3, i64 noundef 2)
  br label %52

52:                                               ; preds = %68, %49
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  %53 = load ptr, ptr %7, align 8, !tbaa !9
  %54 = call i32 @curl_multi_perform(ptr noundef %53, ptr noundef %9)
  store i32 %54, ptr %11, align 4, !tbaa !5
  %55 = load i32, ptr %9, align 4, !tbaa !5
  %56 = icmp ne i32 %55, 0
  br i1 %56, label %57, label %60

57:                                               ; preds = %52
  %58 = load ptr, ptr %7, align 8, !tbaa !9
  %59 = call i32 @curl_multi_poll(ptr noundef %58, ptr noundef null, i32 noundef 0, i32 noundef 1000, ptr noundef null)
  store i32 %59, ptr %11, align 4, !tbaa !5
  br label %60

60:                                               ; preds = %57, %52
  %61 = load i32, ptr %11, align 4, !tbaa !5
  %62 = icmp ne i32 %61, 0
  br i1 %62, label %63, label %64

63:                                               ; preds = %60
  store i32 5, ptr %12, align 4
  br label %65

64:                                               ; preds = %60
  store i32 0, ptr %12, align 4
  br label %65

65:                                               ; preds = %64, %63
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  %66 = load i32, ptr %12, align 4
  switch i32 %66, label %96 [
    i32 0, label %67
    i32 5, label %71
  ]

67:                                               ; preds = %65
  br label %68

68:                                               ; preds = %67
  %69 = load i32, ptr %9, align 4, !tbaa !5
  %70 = icmp ne i32 %69, 0
  br i1 %70, label %52, label %71, !llvm.loop !15

71:                                               ; preds = %68, %65
  store i32 0, ptr %8, align 4, !tbaa !5
  br label %72

72:                                               ; preds = %89, %71
  %73 = load i32, ptr %8, align 4, !tbaa !5
  %74 = load i32, ptr %10, align 4, !tbaa !5
  %75 = icmp slt i32 %73, %74
  br i1 %75, label %76, label %92

76:                                               ; preds = %72
  %77 = load ptr, ptr %7, align 8, !tbaa !9
  %78 = load i32, ptr %8, align 4, !tbaa !5
  %79 = sext i32 %78 to i64
  %80 = getelementptr inbounds [1000 x %struct.transfer], ptr %6, i64 0, i64 %79
  %81 = getelementptr inbounds %struct.transfer, ptr %80, i32 0, i32 0
  %82 = load ptr, ptr %81, align 8, !tbaa !11
  %83 = call i32 @curl_multi_remove_handle(ptr noundef %77, ptr noundef %82)
  %84 = load i32, ptr %8, align 4, !tbaa !5
  %85 = sext i32 %84 to i64
  %86 = getelementptr inbounds [1000 x %struct.transfer], ptr %6, i64 0, i64 %85
  %87 = getelementptr inbounds %struct.transfer, ptr %86, i32 0, i32 0
  %88 = load ptr, ptr %87, align 8, !tbaa !11
  call void @curl_easy_cleanup(ptr noundef %88)
  br label %89

89:                                               ; preds = %76
  %90 = load i32, ptr %8, align 4, !tbaa !5
  %91 = add nsw i32 %90, 1
  store i32 %91, ptr %8, align 4, !tbaa !5
  br label %72, !llvm.loop !16

92:                                               ; preds = %72
  %93 = load ptr, ptr %7, align 8, !tbaa !9
  %94 = call i32 @curl_multi_cleanup(ptr noundef %93)
  store i32 0, ptr %3, align 4
  store i32 1, ptr %12, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 24000, ptr %6) #4
  %95 = load i32, ptr %3, align 4
  ret i32 %95

96:                                               ; preds = %65
  unreachable
}

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

; Function Attrs: inlinehint nounwind willreturn memory(read) uwtable
declare i32 @atoi(ptr noundef nonnull) #2

declare ptr @curl_multi_init() #3

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

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

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

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

declare i32 @curl_multi_poll(ptr noundef, ptr noundef, i32 noundef, i32 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 i32 @curl_multi_remove_handle(ptr noundef, ptr noundef) #3

declare void @curl_easy_cleanup(ptr noundef) #3

declare i32 @curl_multi_cleanup(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 = { inlinehint nounwind willreturn memory(read) 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 = { "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 }
attributes #5 = { nounwind willreturn memory(read) }

!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, !10, i64 0}
!12 = !{!"transfer", !10, i64 0, !6, i64 8, !10, i64 16}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = distinct !{!16, !14}


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

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main(i32 noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %3 = alloca [1000 x %struct.transfer], align 16
  %4 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 24000, ptr nonnull %3) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #4
  store i32 0, ptr %4, align 4, !tbaa !5
  %5 = icmp sgt i32 %0, 1
  br i1 %5, label %6, label %.lr.ph.preheader

6:                                                ; preds = %2
  %7 = getelementptr inbounds i8, ptr %1, i64 8
  %8 = load ptr, ptr %7, align 8, !tbaa !9
  %9 = tail call i32 @atoi(ptr nocapture noundef %8) #5
  %10 = add i32 %9, -1001
  %or.cond = icmp ult i32 %10, -1000
  %spec.select = select i1 %or.cond, i32 3, i32 %9
  %11 = zext nneg i32 %spec.select to i64
  br label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %6, %2
  %.025 = phi i64 [ 3, %2 ], [ %11, %6 ]
  %12 = tail call ptr @curl_multi_init() #4
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %.lr.ph ]
  %13 = getelementptr inbounds [1000 x %struct.transfer], ptr %3, i64 0, i64 %indvars.iv
  %14 = trunc nuw nsw i64 %indvars.iv to i32
  call void @setup(ptr noundef nonnull %13, i32 noundef %14)
  %15 = load ptr, ptr %13, align 8, !tbaa !11
  %16 = call i32 @curl_multi_add_handle(ptr noundef %12, ptr noundef %15) #4
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %.025
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !13

._crit_edge:                                      ; preds = %.lr.ph
  %17 = call i32 (ptr, i32, ...) @curl_multi_setopt(ptr noundef %12, i32 noundef 3, i64 noundef 2) #4
  br label %18

18:                                               ; preds = %21, %._crit_edge
  %19 = call i32 @curl_multi_perform(ptr noundef %12, ptr noundef nonnull %4) #4
  %20 = load i32, ptr %4, align 4
  %.not = icmp eq i32 %20, 0
  br i1 %.not, label %.lr.ph32.preheader, label %21

21:                                               ; preds = %18
  %22 = call i32 @curl_multi_poll(ptr noundef %12, ptr noundef null, i32 noundef 0, i32 noundef 1000, ptr noundef null) #4
  %.pre = load i32, ptr %4, align 4
  %.not27 = icmp ne i32 %22, 0
  %.not28 = icmp eq i32 %.pre, 0
  %or.cond29 = select i1 %.not27, i1 true, i1 %.not28
  br i1 %or.cond29, label %.lr.ph32.preheader, label %18, !llvm.loop !15

.lr.ph32.preheader:                               ; preds = %18, %21
  br label %.lr.ph32

.lr.ph32:                                         ; preds = %.lr.ph32.preheader, %.lr.ph32
  %indvars.iv35 = phi i64 [ %indvars.iv.next36, %.lr.ph32 ], [ 0, %.lr.ph32.preheader ]
  %23 = getelementptr inbounds [1000 x %struct.transfer], ptr %3, i64 0, i64 %indvars.iv35
  %24 = load ptr, ptr %23, align 8, !tbaa !11
  %25 = call i32 @curl_multi_remove_handle(ptr noundef %12, ptr noundef %24) #4
  %26 = load ptr, ptr %23, align 8, !tbaa !11
  call void @curl_easy_cleanup(ptr noundef %26) #4
  %indvars.iv.next36 = add nuw nsw i64 %indvars.iv35, 1
  %exitcond39.not = icmp eq i64 %indvars.iv.next36, %.025
  br i1 %exitcond39.not, label %._crit_edge33, label %.lr.ph32, !llvm.loop !16

._crit_edge33:                                    ; preds = %.lr.ph32
  %27 = call i32 @curl_multi_cleanup(ptr noundef %12) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #4
  call void @llvm.lifetime.end.p0(i64 24000, ptr nonnull %3) #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

; Function Attrs: inlinehint mustprogress nofree nounwind willreturn memory(read) uwtable
declare i32 @atoi(ptr nocapture noundef nonnull) local_unnamed_addr #2

declare ptr @curl_multi_init() local_unnamed_addr #3

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

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

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

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

declare i32 @curl_multi_poll(ptr noundef, ptr noundef, i32 noundef, i32 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

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

declare void @curl_easy_cleanup(ptr noundef) local_unnamed_addr #3

declare i32 @curl_multi_cleanup(ptr 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 = { inlinehint mustprogress nofree nounwind willreturn memory(read) 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 = { "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 }
attributes #5 = { nounwind willreturn memory(read) }

!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, !10, i64 0}
!12 = !{!"transfer", !10, i64 0, !6, i64 8, !10, i64 16}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = distinct !{!16, !14}


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