#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 */
typedef int /*<<< orphan*/ u_int8_t;
struct TYPE_3__ {
  int /*<<< orphan*/ s6_addr;
};
struct sockaddr_in6 {
  TYPE_1__ sin6_addr;
};
struct TYPE_4__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  TYPE_2__ sin_addr;
};
struct sockaddr {
  int sa_family;
};

/* Variables and functions */
#define AF_INET 129
#define AF_INET6 128
int /*<<< orphan*/ log_print(char *, int);
u_int8_t *sockaddr_addrdata(struct sockaddr *sa) {
  switch (sa->sa_family) {
  case AF_INET6:
    return (u_int8_t *)&((struct sockaddr_in6 *)sa)->sin6_addr.s6_addr;
  case AF_INET:
    return (u_int8_t *)&((struct sockaddr_in *)sa)->sin_addr.s_addr;
  default:
    log_print("sockaddr_addrdata: unsupported protocol family %d",
              sa->sa_family);
    return 0;
  }
}


x86 assembly (clang, -O0):
<sockaddr_addrdata>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
sub    $0x80,%eax
je     1148 <sockaddr_addrdata+0x38>
jmp    1135 <sockaddr_addrdata+0x25>
mov    -0x14(%rbp),%eax
sub    $0x81,%eax
je     1155 <sockaddr_addrdata+0x45>
jmp    1162 <sockaddr_addrdata+0x52>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    117c <sockaddr_addrdata+0x6c>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    117c <sockaddr_addrdata+0x6c>
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
lea    0xe91(%rip),%rdi
call   1030 <log_print@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sockaddr_addrdata>:
push   %rax
mov    %rdi,%rax
mov    (%rdi),%esi
mov    %esi,%ecx
and    $0xfffffffe,%ecx
cmp    $0x80,%ecx
je     1131 <sockaddr_addrdata+0x21>
lea    0xed6(%rip),%rdi
call   1030 <log_print@plt>
xor    %eax,%eax
pop    %rcx
ret

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

LLVM IR (-O2):
%struct.sockaddr = type { i32 }
@.str = [50 x i8] c"sockaddr_addrdata: unsupported protocol family %d\00"
define i32* @sockaddr_addrdata(%struct.sockaddr* %0) {
%2 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %0, i64 0, i32 0
%3 = load i32, i32* %2
%4 = and i32 %3, -2
%5 = icmp eq i32 %4, 128
br i1 %5, label %8, label %6
6: ; preds = %1
%7 = tail call i32 @log_print(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i32 %3)
br label %8
8: ; preds = %1, %6
%9 = phi i32* [ null, %6 ], [ %2, %1 ]
ret i32* %9
}