#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 {
  scalar_t__ ss_family;
};
struct sockaddr_in6 {
  int dummy;
};
struct sockaddr_in {
  int dummy;
};

/* Variables and functions */
scalar_t__ AF_INET;
scalar_t__ AF_INET6;
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
char *ipv4ToString(struct sockaddr_in *);
char *ipv6ToString(struct sockaddr_in6 *);
int /*<<< orphan*/ stderr;
char *ipToString(const struct sockaddr_storage *address) {
  if (address->ss_family == AF_INET) {
    return ipv4ToString((struct sockaddr_in *)address);
  }
  if (address->ss_family == AF_INET6) {
    return ipv6ToString((struct sockaddr_in6 *)address);
  }
  fputs("Invalid address type.", stderr);
  return NULL;
}


x86 assembly (clang, -O0):
<ipToString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    0x2e9e(%rip),%rcx
cmp    (%rcx),%rax
jne    1165 <ipToString+0x35>
mov    -0x10(%rbp),%rdi
call   1050 <ipv4ToString@plt>
mov    %rax,-0x8(%rbp)
jmp    11ab <ipToString+0x7b>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    0x2e6d(%rip),%rcx
cmp    (%rcx),%rax
jne    118e <ipToString+0x5e>
mov    -0x10(%rbp),%rdi
call   1040 <ipv6ToString@plt>
mov    %rax,-0x8(%rbp)
jmp    11ab <ipToString+0x7b>
mov    0x2e3b(%rip),%rax
mov    (%rax),%esi
lea    0xe62(%rip),%rdi
call   1030 <fputs@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ipToString>:
push   %rax
mov    (%rdi),%rax
mov    0x2ead(%rip),%rcx
cmp    (%rcx),%rax
jne    1146 <ipToString+0x16>
pop    %rax
jmp    1050 <ipv4ToString@plt>
mov    0x2e93(%rip),%rcx
cmp    (%rcx),%rax
jne    1158 <ipToString+0x28>
pop    %rax
jmp    1040 <ipv6ToString@plt>
mov    0x2e71(%rip),%rax
mov    (%rax),%esi
lea    0xe98(%rip),%rdi
call   1030 <fputs@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
%struct.sockaddr_storage = type { i64 }
%struct.sockaddr_in = type { i32 }
%struct.sockaddr_in6 = type { i32 }
@AF_INET = global i64 0
@AF_INET6 = global i64 0
@.str = [22 x i8] c"Invalid address type.\00"
@stderr = global i32 0
define i8* @ipToString(%struct.sockaddr_storage* %0) {
%2 = alloca i8*
%3 = alloca %struct.sockaddr_storage*
store %struct.sockaddr_storage* %0, %struct.sockaddr_storage** %3
%4 = load %struct.sockaddr_storage*, %struct.sockaddr_storage** %3
%5 = getelementptr inbounds %struct.sockaddr_storage, %struct.sockaddr_storage* %4, i32 0, i32 0
%6 = load i64, i64* %5
%7 = load i64, i64* @AF_INET
%8 = icmp eq i64 %6, %7
br i1 %8, label %9, label %13
9: ; preds = %1
%10 = load %struct.sockaddr_storage*, %struct.sockaddr_storage** %3
%11 = bitcast %struct.sockaddr_storage* %10 to %struct.sockaddr_in*
%12 = call i8* @ipv4ToString(%struct.sockaddr_in* %11)
store i8* %12, i8** %2
br label %26
13: ; preds = %1
%14 = load %struct.sockaddr_storage*, %struct.sockaddr_storage** %3
%15 = getelementptr inbounds %struct.sockaddr_storage, %struct.sockaddr_storage* %14, i32 0, i32 0
%16 = load i64, i64* %15
%17 = load i64, i64* @AF_INET6
%18 = icmp eq i64 %16, %17
br i1 %18, label %19, label %23
19: ; preds = %13
%20 = load %struct.sockaddr_storage*, %struct.sockaddr_storage** %3
%21 = bitcast %struct.sockaddr_storage* %20 to %struct.sockaddr_in6*
%22 = call i8* @ipv6ToString(%struct.sockaddr_in6* %21)
store i8* %22, i8** %2
br label %26
23: ; preds = %13
%24 = load i32, i32* @stderr
%25 = call i32 @fputs(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %24)
store i8* null, i8** %2
br label %26
26: ; preds = %23, %19, %9
%27 = load i8*, i8** %2
ret i8* %27
}

LLVM IR (-O2):
%struct.sockaddr_storage = type { i64 }
%struct.sockaddr_in = type { i32 }
%struct.sockaddr_in6 = type { i32 }
@AF_INET = global i64 0
@AF_INET6 = global i64 0
@.str = [22 x i8] c"Invalid address type.\00"
@stderr = global i32 0
define i8* @ipToString(%struct.sockaddr_storage* %0) {
%2 = getelementptr inbounds %struct.sockaddr_storage, %struct.sockaddr_storage* %0, i64 0, i32 0
%3 = load i64, i64* %2
%4 = load i64, i64* @AF_INET
%5 = icmp eq i64 %3, %4
br i1 %5, label %6, label %9
6: ; preds = %1
%7 = bitcast %struct.sockaddr_storage* %0 to %struct.sockaddr_in*
%8 = tail call i8* @ipv4ToString(%struct.sockaddr_in* %7)
br label %18
9: ; preds = %1
%10 = load i64, i64* @AF_INET6
%11 = icmp eq i64 %3, %10
br i1 %11, label %12, label %15
12: ; preds = %9
%13 = bitcast %struct.sockaddr_storage* %0 to %struct.sockaddr_in6*
%14 = tail call i8* @ipv6ToString(%struct.sockaddr_in6* %13)
br label %18
15: ; preds = %9
%16 = load i32, i32* @stderr
%17 = tail call i32 @fputs(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %16)
br label %18
18: ; preds = %15, %12, %6
%19 = phi i8* [ %8, %6 ], [ %14, %12 ], [ null, %15 ]
ret i8* %19
}