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

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

@.str = external hidden unnamed_addr constant [11 x i8], align 1

; 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.input], align 16
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = 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 32000, 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 8, ptr %10) #4
  store ptr @.str, ptr %10, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  %14 = load i32, ptr %4, align 4, !tbaa !5
  %15 = icmp sgt i32 %14, 1
  br i1 %15, label %16, label %35

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

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

26:                                               ; preds = %23, %16
  store i32 3, ptr %11, align 4, !tbaa !5
  br label %27

27:                                               ; preds = %26, %23
  %28 = load i32, ptr %4, align 4, !tbaa !5
  %29 = icmp sgt i32 %28, 2
  br i1 %29, label %30, label %34

30:                                               ; preds = %27
  %31 = load ptr, ptr %5, align 8, !tbaa !9
  %32 = getelementptr inbounds ptr, ptr %31, i64 2
  %33 = load ptr, ptr %32, align 8, !tbaa !9
  store ptr %33, ptr %10, align 8, !tbaa !9
  br label %34

34:                                               ; preds = %30, %27
  br label %36

35:                                               ; preds = %2
  store i32 3, ptr %11, align 4, !tbaa !5
  br label %36

36:                                               ; preds = %35, %34
  %37 = call ptr @curl_multi_init()
  store ptr %37, ptr %7, align 8, !tbaa !9
  store i32 0, ptr %8, align 4, !tbaa !5
  br label %38

38:                                               ; preds = %55, %36
  %39 = load i32, ptr %8, align 4, !tbaa !5
  %40 = load i32, ptr %11, align 4, !tbaa !5
  %41 = icmp slt i32 %39, %40
  br i1 %41, label %42, label %58

42:                                               ; preds = %38
  %43 = load i32, ptr %8, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [1000 x %struct.input], ptr %6, i64 0, i64 %44
  %46 = load i32, ptr %8, align 4, !tbaa !5
  %47 = load ptr, ptr %10, align 8, !tbaa !9
  call void @setup(ptr noundef %45, i32 noundef %46, ptr noundef %47)
  %48 = load ptr, ptr %7, align 8, !tbaa !9
  %49 = load i32, ptr %8, align 4, !tbaa !5
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [1000 x %struct.input], ptr %6, i64 0, i64 %50
  %52 = getelementptr inbounds %struct.input, ptr %51, i32 0, i32 2
  %53 = load ptr, ptr %52, align 16, !tbaa !11
  %54 = call i32 @curl_multi_add_handle(ptr noundef %48, ptr noundef %53)
  br label %55

55:                                               ; preds = %42
  %56 = load i32, ptr %8, align 4, !tbaa !5
  %57 = add nsw i32 %56, 1
  store i32 %57, ptr %8, align 4, !tbaa !5
  br label %38, !llvm.loop !14

58:                                               ; preds = %38
  %59 = load ptr, ptr %7, align 8, !tbaa !9
  %60 = call i32 (ptr, i32, ...) @curl_multi_setopt(ptr noundef %59, i32 noundef 3, i64 noundef 2)
  %61 = load ptr, ptr %7, align 8, !tbaa !9
  %62 = call i32 (ptr, i32, ...) @curl_multi_setopt(ptr noundef %61, i32 noundef 7, i64 noundef 1)
  br label %63

63:                                               ; preds = %79, %58
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  %64 = load ptr, ptr %7, align 8, !tbaa !9
  %65 = call i32 @curl_multi_perform(ptr noundef %64, ptr noundef %9)
  store i32 %65, ptr %12, align 4, !tbaa !5
  %66 = load i32, ptr %9, align 4, !tbaa !5
  %67 = icmp ne i32 %66, 0
  br i1 %67, label %68, label %71

68:                                               ; preds = %63
  %69 = load ptr, ptr %7, align 8, !tbaa !9
  %70 = call i32 @curl_multi_poll(ptr noundef %69, ptr noundef null, i32 noundef 0, i32 noundef 1000, ptr noundef null)
  store i32 %70, ptr %12, align 4, !tbaa !5
  br label %71

71:                                               ; preds = %68, %63
  %72 = load i32, ptr %12, align 4, !tbaa !5
  %73 = icmp ne i32 %72, 0
  br i1 %73, label %74, label %75

74:                                               ; preds = %71
  store i32 5, ptr %13, align 4
  br label %76

75:                                               ; preds = %71
  store i32 0, ptr %13, align 4
  br label %76

76:                                               ; preds = %75, %74
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  %77 = load i32, ptr %13, align 4
  switch i32 %77, label %107 [
    i32 0, label %78
    i32 5, label %82
  ]

78:                                               ; preds = %76
  br label %79

79:                                               ; preds = %78
  %80 = load i32, ptr %9, align 4, !tbaa !5
  %81 = icmp ne i32 %80, 0
  br i1 %81, label %63, label %82, !llvm.loop !16

82:                                               ; preds = %79, %76
  %83 = load ptr, ptr %7, align 8, !tbaa !9
  %84 = call i32 @curl_multi_cleanup(ptr noundef %83)
  store i32 0, ptr %8, align 4, !tbaa !5
  br label %85

85:                                               ; preds = %102, %82
  %86 = load i32, ptr %8, align 4, !tbaa !5
  %87 = load i32, ptr %11, align 4, !tbaa !5
  %88 = icmp slt i32 %86, %87
  br i1 %88, label %89, label %105

89:                                               ; preds = %85
  %90 = load ptr, ptr %7, align 8, !tbaa !9
  %91 = load i32, ptr %8, align 4, !tbaa !5
  %92 = sext i32 %91 to i64
  %93 = getelementptr inbounds [1000 x %struct.input], ptr %6, i64 0, i64 %92
  %94 = getelementptr inbounds %struct.input, ptr %93, i32 0, i32 2
  %95 = load ptr, ptr %94, align 16, !tbaa !11
  %96 = call i32 @curl_multi_remove_handle(ptr noundef %90, ptr noundef %95)
  %97 = load i32, ptr %8, align 4, !tbaa !5
  %98 = sext i32 %97 to i64
  %99 = getelementptr inbounds [1000 x %struct.input], ptr %6, i64 0, i64 %98
  %100 = getelementptr inbounds %struct.input, ptr %99, i32 0, i32 2
  %101 = load ptr, ptr %100, align 16, !tbaa !11
  call void @curl_easy_cleanup(ptr noundef %101)
  br label %102

102:                                              ; preds = %89
  %103 = load i32, ptr %8, align 4, !tbaa !5
  %104 = add nsw i32 %103, 1
  store i32 %104, ptr %8, align 4, !tbaa !5
  br label %85, !llvm.loop !17

105:                                              ; preds = %85
  store i32 0, ptr %3, align 4
  store i32 1, ptr %13, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, 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 32000, ptr %6) #4
  %106 = load i32, ptr %3, align 4
  ret i32 %106

107:                                              ; preds = %76
  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, ptr 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_cleanup(ptr noundef) #3

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

declare void @curl_easy_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 16}
!12 = !{!"input", !10, i64 0, !13, i64 8, !10, i64 16, !6, i64 24}
!13 = !{!"long", !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}
!17 = distinct !{!17, !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.input = type { ptr, i64, ptr, i32 }

@.str = external hidden unnamed_addr constant [11 x i8], align 1

; 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.input], align 16
  %4 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 32000, 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 %7, label %.thread

.thread:                                          ; preds = %2
  %6 = tail call ptr @curl_multi_init() #4
  br label %.lr.ph.preheader

7:                                                ; preds = %2
  %8 = getelementptr inbounds i8, ptr %1, i64 8
  %9 = load ptr, ptr %8, align 8, !tbaa !9
  %10 = tail call i32 @atoi(ptr nocapture noundef %9) #5
  %11 = icmp eq i32 %10, 0
  %12 = icmp sgt i32 %10, 1000
  %or.cond = or i1 %11, %12
  %spec.store.select = select i1 %or.cond, i32 3, i32 %10
  %.not = icmp eq i32 %0, 2
  br i1 %.not, label %16, label %13

13:                                               ; preds = %7
  %14 = getelementptr inbounds i8, ptr %1, i64 16
  %15 = load ptr, ptr %14, align 8, !tbaa !9
  br label %16

16:                                               ; preds = %7, %13
  %.030 = phi ptr [ %15, %13 ], [ @.str, %7 ]
  %17 = tail call ptr @curl_multi_init() #4
  %18 = icmp sgt i32 %spec.store.select, 0
  br i1 %18, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %.thread, %16
  %19 = phi ptr [ %6, %.thread ], [ %17, %16 ]
  %.02951 = phi i32 [ 3, %.thread ], [ %spec.store.select, %16 ]
  %.03050 = phi ptr [ @.str, %.thread ], [ %.030, %16 ]
  %wide.trip.count = zext nneg i32 %.02951 to i64
  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 ]
  %20 = getelementptr inbounds [1000 x %struct.input], ptr %3, i64 0, i64 %indvars.iv
  %21 = trunc nuw nsw i64 %indvars.iv to i32
  call void @setup(ptr noundef nonnull %20, i32 noundef %21, ptr noundef %.03050)
  %22 = getelementptr inbounds i8, ptr %20, i64 16
  %23 = load ptr, ptr %22, align 16, !tbaa !11
  %24 = call i32 @curl_multi_add_handle(ptr noundef %19, ptr noundef %23) #4
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !14

._crit_edge:                                      ; preds = %.lr.ph, %16
  %25 = phi i1 [ false, %16 ], [ true, %.lr.ph ]
  %26 = phi ptr [ %17, %16 ], [ %19, %.lr.ph ]
  %.02952 = phi i32 [ %10, %16 ], [ %.02951, %.lr.ph ]
  %27 = call i32 (ptr, i32, ...) @curl_multi_setopt(ptr noundef %26, i32 noundef 3, i64 noundef 2) #4
  %28 = call i32 (ptr, i32, ...) @curl_multi_setopt(ptr noundef %26, i32 noundef 7, i64 noundef 1) #4
  br label %29

29:                                               ; preds = %32, %._crit_edge
  %30 = call i32 @curl_multi_perform(ptr noundef %26, ptr noundef nonnull %4) #4
  %31 = load i32, ptr %4, align 4
  %.not33 = icmp eq i32 %31, 0
  br i1 %.not33, label %.thread53, label %32

32:                                               ; preds = %29
  %33 = call i32 @curl_multi_poll(ptr noundef %26, ptr noundef null, i32 noundef 0, i32 noundef 1000, ptr noundef null) #4
  %.pre = load i32, ptr %4, align 4
  %.not34 = icmp ne i32 %33, 0
  %.not35 = icmp eq i32 %.pre, 0
  %or.cond36 = select i1 %.not34, i1 true, i1 %.not35
  br i1 %or.cond36, label %.thread53, label %29, !llvm.loop !16

.thread53:                                        ; preds = %29, %32
  %34 = call i32 @curl_multi_cleanup(ptr noundef %26) #4
  br i1 %25, label %.lr.ph40.preheader, label %._crit_edge41

.lr.ph40.preheader:                               ; preds = %.thread53
  %wide.trip.count46 = zext nneg i32 %.02952 to i64
  br label %.lr.ph40

.lr.ph40:                                         ; preds = %.lr.ph40.preheader, %.lr.ph40
  %indvars.iv43 = phi i64 [ 0, %.lr.ph40.preheader ], [ %indvars.iv.next44, %.lr.ph40 ]
  %35 = getelementptr inbounds [1000 x %struct.input], ptr %3, i64 0, i64 %indvars.iv43, i32 2
  %36 = load ptr, ptr %35, align 16, !tbaa !11
  %37 = call i32 @curl_multi_remove_handle(ptr noundef %26, ptr noundef %36) #4
  %38 = load ptr, ptr %35, align 16, !tbaa !11
  call void @curl_easy_cleanup(ptr noundef %38) #4
  %indvars.iv.next44 = add nuw nsw i64 %indvars.iv43, 1
  %exitcond47.not = icmp eq i64 %indvars.iv.next44, %wide.trip.count46
  br i1 %exitcond47.not, label %._crit_edge41, label %.lr.ph40, !llvm.loop !17

._crit_edge41:                                    ; preds = %.lr.ph40, %.thread53
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #4
  call void @llvm.lifetime.end.p0(i64 32000, 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, ptr 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_cleanup(ptr noundef) local_unnamed_addr #3

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

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


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