#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_storage {
  int ss_family;
};
struct sockaddr_in6 {
  int /*<<< orphan*/ sin6_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_addr;
};

/* Variables and functions */
#define AF_INET 129
#define AF_INET6 128
int /*<<< orphan*/ INET6_ADDRSTRLEN;
int /*<<< orphan*/ inet_ntop(int, int /*<<< orphan*/ *, char *,
                             int /*<<< orphan*/);
const char *get_ipstring(struct sockaddr_storage *ss, char *dst) {
  switch (ss->ss_family) {
  case AF_INET:
    inet_ntop(ss->ss_family, &((struct sockaddr_in *)ss)->sin_addr, dst,
              INET6_ADDRSTRLEN);
    break;
  case AF_INET6:
    inet_ntop(ss->ss_family, &((struct sockaddr_in6 *)ss)->sin6_addr, dst,
              INET6_ADDRSTRLEN);
    break;
  default:
    dst = NULL;
    break;
  }
  return dst;
}


x86 assembly (clang, -O0):
<get_ipstring>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
sub    $0x80,%eax
je     116d <get_ipstring+0x5d>
jmp    1139 <get_ipstring+0x29>
mov    -0x14(%rbp),%eax
sub    $0x81,%eax
jne    118e <get_ipstring+0x7e>
jmp    114c <get_ipstring+0x3c>
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    0x2e87(%rip),%rax
mov    (%rax),%ecx
call   1030 <inet_ntop@plt>
jmp    1196 <get_ipstring+0x86>
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    0x2e66(%rip),%rax
mov    (%rax),%ecx
call   1030 <inet_ntop@plt>
jmp    1196 <get_ipstring+0x86>
movq   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_ipstring>:
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%rsi
mov    (%rdi),%edi
cmp    $0x81,%edi
je     112e <get_ipstring+0x1e>
cmp    $0x80,%edi
jne    1141 <get_ipstring+0x31>
mov    $0x80,%edi
mov    0x2eb3(%rip),%rax
mov    (%rax),%ecx
mov    %rbx,%rdx
call   1030 <inet_ntop@plt>
jmp    1143 <get_ipstring+0x33>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
%struct.sockaddr_storage = type { i32 }
%struct.sockaddr_in = type { i32 }
%struct.sockaddr_in6 = type { i32 }
@INET6_ADDRSTRLEN = global i32 0
define i8* @get_ipstring(%struct.sockaddr_storage* %0, i8* %1) {
%3 = alloca %struct.sockaddr_storage*
%4 = alloca i8*
store %struct.sockaddr_storage* %0, %struct.sockaddr_storage** %3
store i8* %1, i8** %4
%5 = load %struct.sockaddr_storage*, %struct.sockaddr_storage** %3
%6 = getelementptr inbounds %struct.sockaddr_storage, %struct.sockaddr_storage* %5, i32 0, i32 0
%7 = load i32, i32* %6
switch i32 %7, label %28 [
i32 129, label %8
i32 128, label %18
]
8: ; preds = %2
%9 = load %struct.sockaddr_storage*, %struct.sockaddr_storage** %3
%10 = getelementptr inbounds %struct.sockaddr_storage, %struct.sockaddr_storage* %9, i32 0, i32 0
%11 = load i32, i32* %10
%12 = load %struct.sockaddr_storage*, %struct.sockaddr_storage** %3
%13 = bitcast %struct.sockaddr_storage* %12 to %struct.sockaddr_in*
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %13, i32 0, i32 0
%15 = load i8*, i8** %4
%16 = load i32, i32* @INET6_ADDRSTRLEN
%17 = call i32 @inet_ntop(i32 %11, i32* %14, i8* %15, i32 %16)
br label %29
18: ; preds = %2
%19 = load %struct.sockaddr_storage*, %struct.sockaddr_storage** %3
%20 = getelementptr inbounds %struct.sockaddr_storage, %struct.sockaddr_storage* %19, i32 0, i32 0
%21 = load i32, i32* %20
%22 = load %struct.sockaddr_storage*, %struct.sockaddr_storage** %3
%23 = bitcast %struct.sockaddr_storage* %22 to %struct.sockaddr_in6*
%24 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %23, i32 0, i32 0
%25 = load i8*, i8** %4
%26 = load i32, i32* @INET6_ADDRSTRLEN
%27 = call i32 @inet_ntop(i32 %21, i32* %24, i8* %25, i32 %26)
br label %29
28: ; preds = %2
store i8* null, i8** %4
br label %29
29: ; preds = %28, %18, %8
%30 = load i8*, i8** %4
ret i8* %30
}

LLVM IR (-O2):
%struct.sockaddr_storage = type { i32 }
@INET6_ADDRSTRLEN = global i32 0
define i8* @get_ipstring(%struct.sockaddr_storage* %0, i8* %1) {
%3 = getelementptr inbounds %struct.sockaddr_storage, %struct.sockaddr_storage* %0, i64 0, i32 0
%4 = load i32, i32* %3
switch i32 %4, label %10 [
i32 129, label %6
i32 128, label %5
]
5: ; preds = %2
br label %6
6: ; preds = %2, %5
%7 = phi i32 [ 128, %5 ], [ %4, %2 ]
%8 = load i32, i32* @INET6_ADDRSTRLEN
%9 = tail call i32 @inet_ntop(i32 %7, i32* %3, i8* %1, i32 %8)
br label %10
10: ; preds = %6, %2
%11 = phi i8* [ null, %2 ], [ %1, %6 ]
ret i8* %11
}