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

; 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.upload_status = type { i64 }

@.str = external hidden unnamed_addr constant [24 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [24 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [19 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 %struct.upload_status, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  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
  store i32 1, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  store ptr null, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  call void @llvm.memset.p0.i64(ptr align 8 %6, i8 0, i64 8, i1 false)
  %9 = call i32 @curl_global_init(i64 noundef 3)
  %10 = call ptr @curl_easy_init()
  store ptr %10, ptr %2, align 8, !tbaa !9
  %11 = load ptr, ptr %2, align 8, !tbaa !9
  %12 = icmp ne ptr %11, null
  br i1 %12, label %14, label %13

13:                                               ; preds = %0
  store i32 1, ptr %1, align 4
  store i32 1, ptr %7, align 4
  br label %67

14:                                               ; preds = %0
  %15 = call ptr @curl_multi_init()
  store ptr %15, ptr %3, align 8, !tbaa !9
  %16 = load ptr, ptr %3, align 8, !tbaa !9
  %17 = icmp ne ptr %16, null
  br i1 %17, label %19, label %18

18:                                               ; preds = %14
  store i32 2, ptr %1, align 4
  store i32 1, ptr %7, align 4
  br label %67

19:                                               ; preds = %14
  %20 = load ptr, ptr %2, align 8, !tbaa !9
  %21 = call i32 (ptr, i32, ...) @curl_easy_setopt(ptr noundef %20, i32 noundef 10002, ptr noundef @.str)
  %22 = load ptr, ptr %2, align 8, !tbaa !9
  %23 = call i32 (ptr, i32, ...) @curl_easy_setopt(ptr noundef %22, i32 noundef 10186, ptr noundef @.str.1)
  %24 = load ptr, ptr %5, align 8, !tbaa !9
  %25 = call ptr @curl_slist_append(ptr noundef %24, ptr noundef @.str.2)
  store ptr %25, ptr %5, align 8, !tbaa !9
  %26 = load ptr, ptr %5, align 8, !tbaa !9
  %27 = call ptr @curl_slist_append(ptr noundef %26, ptr noundef @.str.3)
  store ptr %27, ptr %5, align 8, !tbaa !9
  %28 = load ptr, ptr %2, align 8, !tbaa !9
  %29 = load ptr, ptr %5, align 8, !tbaa !9
  %30 = call i32 (ptr, i32, ...) @curl_easy_setopt(ptr noundef %28, i32 noundef 10187, ptr noundef %29)
  %31 = load ptr, ptr %2, align 8, !tbaa !9
  %32 = call i32 (ptr, i32, ...) @curl_easy_setopt(ptr noundef %31, i32 noundef 20012, ptr noundef @payload_source)
  %33 = load ptr, ptr %2, align 8, !tbaa !9
  %34 = call i32 (ptr, i32, ...) @curl_easy_setopt(ptr noundef %33, i32 noundef 10009, ptr noundef %6)
  %35 = load ptr, ptr %2, align 8, !tbaa !9
  %36 = call i32 (ptr, i32, ...) @curl_easy_setopt(ptr noundef %35, i32 noundef 46, i64 noundef 1)
  %37 = load ptr, ptr %3, align 8, !tbaa !9
  %38 = load ptr, ptr %2, align 8, !tbaa !9
  %39 = call i32 @curl_multi_add_handle(ptr noundef %37, ptr noundef %38)
  br label %40

40:                                               ; preds = %56, %19
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %41 = load ptr, ptr %3, align 8, !tbaa !9
  %42 = call i32 @curl_multi_perform(ptr noundef %41, ptr noundef %4)
  store i32 %42, ptr %8, align 4, !tbaa !5
  %43 = load i32, ptr %4, align 4, !tbaa !5
  %44 = icmp ne i32 %43, 0
  br i1 %44, label %45, label %48

45:                                               ; preds = %40
  %46 = load ptr, ptr %3, align 8, !tbaa !9
  %47 = call i32 @curl_multi_poll(ptr noundef %46, ptr noundef null, i32 noundef 0, i32 noundef 1000, ptr noundef null)
  store i32 %47, ptr %8, align 4, !tbaa !5
  br label %48

48:                                               ; preds = %45, %40
  %49 = load i32, ptr %8, align 4, !tbaa !5
  %50 = icmp ne i32 %49, 0
  br i1 %50, label %51, label %52

51:                                               ; preds = %48
  store i32 2, ptr %7, align 4
  br label %53

52:                                               ; preds = %48
  store i32 0, ptr %7, align 4
  br label %53

53:                                               ; preds = %52, %51
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  %54 = load i32, ptr %7, align 4
  switch i32 %54, label %69 [
    i32 0, label %55
    i32 2, label %59
  ]

55:                                               ; preds = %53
  br label %56

56:                                               ; preds = %55
  %57 = load i32, ptr %4, align 4, !tbaa !5
  %58 = icmp ne i32 %57, 0
  br i1 %58, label %40, label %59, !llvm.loop !11

59:                                               ; preds = %56, %53
  %60 = load ptr, ptr %5, align 8, !tbaa !9
  call void @curl_slist_free_all(ptr noundef %60)
  %61 = load ptr, ptr %3, align 8, !tbaa !9
  %62 = load ptr, ptr %2, align 8, !tbaa !9
  %63 = call i32 @curl_multi_remove_handle(ptr noundef %61, ptr noundef %62)
  %64 = load ptr, ptr %3, align 8, !tbaa !9
  %65 = call i32 @curl_multi_cleanup(ptr noundef %64)
  %66 = load ptr, ptr %2, align 8, !tbaa !9
  call void @curl_easy_cleanup(ptr noundef %66)
  call void @curl_global_cleanup()
  store i32 0, ptr %1, align 4
  store i32 1, ptr %7, align 4
  br label %67

67:                                               ; preds = %59, %18, %13
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, 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
  %68 = load i32, ptr %1, align 4
  ret i32 %68

69:                                               ; preds = %53
  unreachable
}

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

declare i32 @curl_global_init(i64 noundef) #3

declare ptr @curl_easy_init() #3

declare ptr @curl_multi_init() #3

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

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

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

declare i32 @curl_multi_add_handle(ptr noundef, ptr 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 void @curl_slist_free_all(ptr noundef) #3

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

declare i32 @curl_multi_cleanup(ptr noundef) #3

declare void @curl_easy_cleanup(ptr noundef) #3

declare void @curl_global_cleanup() #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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 }

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

%struct.upload_status = type { i64 }

@.str = external hidden unnamed_addr constant [24 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [24 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [19 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 3) i32 @main() local_unnamed_addr #0 {
  %1 = alloca i32, align 4
  %2 = alloca %struct.upload_status, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #3
  store i32 1, ptr %1, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #3
  store i64 0, ptr %2, align 8
  %3 = tail call i32 @curl_global_init(i64 noundef 3) #3
  %4 = tail call ptr @curl_easy_init() #3
  %.not = icmp eq ptr %4, null
  br i1 %.not, label %24, label %5

5:                                                ; preds = %0
  %6 = tail call ptr @curl_multi_init() #3
  %.not26 = icmp eq ptr %6, null
  br i1 %.not26, label %24, label %7

7:                                                ; preds = %5
  %8 = tail call i32 (ptr, i32, ...) @curl_easy_setopt(ptr noundef nonnull %4, i32 noundef 10002, ptr noundef nonnull @.str) #3
  %9 = tail call i32 (ptr, i32, ...) @curl_easy_setopt(ptr noundef nonnull %4, i32 noundef 10186, ptr noundef nonnull @.str.1) #3
  %10 = tail call ptr @curl_slist_append(ptr noundef null, ptr noundef nonnull @.str.2) #3
  %11 = tail call ptr @curl_slist_append(ptr noundef %10, ptr noundef nonnull @.str.3) #3
  %12 = tail call i32 (ptr, i32, ...) @curl_easy_setopt(ptr noundef nonnull %4, i32 noundef 10187, ptr noundef %11) #3
  %13 = tail call i32 (ptr, i32, ...) @curl_easy_setopt(ptr noundef nonnull %4, i32 noundef 20012, ptr noundef nonnull @payload_source) #3
  %14 = call i32 (ptr, i32, ...) @curl_easy_setopt(ptr noundef nonnull %4, i32 noundef 10009, ptr noundef nonnull %2) #3
  %15 = call i32 (ptr, i32, ...) @curl_easy_setopt(ptr noundef nonnull %4, i32 noundef 46, i64 noundef 1) #3
  %16 = call i32 @curl_multi_add_handle(ptr noundef nonnull %6, ptr noundef nonnull %4) #3
  br label %17

17:                                               ; preds = %20, %7
  %18 = call i32 @curl_multi_perform(ptr noundef nonnull %6, ptr noundef nonnull %1) #3
  %19 = load i32, ptr %1, align 4
  %.not27 = icmp eq i32 %19, 0
  br i1 %.not27, label %.thread, label %20

20:                                               ; preds = %17
  %21 = call i32 @curl_multi_poll(ptr noundef nonnull %6, ptr noundef null, i32 noundef 0, i32 noundef 1000, ptr noundef null) #3
  %.pre = load i32, ptr %1, align 4
  %.not28 = icmp ne i32 %21, 0
  %.not29 = icmp eq i32 %.pre, 0
  %or.cond = select i1 %.not28, i1 true, i1 %.not29
  br i1 %or.cond, label %.thread, label %17, !llvm.loop !9

.thread:                                          ; preds = %17, %20
  call void @curl_slist_free_all(ptr noundef %11) #3
  %22 = call i32 @curl_multi_remove_handle(ptr noundef nonnull %6, ptr noundef nonnull %4) #3
  %23 = call i32 @curl_multi_cleanup(ptr noundef nonnull %6) #3
  call void @curl_easy_cleanup(ptr noundef nonnull %4) #3
  call void @curl_global_cleanup() #3
  br label %24

24:                                               ; preds = %5, %0, %.thread
  %.023 = phi i32 [ 0, %.thread ], [ 1, %0 ], [ 2, %5 ]
  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 %.023
}

; 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_global_init(i64 noundef) local_unnamed_addr #2

declare ptr @curl_easy_init() local_unnamed_addr #2

declare ptr @curl_multi_init() local_unnamed_addr #2

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

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

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

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 void @curl_slist_free_all(ptr noundef) local_unnamed_addr #2

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

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_global_cleanup() 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,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,SROAPass,SimplifyCFGPass,TailCallElimPass