; LLVM IR from holzschu/ios_system :: curl/curl/docs/examples (externalsocket)

; 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.sockaddr_in = type { i16, i16, %struct.in_addr, [8 x i8] }
%struct.in_addr = type { i32 }

@.str = external hidden unnamed_addr constant [24 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [34 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [27 x i8], align 1
@.str.4 = 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 i32, align 4
  %4 = alloca %struct.sockaddr_in, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #7
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #7
  call void @llvm.lifetime.start.p0(i64 16, ptr %4) #7
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #7
  %7 = call ptr @curl_easy_init()
  store ptr %7, ptr %2, align 8, !tbaa !5
  %8 = load ptr, ptr %2, align 8, !tbaa !5
  %9 = icmp ne ptr %8, null
  br i1 %9, label %10, label %71

10:                                               ; preds = %0
  %11 = load ptr, ptr %2, align 8, !tbaa !5
  %12 = call i32 (ptr, i32, ...) @curl_easy_setopt(ptr noundef %11, i32 noundef 10002, ptr noundef @.str)
  %13 = call i32 @socket(i32 noundef 2, i32 noundef 1, i32 noundef 0) #7
  store i32 %13, ptr %5, align 4, !tbaa !9
  %14 = load i32, ptr %5, align 4, !tbaa !9
  %15 = icmp eq i32 %14, -1
  br i1 %15, label %16, label %18

16:                                               ; preds = %10
  %17 = call i32 (ptr, ...) @printf(ptr noundef @.str.1)
  store i32 3, ptr %1, align 4
  store i32 1, ptr %6, align 4
  br label %72

18:                                               ; preds = %10
  call void @llvm.memset.p0.i64(ptr align 4 %4, i8 0, i64 16, i1 false)
  %19 = getelementptr inbounds %struct.sockaddr_in, ptr %4, i32 0, i32 0
  store i16 2, ptr %19, align 4, !tbaa !11
  %20 = call zeroext i16 @__bswap_16(i16 noundef zeroext 80)
  %21 = getelementptr inbounds %struct.sockaddr_in, ptr %4, i32 0, i32 1
  store i16 %20, ptr %21, align 2, !tbaa !15
  %22 = call i32 @inet_addr(ptr noundef @.str.2) #7
  %23 = getelementptr inbounds %struct.sockaddr_in, ptr %4, i32 0, i32 2
  %24 = getelementptr inbounds %struct.in_addr, ptr %23, i32 0, i32 0
  store i32 %22, ptr %24, align 4, !tbaa !16
  %25 = getelementptr inbounds %struct.sockaddr_in, ptr %4, i32 0, i32 2
  %26 = getelementptr inbounds %struct.in_addr, ptr %25, i32 0, i32 0
  %27 = load i32, ptr %26, align 4, !tbaa !16
  %28 = icmp eq i32 -1, %27
  br i1 %28, label %29, label %32

29:                                               ; preds = %18
  %30 = load i32, ptr %5, align 4, !tbaa !9
  %31 = call i32 @close(i32 noundef %30)
  store i32 2, ptr %1, align 4
  store i32 1, ptr %6, align 4
  br label %72

32:                                               ; preds = %18
  %33 = load i32, ptr %5, align 4, !tbaa !9
  %34 = call i32 @connect(i32 noundef %33, ptr noundef %4, i32 noundef 16)
  %35 = icmp eq i32 %34, -1
  br i1 %35, label %36, label %43

36:                                               ; preds = %32
  %37 = load i32, ptr %5, align 4, !tbaa !9
  %38 = call i32 @close(i32 noundef %37)
  %39 = call ptr @__errno_location() #8
  %40 = load i32, ptr %39, align 4, !tbaa !9
  %41 = call ptr @strerror(i32 noundef %40) #7
  %42 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, ptr noundef %41)
  store i32 1, ptr %1, align 4
  store i32 1, ptr %6, align 4
  br label %72

43:                                               ; preds = %32
  %44 = load ptr, ptr %2, align 8, !tbaa !5
  %45 = call i32 (ptr, i32, ...) @curl_easy_setopt(ptr noundef %44, i32 noundef 43, i64 noundef 1)
  %46 = load ptr, ptr %2, align 8, !tbaa !5
  %47 = call i32 (ptr, i32, ...) @curl_easy_setopt(ptr noundef %46, i32 noundef 20011, ptr noundef @write_data)
  %48 = load ptr, ptr %2, align 8, !tbaa !5
  %49 = call i32 (ptr, i32, ...) @curl_easy_setopt(ptr noundef %48, i32 noundef 20163, ptr noundef @opensocket)
  %50 = load ptr, ptr %2, align 8, !tbaa !5
  %51 = call i32 (ptr, i32, ...) @curl_easy_setopt(ptr noundef %50, i32 noundef 10164, ptr noundef %5)
  %52 = load ptr, ptr %2, align 8, !tbaa !5
  %53 = call i32 (ptr, i32, ...) @curl_easy_setopt(ptr noundef %52, i32 noundef 20208, ptr noundef @closecb)
  %54 = load ptr, ptr %2, align 8, !tbaa !5
  %55 = call i32 (ptr, i32, ...) @curl_easy_setopt(ptr noundef %54, i32 noundef 10209, ptr noundef %5)
  %56 = load ptr, ptr %2, align 8, !tbaa !5
  %57 = call i32 (ptr, i32, ...) @curl_easy_setopt(ptr noundef %56, i32 noundef 20148, ptr noundef @sockopt_callback)
  %58 = load ptr, ptr %2, align 8, !tbaa !5
  %59 = call i32 (ptr, i32, ...) @curl_easy_setopt(ptr noundef %58, i32 noundef 41, i32 noundef 1)
  %60 = load ptr, ptr %2, align 8, !tbaa !5
  %61 = call i32 @curl_easy_perform(ptr noundef %60)
  store i32 %61, ptr %3, align 4, !tbaa !9
  %62 = load ptr, ptr %2, align 8, !tbaa !5
  call void @curl_easy_cleanup(ptr noundef %62)
  %63 = load i32, ptr %5, align 4, !tbaa !9
  %64 = call i32 @close(i32 noundef %63)
  %65 = load i32, ptr %3, align 4, !tbaa !9
  %66 = icmp ne i32 %65, 0
  br i1 %66, label %67, label %70

67:                                               ; preds = %43
  %68 = load i32, ptr %3, align 4, !tbaa !9
  %69 = call i32 (ptr, ...) @printf(ptr noundef @.str.4, i32 noundef %68)
  store i32 4, ptr %1, align 4
  store i32 1, ptr %6, align 4
  br label %72

70:                                               ; preds = %43
  br label %71

71:                                               ; preds = %70, %0
  store i32 0, ptr %1, align 4
  store i32 1, ptr %6, align 4
  br label %72

72:                                               ; preds = %71, %67, %36, %29, %16
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #7
  call void @llvm.lifetime.end.p0(i64 16, ptr %4) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #7
  %73 = load i32, ptr %1, align 4
  ret i32 %73
}

; 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 i32 @curl_easy_setopt(ptr noundef, i32 noundef, ...) #2

; Function Attrs: nounwind
declare i32 @socket(i32 noundef, i32 noundef, i32 noundef) #3

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

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i16 @__bswap_16(i16 noundef zeroext) #5

; Function Attrs: nounwind
declare i32 @inet_addr(ptr noundef) #3

declare i32 @close(i32 noundef) #2

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

; Function Attrs: nounwind
declare ptr @strerror(i32 noundef) #3

; Function Attrs: nounwind willreturn memory(none)
declare ptr @__errno_location() #6

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

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

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

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

declare i32 @curl_easy_perform(ptr noundef) #2

declare void @curl_easy_cleanup(ptr noundef) #2

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

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 "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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #5 = { inlinehint 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 #6 = { nounwind willreturn memory(none) "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 #7 = { nounwind }
attributes #8 = { nounwind willreturn memory(none) }

!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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !13, i64 0}
!12 = !{!"sockaddr_in", !13, i64 0, !13, i64 2, !14, i64 4, !7, i64 8}
!13 = !{!"short", !7, i64 0}
!14 = !{!"in_addr", !10, i64 0}
!15 = !{!12, !13, i64 2}
!16 = !{!12, !10, i64 4}


; 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.sockaddr_in = type { i16, i16, %struct.in_addr, [8 x i8] }
%struct.in_addr = type { i32 }

@.str = external hidden unnamed_addr constant [24 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [34 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [27 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [19 x i8], align 1

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

4:                                                ; preds = %0
  %5 = tail call i32 (ptr, i32, ...) @curl_easy_setopt(ptr noundef nonnull %3, i32 noundef 10002, ptr noundef nonnull @.str) #7
  %6 = tail call i32 @socket(i32 noundef 2, i32 noundef 1, i32 noundef 0) #7
  store i32 %6, ptr %2, align 4, !tbaa !5
  %7 = icmp eq i32 %6, -1
  br i1 %7, label %8, label %10

8:                                                ; preds = %4
  %9 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1)
  br label %42

10:                                               ; preds = %4
  %11 = getelementptr inbounds i8, ptr %1, i64 8
  store i64 0, ptr %11, align 4
  store i16 2, ptr %1, align 4, !tbaa !9
  %12 = tail call zeroext i16 @__bswap_16(i16 noundef zeroext 80)
  %13 = getelementptr inbounds i8, ptr %1, i64 2
  store i16 %12, ptr %13, align 2, !tbaa !13
  %14 = tail call i32 @inet_addr(ptr noundef nonnull @.str.2) #7
  %15 = getelementptr inbounds i8, ptr %1, i64 4
  store i32 %14, ptr %15, align 4, !tbaa !14
  %16 = icmp eq i32 %14, -1
  br i1 %16, label %17, label %19

17:                                               ; preds = %10
  %18 = tail call i32 @close(i32 noundef %6) #7
  br label %42

19:                                               ; preds = %10
  %20 = call i32 @connect(i32 noundef %6, ptr noundef nonnull %1, i32 noundef 16) #7
  %21 = icmp eq i32 %20, -1
  br i1 %21, label %22, label %28

22:                                               ; preds = %19
  %23 = call i32 @close(i32 noundef %6) #7
  %24 = tail call ptr @__errno_location() #8
  %25 = load i32, ptr %24, align 4, !tbaa !5
  %26 = call ptr @strerror(i32 noundef %25) #7
  %27 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, ptr noundef %26)
  br label %42

28:                                               ; preds = %19
  %29 = call i32 (ptr, i32, ...) @curl_easy_setopt(ptr noundef nonnull %3, i32 noundef 43, i64 noundef 1) #7
  %30 = call i32 (ptr, i32, ...) @curl_easy_setopt(ptr noundef nonnull %3, i32 noundef 20011, ptr noundef nonnull @write_data) #7
  %31 = call i32 (ptr, i32, ...) @curl_easy_setopt(ptr noundef nonnull %3, i32 noundef 20163, ptr noundef nonnull @opensocket) #7
  %32 = call i32 (ptr, i32, ...) @curl_easy_setopt(ptr noundef nonnull %3, i32 noundef 10164, ptr noundef nonnull %2) #7
  %33 = call i32 (ptr, i32, ...) @curl_easy_setopt(ptr noundef nonnull %3, i32 noundef 20208, ptr noundef nonnull @closecb) #7
  %34 = call i32 (ptr, i32, ...) @curl_easy_setopt(ptr noundef nonnull %3, i32 noundef 10209, ptr noundef nonnull %2) #7
  %35 = call i32 (ptr, i32, ...) @curl_easy_setopt(ptr noundef nonnull %3, i32 noundef 20148, ptr noundef nonnull @sockopt_callback) #7
  %36 = call i32 (ptr, i32, ...) @curl_easy_setopt(ptr noundef nonnull %3, i32 noundef 41, i32 noundef 1) #7
  %37 = call i32 @curl_easy_perform(ptr noundef nonnull %3) #7
  call void @curl_easy_cleanup(ptr noundef nonnull %3) #7
  %38 = load i32, ptr %2, align 4, !tbaa !5
  %39 = call i32 @close(i32 noundef %38) #7
  %.not16 = icmp eq i32 %37, 0
  br i1 %.not16, label %42, label %40

40:                                               ; preds = %28
  %41 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4, i32 noundef %37)
  br label %42

42:                                               ; preds = %0, %28, %40, %22, %17, %8
  %.0 = phi i32 [ 3, %8 ], [ 2, %17 ], [ 1, %22 ], [ 4, %40 ], [ 0, %28 ], [ 0, %0 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #7
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %1) #7
  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 i32 @curl_easy_setopt(ptr noundef, i32 noundef, ...) local_unnamed_addr #2

; Function Attrs: nounwind
declare i32 @socket(i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #3

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #4

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i16 @__bswap_16(i16 noundef zeroext) local_unnamed_addr #5

; Function Attrs: nounwind
declare i32 @inet_addr(ptr noundef) local_unnamed_addr #3

declare i32 @close(i32 noundef) local_unnamed_addr #2

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

; Function Attrs: nounwind
declare ptr @strerror(i32 noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
declare ptr @__errno_location() local_unnamed_addr #6

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

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

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

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

declare i32 @curl_easy_perform(ptr noundef) local_unnamed_addr #2

declare void @curl_easy_cleanup(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

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 "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 = { nofree nounwind "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 #5 = { inlinehint 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 #6 = { mustprogress nofree nosync nounwind willreturn memory(none) "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 #7 = { nounwind }
attributes #8 = { nounwind willreturn memory(none) }

!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, !11, i64 0}
!10 = !{!"sockaddr_in", !11, i64 0, !11, i64 2, !12, i64 4, !7, i64 8}
!11 = !{!"short", !7, i64 0}
!12 = !{!"in_addr", !6, i64 0}
!13 = !{!10, !11, i64 2}
!14 = !{!10, !6, i64 4}


; Effective O3 passes: DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass