#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_2__ TYPE_1__;

/* Type definitions */
typedef int /*<<< orphan*/ uint8_t;
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
  TYPE_1__ sin_addr;
};
struct sockaddr {
  scalar_t__ sa_family;
};

/* Variables and functions */
scalar_t__ AF_INET;
int /*<<< orphan*/ LOG_DEBUG;
int /*<<< orphan*/ LOG_INFO;
int /*<<< orphan*/ ipv4(int /*<<< orphan*/ const *);
int /*<<< orphan*/ ntohs(int /*<<< orphan*/);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *, scalar_t__, ...);
void log_address(struct sockaddr *pin) {
  struct sockaddr_in *pi;
  if (pin->sa_family != AF_INET) {
    syslog(LOG_INFO, "wrong family of packet: %d", pin->sa_family);
    return;
  }
  pi = (struct sockaddr_in *)pin;
  syslog(LOG_DEBUG, "Address: %s:%d",
         ipv4((uint8_t const *)&pi->sin_addr.s_addr), ntohs(pi->sin_port));
}


x86 assembly (clang, -O0):
<log_address>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    0x2e9e(%rip),%rcx
cmp    (%rcx),%rax
je     1176 <log_address+0x46>
mov    0x2e76(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rax
mov    (%rax),%rdx
lea    0xe96(%rip),%rsi
mov    $0x0,%al
call   1030 <syslog@plt>
jmp    11bf <log_address+0x8f>
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    0x2e53(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
add    $0x4,%rdi
call   1050 <ipv4@plt>
cltq
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
call   1040 <ntohs@plt>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rdx
mov    %eax,%ecx
lea    0xe63(%rip),%rsi
mov    $0x0,%al
call   1030 <syslog@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<log_address>:
push   %rbp
push   %r14
push   %rbx
mov    (%rdi),%rdx
mov    0x2eaa(%rip),%rax
cmp    (%rax),%rdx
jne    117d <log_address+0x4d>
mov    %rdi,%rbx
mov    0x2e8b(%rip),%rax
mov    (%rax),%r14d
add    $0x4,%rdi
call   1050 <ipv4@plt>
movslq %eax,%rbp
mov    (%rbx),%edi
call   1040 <ntohs@plt>
lea    0xeb1(%rip),%rsi
mov    %r14d,%edi
mov    %rbp,%rdx
mov    %eax,%ecx
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <syslog@plt>
mov    0x2e4c(%rip),%rax
mov    (%rax),%edi
lea    0xe73(%rip),%rsi
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <syslog@plt>

LLVM IR (-O0):
%struct.sockaddr = type { i64 }
%struct.sockaddr_in = type { i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
@AF_INET = global i64 0
@LOG_INFO = global i32 0
@.str = [27 x i8] c"wrong family of packet: %d\00"
@LOG_DEBUG = global i32 0
@.str.1 = [15 x i8] c"Address: %s:%d\00"
define void @log_address(%struct.sockaddr* %0) {
%2 = alloca %struct.sockaddr*
%3 = alloca %struct.sockaddr_in*
store %struct.sockaddr* %0, %struct.sockaddr** %2
%4 = load %struct.sockaddr*, %struct.sockaddr** %2
%5 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %4, i32 0, i32 0
%6 = load i64, i64* %5
%7 = load i64, i64* @AF_INET
%8 = icmp ne i64 %6, %7
br i1 %8, label %9, label %15
9: ; preds = %1
%10 = load i32, i32* @LOG_INFO
%11 = load %struct.sockaddr*, %struct.sockaddr** %2
%12 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %11, i32 0, i32 0
%13 = load i64, i64* %12
%14 = call i32 (i32, i8*, i64, ...) @syslog(i32 %10, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i64 %13)
br label %29
15: ; preds = %1
%16 = load %struct.sockaddr*, %struct.sockaddr** %2
%17 = bitcast %struct.sockaddr* %16 to %struct.sockaddr_in*
store %struct.sockaddr_in* %17, %struct.sockaddr_in** %3
%18 = load i32, i32* @LOG_DEBUG
%19 = load %struct.sockaddr_in*, %struct.sockaddr_in** %3
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %19, i32 0, i32 1
%21 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %20, i32 0, i32 0
%22 = call i32 @ipv4(i32* %21)
%23 = sext i32 %22 to i64
%24 = load %struct.sockaddr_in*, %struct.sockaddr_in** %3
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %24, i32 0, i32 0
%26 = load i32, i32* %25
%27 = call i32 @ntohs(i32 %26)
%28 = call i32 (i32, i8*, i64, ...) @syslog(i32 %18, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i64 %23, i32 %27)
br label %29
29: ; preds = %15, %9
ret void
}

LLVM IR (-O2):
%struct.sockaddr = type { i64 }
%struct.sockaddr_in = type { i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
@AF_INET = global i64 0
@LOG_INFO = global i32 0
@.str = [27 x i8] c"wrong family of packet: %d\00"
@LOG_DEBUG = global i32 0
@.str.1 = [15 x i8] c"Address: %s:%d\00"
define void @log_address(%struct.sockaddr* %0) {
%2 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %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 %9, label %6
6: ; preds = %1
%7 = load i32, i32* @LOG_INFO
%8 = tail call i32 (i32, i8*, i64, ...) @syslog(i32 %7, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i64 %3)
br label %19
9: ; preds = %1
%10 = bitcast %struct.sockaddr* %0 to %struct.sockaddr_in*
%11 = load i32, i32* @LOG_DEBUG
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i64 0, i32 1, i32 0
%13 = tail call i32 @ipv4(i32* %12)
%14 = sext i32 %13 to i64
%15 = bitcast %struct.sockaddr* %0 to i32*
%16 = load i32, i32* %15
%17 = tail call i32 @ntohs(i32 %16)
%18 = tail call i32 (i32, i8*, i64, ...) @syslog(i32 %11, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i64 %14, i32 %17)
br label %19
19: ; preds = %9, %6
ret void
}