#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
struct sockaddr_in6 {
  int /*<<< orphan*/ sin6_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_addr;
};
struct addrinfo {
  scalar_t__ ai_family;
  scalar_t__ ai_addr;
};
typedef int /*<<< orphan*/ addr_str;

/* Variables and functions */
scalar_t__ AF_INET;
scalar_t__ AF_INET6;
int INET6_ADDRSTRLEN;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, char *);
int /*<<< orphan*/ inet_ntop(scalar_t__, int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ stderr;
void print_info(int sock_fd, struct addrinfo *curr) {
  char addr_str[INET6_ADDRSTRLEN];
  if (curr->ai_family == AF_INET6) {
    inet_ntop(AF_INET6, &((struct sockaddr_in6 *)curr->ai_addr)->sin6_addr,
              addr_str, sizeof(addr_str));
  } else {
    inet_ntop(AF_INET, &((struct sockaddr_in *)curr->ai_addr)->sin_addr,
              addr_str, sizeof(addr_str));
  }
  fprintf(stderr, "fd = %d - Trying to connect to %s\n", sock_fd, addr_str);
}


x86 assembly (clang, -O0):
<print_info>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2eb2(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x30(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    0x2e6b(%rip),%rcx
cmp    (%rcx),%rax
jne    119c <print_info+0x7c>
mov    -0x28(%rbp),%rdx
mov    -0x30(%rbp),%rax
mov    0x2e53(%rip),%rcx
mov    (%rcx),%rdi
mov    -0x10(%rbp),%rcx
mov    0x8(%rcx),%rsi
mov    %eax,%ecx
call   1030 <inet_ntop@plt>
jmp    11bd <print_info+0x9d>
mov    -0x28(%rbp),%rdx
mov    -0x30(%rbp),%rax
mov    0x2e35(%rip),%rcx
mov    (%rcx),%rdi
mov    -0x10(%rbp),%rcx
mov    0x8(%rcx),%rsi
mov    %eax,%ecx
call   1030 <inet_ntop@plt>
mov    -0x28(%rbp),%rcx
mov    0x2e00(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%edx
lea    0xe2c(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_info>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
mov    %edi,%r14d
mov    0x2eb7(%rip),%rax
mov    (%rax),%ecx
mov    %rsp,%rbx
mov    %rcx,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    (%rsi),%rdi
mov    0x2e87(%rip),%rax
cmp    (%rax),%rdi
je     1160 <print_info+0x40>
mov    0x2e83(%rip),%rax
mov    (%rax),%rdi
mov    0x8(%rsi),%rsi
mov    %rbx,%rdx
call   1030 <inet_ntop@plt>
mov    0x2e55(%rip),%rax
mov    (%rax),%edi
lea    0xe84(%rip),%rsi
mov    %r14d,%edx
mov    %rbx,%rcx
call   1040 <fprintf@plt>
lea    -0x10(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.addrinfo = type { i64, i64 }
%struct.sockaddr_in6 = type { i32 }
%struct.sockaddr_in = type { i32 }
@INET6_ADDRSTRLEN = global i32 0
@AF_INET6 = global i64 0
@AF_INET = global i64 0
@stderr = global i32 0
@.str = [35 x i8] c"fd = %d - Trying to connect to %s\0A\00"
define void @print_info(i32 %0, %struct.addrinfo* %1) {
%3 = alloca i32
%4 = alloca %struct.addrinfo*
%5 = alloca i8*
%6 = alloca i64
store i32 %0, i32* %3
store %struct.addrinfo* %1, %struct.addrinfo** %4
%7 = load i32, i32* @INET6_ADDRSTRLEN
%8 = zext i32 %7 to i64
%9 = call i8* @llvm.stacksave()
store i8* %9, i8** %5
%10 = alloca i8, i64 %8
store i64 %8, i64* %6
%11 = load %struct.addrinfo*, %struct.addrinfo** %4
%12 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %11, i32 0, i32 0
%13 = load i64, i64* %12
%14 = load i64, i64* @AF_INET6
%15 = icmp eq i64 %13, %14
br i1 %15, label %16, label %25
16: ; preds = %2
%17 = load i64, i64* @AF_INET6
%18 = load %struct.addrinfo*, %struct.addrinfo** %4
%19 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %18, i32 0, i32 1
%20 = load i64, i64* %19
%21 = inttoptr i64 %20 to %struct.sockaddr_in6*
%22 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %21, i32 0, i32 0
%23 = trunc i64 %8 to i32
%24 = call i32 @inet_ntop(i64 %17, i32* %22, i8* %10, i32 %23)
br label %34
25: ; preds = %2
%26 = load i64, i64* @AF_INET
%27 = load %struct.addrinfo*, %struct.addrinfo** %4
%28 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %27, i32 0, i32 1
%29 = load i64, i64* %28
%30 = inttoptr i64 %29 to %struct.sockaddr_in*
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %30, i32 0, i32 0
%32 = trunc i64 %8 to i32
%33 = call i32 @inet_ntop(i64 %26, i32* %31, i8* %10, i32 %32)
br label %34
34: ; preds = %25, %16
%35 = load i32, i32* @stderr
%36 = load i32, i32* %3
%37 = call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %36, i8* %10)
%38 = load i8*, i8** %5
ret void
}

LLVM IR (-O2):
%struct.addrinfo = type { i64, i64 }
%struct.sockaddr_in6 = type { i32 }
%struct.sockaddr_in = type { i32 }
@INET6_ADDRSTRLEN = global i32 0
@AF_INET6 = global i64 0
@AF_INET = global i64 0
@stderr = global i32 0
@.str = [35 x i8] c"fd = %d - Trying to connect to %s\0A\00"
define void @print_info(i32 %0, %struct.addrinfo* nocapture %1) {
%3 = load i32, i32* @INET6_ADDRSTRLEN
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %1, i64 0, i32 0
%7 = load i64, i64* %6
%8 = load i64, i64* @AF_INET6
%9 = icmp eq i64 %7, %8
br i1 %9, label %10, label %16
10: ; preds = %2
%11 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %1, i64 0, i32 1
%12 = load i64, i64* %11
%13 = inttoptr i64 %12 to %struct.sockaddr_in6*
%14 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %13, i64 0, i32 0
%15 = call i32 @inet_ntop(i64 %7, i32* %14, i8* %5, i32 %3)
br label %23
16: ; preds = %2
%17 = load i64, i64* @AF_INET
%18 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %1, i64 0, i32 1
%19 = load i64, i64* %18
%20 = inttoptr i64 %19 to %struct.sockaddr_in*
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %20, i64 0, i32 0
%22 = call i32 @inet_ntop(i64 %17, i32* %21, i8* %5, i32 %3)
br label %23
23: ; preds = %16, %10
%24 = load i32, i32* @stderr
%25 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %0, i8* %5)
ret void
}