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

; 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 [16 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 i32 (ptr, ptr, ...) @curl_formadd(ptr noundef %5, ptr noundef %6, i32 noundef 1, ptr noundef @.str, i32 noundef 10, ptr noundef @.str.1, i32 noundef 17)
  %11 = call i32 (ptr, ptr, ...) @curl_formadd(ptr noundef %5, ptr noundef %6, i32 noundef 1, ptr noundef @.str.2, i32 noundef 4, ptr noundef @.str.1, i32 noundef 17)
  %12 = call i32 (ptr, ptr, ...) @curl_formadd(ptr noundef %5, ptr noundef %6, i32 noundef 1, ptr noundef @.str.3, i32 noundef 4, ptr noundef @.str.4, i32 noundef 17)
  %13 = call ptr @curl_easy_init()
  store ptr %13, ptr %2, align 8, !tbaa !9
  %14 = call ptr @curl_multi_init()
  store ptr %14, ptr %3, align 8, !tbaa !9
  %15 = load ptr, ptr %7, align 8, !tbaa !9
  %16 = call ptr @curl_slist_append(ptr noundef %15, ptr noundef @main.buf)
  store ptr %16, ptr %7, align 8, !tbaa !9
  %17 = load ptr, ptr %2, align 8, !tbaa !9
  %18 = icmp ne ptr %17, null
  br i1 %18, label %19, label %61

19:                                               ; preds = %0
  %20 = load ptr, ptr %3, align 8, !tbaa !9
  %21 = icmp ne ptr %20, null
  br i1 %21, label %22, label %61

22:                                               ; preds = %19
  %23 = load ptr, ptr %2, align 8, !tbaa !9
  %24 = call i32 (ptr, i32, ...) @curl_easy_setopt(ptr noundef %23, i32 noundef 10002, ptr noundef @.str.5)
  %25 = load ptr, ptr %2, align 8, !tbaa !9
  %26 = call i32 (ptr, i32, ...) @curl_easy_setopt(ptr noundef %25, i32 noundef 41, i64 noundef 1)
  %27 = load ptr, ptr %2, align 8, !tbaa !9
  %28 = load ptr, ptr %7, align 8, !tbaa !9
  %29 = call i32 (ptr, i32, ...) @curl_easy_setopt(ptr noundef %27, i32 noundef 10023, ptr noundef %28)
  %30 = load ptr, ptr %2, align 8, !tbaa !9
  %31 = load ptr, ptr %5, align 8, !tbaa !9
  %32 = call i32 (ptr, i32, ...) @curl_easy_setopt(ptr noundef %30, i32 noundef 10024, ptr noundef %31)
  %33 = load ptr, ptr %3, align 8, !tbaa !9
  %34 = load ptr, ptr %2, align 8, !tbaa !9
  %35 = call i32 @curl_multi_add_handle(ptr noundef %33, ptr noundef %34)
  br label %36

36:                                               ; preds = %52, %22
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %37 = load ptr, ptr %3, align 8, !tbaa !9
  %38 = call i32 @curl_multi_perform(ptr noundef %37, ptr noundef %4)
  store i32 %38, ptr %8, align 4, !tbaa !5
  %39 = load i32, ptr %4, align 4, !tbaa !5
  %40 = icmp ne i32 %39, 0
  br i1 %40, label %41, label %44

41:                                               ; preds = %36
  %42 = load ptr, ptr %3, align 8, !tbaa !9
  %43 = call i32 @curl_multi_poll(ptr noundef %42, ptr noundef null, i32 noundef 0, i32 noundef 1000, ptr noundef null)
  store i32 %43, ptr %8, align 4, !tbaa !5
  br label %44

44:                                               ; preds = %41, %36
  %45 = load i32, ptr %8, align 4, !tbaa !5
  %46 = icmp ne i32 %45, 0
  br i1 %46, label %47, label %48

47:                                               ; preds = %44
  store i32 2, ptr %9, align 4
  br label %49

48:                                               ; preds = %44
  store i32 0, ptr %9, align 4
  br label %49

49:                                               ; preds = %48, %47
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  %50 = load i32, ptr %9, align 4
  switch i32 %50, label %63 [
    i32 0, label %51
    i32 2, label %55
  ]

51:                                               ; preds = %49
  br label %52

52:                                               ; preds = %51
  %53 = load i32, ptr %4, align 4, !tbaa !5
  %54 = icmp ne i32 %53, 0
  br i1 %54, label %36, label %55, !llvm.loop !11

55:                                               ; preds = %52, %49
  %56 = load ptr, ptr %3, align 8, !tbaa !9
  %57 = call i32 @curl_multi_cleanup(ptr noundef %56)
  %58 = load ptr, ptr %2, align 8, !tbaa !9
  call void @curl_easy_cleanup(ptr noundef %58)
  %59 = load ptr, ptr %5, align 8, !tbaa !9
  call void @curl_formfree(ptr noundef %59)
  %60 = load ptr, ptr %7, align 8, !tbaa !9
  call void @curl_slist_free_all(ptr noundef %60)
  br label %61

61:                                               ; preds = %55, %19, %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
  %62 = load i32, ptr %1, align 4
  ret i32 %62

63:                                               ; preds = %49
  unreachable
}

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

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

declare ptr @curl_easy_init() #2

declare ptr @curl_multi_init() #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_formfree(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 [16 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
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #3
  store i32 0, ptr %1, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #3
  store ptr null, ptr %2, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #3
  store ptr null, ptr %3, align 8, !tbaa !9
  %4 = call i32 (ptr, ptr, ...) @curl_formadd(ptr noundef nonnull %2, ptr noundef nonnull %3, i32 noundef 1, ptr noundef nonnull @.str, i32 noundef 10, ptr noundef nonnull @.str.1, i32 noundef 17) #3
  %5 = call i32 (ptr, ptr, ...) @curl_formadd(ptr noundef nonnull %2, ptr noundef nonnull %3, i32 noundef 1, ptr noundef nonnull @.str.2, i32 noundef 4, ptr noundef nonnull @.str.1, i32 noundef 17) #3
  %6 = call i32 (ptr, ptr, ...) @curl_formadd(ptr noundef nonnull %2, ptr noundef nonnull %3, i32 noundef 1, ptr noundef nonnull @.str.3, i32 noundef 4, ptr noundef nonnull @.str.4, i32 noundef 17) #3
  %7 = call ptr @curl_easy_init() #3
  %8 = call ptr @curl_multi_init() #3
  %9 = call ptr @curl_slist_append(ptr noundef null, ptr noundef nonnull @main.buf) #3
  %10 = icmp ne ptr %7, null
  %11 = icmp ne ptr %8, null
  %or.cond = select i1 %10, i1 %11, i1 false
  br i1 %or.cond, label %12, label %26

12:                                               ; preds = %0
  %13 = call i32 (ptr, i32, ...) @curl_easy_setopt(ptr noundef nonnull %7, i32 noundef 10002, ptr noundef nonnull @.str.5) #3
  %14 = call i32 (ptr, i32, ...) @curl_easy_setopt(ptr noundef nonnull %7, i32 noundef 41, i64 noundef 1) #3
  %15 = call i32 (ptr, i32, ...) @curl_easy_setopt(ptr noundef nonnull %7, i32 noundef 10023, ptr noundef %9) #3
  %16 = load ptr, ptr %2, align 8, !tbaa !9
  %17 = call i32 (ptr, i32, ...) @curl_easy_setopt(ptr noundef nonnull %7, i32 noundef 10024, ptr noundef %16) #3
  %18 = call i32 @curl_multi_add_handle(ptr noundef nonnull %8, ptr noundef nonnull %7) #3
  br label %19

19:                                               ; preds = %22, %12
  %20 = call i32 @curl_multi_perform(ptr noundef nonnull %8, ptr noundef nonnull %1) #3
  %21 = load i32, ptr %1, align 4
  %.not = icmp eq i32 %21, 0
  br i1 %.not, label %.thread, label %22

22:                                               ; preds = %19
  %23 = call i32 @curl_multi_poll(ptr noundef nonnull %8, ptr noundef null, i32 noundef 0, i32 noundef 1000, ptr noundef null) #3
  %.pre = load i32, ptr %1, align 4
  %.not21 = icmp ne i32 %23, 0
  %.not22 = icmp eq i32 %.pre, 0
  %or.cond23 = select i1 %.not21, i1 true, i1 %.not22
  br i1 %or.cond23, label %.thread, label %19, !llvm.loop !11

.thread:                                          ; preds = %19, %22
  %24 = call i32 @curl_multi_cleanup(ptr noundef nonnull %8) #3
  call void @curl_easy_cleanup(ptr noundef nonnull %7) #3
  %25 = load ptr, ptr %2, align 8, !tbaa !9
  call void @curl_formfree(ptr noundef %25) #3
  call void @curl_slist_free_all(ptr noundef %9) #3
  br label %26

26:                                               ; preds = %.thread, %0
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #3
  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 i32 @curl_formadd(ptr noundef, ptr noundef, ...) local_unnamed_addr #2

declare ptr @curl_easy_init() local_unnamed_addr #2

declare ptr @curl_multi_init() 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_formfree(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 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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