#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 */
typedef struct TYPE_4__ TYPE_2__;
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
struct TYPE_4__ {
  int /*<<< orphan*/ s6_addr16;
};
struct sockaddr_in6 {
  TYPE_2__ sin6_addr;
};
struct TYPE_3__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  TYPE_1__ sin_addr;
};
struct sockaddr {
  int sa_family;
};

/* Variables and functions */
#define AF_INET 129
#define AF_INET6 128
int /*<<< orphan*/ print_quad_ipv4(int /*<<< orphan*/);
int /*<<< orphan*/ print_quad_ipv6(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
void print_quad(struct sockaddr *adr) {
  switch (adr->sa_family) {
  case AF_INET:
    print_quad_ipv4(((struct sockaddr_in *)adr)->sin_addr.s_addr);
    break;
  case AF_INET6:
    print_quad_ipv6(((struct sockaddr_in6 *)adr)->sin6_addr.s6_addr16);
    break;
  default:
    printf("NON-IP");
    break;
  }
}


x86 assembly (clang, -O0):
<print_quad>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
sub    $0x80,%eax
je     1178 <print_quad+0x48>
jmp    1155 <print_quad+0x25>
mov    -0xc(%rbp),%eax
sub    $0x81,%eax
jne    1188 <print_quad+0x58>
jmp    1168 <print_quad+0x38>
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
call   1030 <print_quad_ipv4@plt>
jmp    1194 <print_quad+0x64>
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
call   1040 <print_quad_ipv6@plt>
jmp    1194 <print_quad+0x64>
lea    0xe71(%rip),%rdi
call   1050 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_quad>:
mov    (%rdi),%eax
cmp    $0x80,%eax
je     114a <print_quad+0x1a>
cmp    $0x81,%eax
jne    1154 <print_quad+0x24>
mov    $0x81,%edi
jmp    1030 <print_quad_ipv4@plt>
mov    $0x80,%edi
jmp    1040 <print_quad_ipv6@plt>
lea    0xea5(%rip),%rdi
jmp    1050 <printf@plt>

LLVM IR (-O0):
%struct.sockaddr = type { i32 }
%struct.sockaddr_in = type { %struct.TYPE_3__ }
%struct.TYPE_3__ = type { i32 }
%struct.sockaddr_in6 = type { %struct.TYPE_4__ }
%struct.TYPE_4__ = type { i32 }
@.str = [7 x i8] c"NON-IP\00"
define void @print_quad(%struct.sockaddr* %0) {
%2 = alloca %struct.sockaddr*
store %struct.sockaddr* %0, %struct.sockaddr** %2
%3 = load %struct.sockaddr*, %struct.sockaddr** %2
%4 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %3, i32 0, i32 0
%5 = load i32, i32* %4
switch i32 %5, label %20 [
i32 129, label %6
i32 128, label %13
]
6: ; preds = %1
%7 = load %struct.sockaddr*, %struct.sockaddr** %2
%8 = bitcast %struct.sockaddr* %7 to %struct.sockaddr_in*
%9 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
%10 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %9, i32 0, i32 0
%11 = load i32, i32* %10
%12 = call i32 @print_quad_ipv4(i32 %11)
br label %22
13: ; preds = %1
%14 = load %struct.sockaddr*, %struct.sockaddr** %2
%15 = bitcast %struct.sockaddr* %14 to %struct.sockaddr_in6*
%16 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %15, i32 0, i32 0
%17 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %16, i32 0, i32 0
%18 = load i32, i32* %17
%19 = call i32 @print_quad_ipv6(i32 %18)
br label %22
20: ; preds = %1
%21 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %22
22: ; preds = %20, %13, %6
ret void
}

LLVM IR (-O2):
%struct.sockaddr = type { i32 }
@.str = [7 x i8] c"NON-IP\00"
define void @print_quad(%struct.sockaddr* nocapture %0) {
%2 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %0, i64 0, i32 0
%3 = load i32, i32* %2
switch i32 %3, label %8 [
i32 129, label %4
i32 128, label %6
]
4: ; preds = %1
%5 = tail call i32 @print_quad_ipv4(i32 129)
br label %10
6: ; preds = %1
%7 = tail call i32 @print_quad_ipv6(i32 128)
br label %10
8: ; preds = %1
%9 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %8, %6, %4
ret void
}