; LLVM IR from holzschu/ios_system :: curl/curl/docs/examples (multi-post)

; 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"

@main.buf = external hidden constant [8 x i8], align 1
@.str = external hidden unnamed_addr constant [9 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [35 x i8], align 1

; 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 ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store i32 0, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  store ptr null, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  store ptr null, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  store ptr null, ptr %7, align 8, !tbaa !9
  %10 = call ptr @curl_easy_init()
  store ptr %10, ptr %2, align 8, !tbaa !9
  %11 = call ptr @curl_multi_init()
  store ptr %11, ptr %3, align 8, !tbaa !9
  %12 = load ptr, ptr %2, align 8, !tbaa !9
  %13 = icmp ne ptr %12, null
  br i1 %13, label %14, label %78

14:                                               ; preds = %0
  %15 = load ptr, ptr %3, align 8, !tbaa !9
  %16 = icmp ne ptr %15, null
  br i1 %16, label %17, label %78

17:                                               ; preds = %14
  %18 = load ptr, ptr %2, align 8, !tbaa !9
  %19 = call ptr @curl_mime_init(ptr noundef %18)
  store ptr %19, ptr %5, align 8, !tbaa !9
  %20 = load ptr, ptr %5, align 8, !tbaa !9
  %21 = call ptr @curl_mime_addpart(ptr noundef %20)
  store ptr %21, ptr %6, align 8, !tbaa !9
  %22 = load ptr, ptr %6, align 8, !tbaa !9
  %23 = call i32 @curl_mime_name(ptr noundef %22, ptr noundef @.str)
  %24 = load ptr, ptr %6, align 8, !tbaa !9
  %25 = call i32 @curl_mime_filedata(ptr noundef %24, ptr noundef @.str.1)
  %26 = load ptr, ptr %5, align 8, !tbaa !9
  %27 = call ptr @curl_mime_addpart(ptr noundef %26)
  store ptr %27, ptr %6, align 8, !tbaa !9
  %28 = load ptr, ptr %6, align 8, !tbaa !9
  %29 = call i32 @curl_mime_name(ptr noundef %28, ptr noundef @.str.2)
  %30 = load ptr, ptr %6, align 8, !tbaa !9
  %31 = call i32 @curl_mime_data(ptr noundef %30, ptr noundef @.str.1, i64 noundef -1)
  %32 = load ptr, ptr %5, align 8, !tbaa !9
  %33 = call ptr @curl_mime_addpart(ptr noundef %32)
  store ptr %33, ptr %6, align 8, !tbaa !9
  %34 = load ptr, ptr %6, align 8, !tbaa !9
  %35 = call i32 @curl_mime_name(ptr noundef %34, ptr noundef @.str.3)
  %36 = load ptr, ptr %6, align 8, !tbaa !9
  %37 = call i32 @curl_mime_data(ptr noundef %36, ptr noundef @.str.4, i64 noundef -1)
  %38 = load ptr, ptr %7, align 8, !tbaa !9
  %39 = call ptr @curl_slist_append(ptr noundef %38, ptr noundef @main.buf)
  store ptr %39, ptr %7, align 8, !tbaa !9
  %40 = load ptr, ptr %2, align 8, !tbaa !9
  %41 = call i32 (ptr, i32, ...) @curl_easy_setopt(ptr noundef %40, i32 noundef 10002, ptr noundef @.str.5)
  %42 = load ptr, ptr %2, align 8, !tbaa !9
  %43 = call i32 (ptr, i32, ...) @curl_easy_setopt(ptr noundef %42, i32 noundef 41, i64 noundef 1)
  %44 = load ptr, ptr %2, align 8, !tbaa !9
  %45 = load ptr, ptr %7, align 8, !tbaa !9
  %46 = call i32 (ptr, i32, ...) @curl_easy_setopt(ptr noundef %44, i32 noundef 10023, ptr noundef %45)
  %47 = load ptr, ptr %2, align 8, !tbaa !9
  %48 = load ptr, ptr %5, align 8, !tbaa !9
  %49 = call i32 (ptr, i32, ...) @curl_easy_setopt(ptr noundef %47, i32 noundef 10269, ptr noundef %48)
  %50 = load ptr, ptr %3, align 8, !tbaa !9
  %51 = load ptr, ptr %2, align 8, !tbaa !9
  %52 = call i32 @curl_multi_add_handle(ptr noundef %50, ptr noundef %51)
  br label %53

53:                                               ; preds = %69, %17
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %54 = load ptr, ptr %3, align 8, !tbaa !9
  %55 = call i32 @curl_multi_perform(ptr noundef %54, ptr noundef %4)
  store i32 %55, ptr %8, align 4, !tbaa !5
  %56 = load i32, ptr %4, align 4, !tbaa !5
  %57 = icmp ne i32 %56, 0
  br i1 %57, label %58, label %61

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

61:                                               ; preds = %58, %53
  %62 = load i32, ptr %8, align 4, !tbaa !5
  %63 = icmp ne i32 %62, 0
  br i1 %63, label %64, label %65

64:                                               ; preds = %61
  store i32 2, ptr %9, align 4
  br label %66

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

66:                                               ; preds = %65, %64
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  %67 = load i32, ptr %9, align 4
  switch i32 %67, label %80 [
    i32 0, label %68
    i32 2, label %72
  ]

68:                                               ; preds = %66
  br label %69

69:                                               ; preds = %68
  %70 = load i32, ptr %4, align 4, !tbaa !5
  %71 = icmp ne i32 %70, 0
  br i1 %71, label %53, label %72, !llvm.loop !11

72:                                               ; preds = %69, %66
  %73 = load ptr, ptr %3, align 8, !tbaa !9
  %74 = call i32 @curl_multi_cleanup(ptr noundef %73)
  %75 = load ptr, ptr %2, align 8, !tbaa !9
  call void @curl_easy_cleanup(ptr noundef %75)
  %76 = load ptr, ptr %5, align 8, !tbaa !9
  call void @curl_mime_free(ptr noundef %76)
  %77 = load ptr, ptr %7, align 8, !tbaa !9
  call void @curl_slist_free_all(ptr noundef %77)
  br label %78

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

80:                                               ; 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_easy_init() #2

declare ptr @curl_multi_init() #2

declare ptr @curl_mime_init(ptr noundef) #2

declare ptr @curl_mime_addpart(ptr noundef) #2

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

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

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

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

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

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

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

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

declare void @curl_easy_cleanup(ptr noundef) #2

declare void @curl_mime_free(ptr noundef) #2

declare void @curl_slist_free_all(ptr noundef) #2

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 }

!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 = distinct !{!11, !12}
!12 = !{!"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"

@main.buf = external hidden constant [8 x i8], align 1
@.str = external hidden unnamed_addr constant [9 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [35 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #3
  store i32 0, ptr %1, align 4, !tbaa !5
  %2 = tail call ptr @curl_easy_init() #3
  %3 = tail call ptr @curl_multi_init() #3
  %4 = icmp ne ptr %2, null
  %5 = icmp ne ptr %3, null
  %or.cond = select i1 %4, i1 %5, i1 false
  br i1 %or.cond, label %6, label %29

6:                                                ; preds = %0
  %7 = tail call ptr @curl_mime_init(ptr noundef nonnull %2) #3
  %8 = tail call ptr @curl_mime_addpart(ptr noundef %7) #3
  %9 = tail call i32 @curl_mime_name(ptr noundef %8, ptr noundef nonnull @.str) #3
  %10 = tail call i32 @curl_mime_filedata(ptr noundef %8, ptr noundef nonnull @.str.1) #3
  %11 = tail call ptr @curl_mime_addpart(ptr noundef %7) #3
  %12 = tail call i32 @curl_mime_name(ptr noundef %11, ptr noundef nonnull @.str.2) #3
  %13 = tail call i32 @curl_mime_data(ptr noundef %11, ptr noundef nonnull @.str.1, i64 noundef -1) #3
  %14 = tail call ptr @curl_mime_addpart(ptr noundef %7) #3
  %15 = tail call i32 @curl_mime_name(ptr noundef %14, ptr noundef nonnull @.str.3) #3
  %16 = tail call i32 @curl_mime_data(ptr noundef %14, ptr noundef nonnull @.str.4, i64 noundef -1) #3
  %17 = tail call ptr @curl_slist_append(ptr noundef null, ptr noundef nonnull @main.buf) #3
  %18 = tail call i32 (ptr, i32, ...) @curl_easy_setopt(ptr noundef nonnull %2, i32 noundef 10002, ptr noundef nonnull @.str.5) #3
  %19 = tail call i32 (ptr, i32, ...) @curl_easy_setopt(ptr noundef nonnull %2, i32 noundef 41, i64 noundef 1) #3
  %20 = tail call i32 (ptr, i32, ...) @curl_easy_setopt(ptr noundef nonnull %2, i32 noundef 10023, ptr noundef %17) #3
  %21 = tail call i32 (ptr, i32, ...) @curl_easy_setopt(ptr noundef nonnull %2, i32 noundef 10269, ptr noundef %7) #3
  %22 = tail call i32 @curl_multi_add_handle(ptr noundef nonnull %3, ptr noundef nonnull %2) #3
  br label %23

23:                                               ; preds = %26, %6
  %24 = call i32 @curl_multi_perform(ptr noundef nonnull %3, ptr noundef nonnull %1) #3
  %25 = load i32, ptr %1, align 4
  %.not = icmp eq i32 %25, 0
  br i1 %.not, label %.thread, label %26

26:                                               ; preds = %23
  %27 = call i32 @curl_multi_poll(ptr noundef nonnull %3, ptr noundef null, i32 noundef 0, i32 noundef 1000, ptr noundef null) #3
  %.pre = load i32, ptr %1, align 4
  %.not33 = icmp ne i32 %27, 0
  %.not34 = icmp eq i32 %.pre, 0
  %or.cond35 = select i1 %.not33, i1 true, i1 %.not34
  br i1 %or.cond35, label %.thread, label %23, !llvm.loop !9

.thread:                                          ; preds = %23, %26
  %28 = call i32 @curl_multi_cleanup(ptr noundef nonnull %3) #3
  call void @curl_easy_cleanup(ptr noundef nonnull %2) #3
  call void @curl_mime_free(ptr noundef %7) #3
  call void @curl_slist_free_all(ptr noundef %17) #3
  br label %29

29:                                               ; preds = %.thread, %0
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #3
  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_easy_init() local_unnamed_addr #2

declare ptr @curl_multi_init() local_unnamed_addr #2

declare ptr @curl_mime_init(ptr noundef) local_unnamed_addr #2

declare ptr @curl_mime_addpart(ptr noundef) local_unnamed_addr #2

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

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

declare i32 @curl_mime_data(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #2

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

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

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

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

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

declare void @curl_easy_cleanup(ptr noundef) local_unnamed_addr #2

declare void @curl_mime_free(ptr noundef) local_unnamed_addr #2

declare void @curl_slist_free_all(ptr noundef) local_unnamed_addr #2

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 = { 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass