#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 */
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  TYPE_1__ sin_addr;
};
struct sockaddr {
  scalar_t__ sa_family;
};

/* Variables and functions */
scalar_t__ AF_INET;
unsigned long ntohl(int /*<<< orphan*/);
unsigned long SockAddrToUint32(struct sockaddr *a) {
  return ((a) && (a->sa_family == AF_INET))
             ? ntohl(((struct sockaddr_in *)a)->sin_addr.s_addr)
             : 0;
}


x86 assembly (clang, -O0):
<SockAddrToUint32>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1152 <SockAddrToUint32+0x42>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    0x2eb3(%rip),%rcx
cmp    (%rcx),%rax
jne    1152 <SockAddrToUint32+0x42>
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
call   1030 <ntohl@plt>
mov    %rax,-0x10(%rbp)
jmp    115d <SockAddrToUint32+0x4d>
xor    %eax,%eax
mov    %rax,-0x10(%rbp)
jmp    115d <SockAddrToUint32+0x4d>
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SockAddrToUint32>:
test   %rdi,%rdi
je     1129 <SockAddrToUint32+0x19>
mov    (%rdi),%rdi
mov    0x2ec9(%rip),%rax
cmp    (%rax),%rdi
jne    1129 <SockAddrToUint32+0x19>
jmp    1030 <ntohl@plt>
xor    %eax,%eax
ret

LLVM IR (-O0):
%struct.sockaddr = type { i64 }
%struct.sockaddr_in = type { %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
@AF_INET = global i64 0
define i64 @SockAddrToUint32(%struct.sockaddr* %0) {
%2 = alloca %struct.sockaddr*
store %struct.sockaddr* %0, %struct.sockaddr** %2
%3 = load %struct.sockaddr*, %struct.sockaddr** %2
%4 = icmp ne %struct.sockaddr* %3, null
br i1 %4, label %5, label %18
5: ; preds = %1
%6 = load %struct.sockaddr*, %struct.sockaddr** %2
%7 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %6, i32 0, i32 0
%8 = load i64, i64* %7
%9 = load i64, i64* @AF_INET
%10 = icmp eq i64 %8, %9
br i1 %10, label %11, label %18
11: ; preds = %5
%12 = load %struct.sockaddr*, %struct.sockaddr** %2
%13 = bitcast %struct.sockaddr* %12 to %struct.sockaddr_in*
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %13, i32 0, i32 0
%15 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %14, i32 0, i32 0
%16 = load i32, i32* %15
%17 = call i64 @ntohl(i32 %16)
br label %19
18: ; preds = %5, %1
br label %19
19: ; preds = %18, %11
%20 = phi i64 [ %17, %11 ], [ 0, %18 ]
ret i64 %20
}

LLVM IR (-O2):
%struct.sockaddr = type { i64 }
@AF_INET = global i64 0
define i64 @SockAddrToUint32(%struct.sockaddr* %0) {
%2 = icmp eq %struct.sockaddr* %0, null
br i1 %2, label %11, label %3
3: ; preds = %1
%4 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %0, i64 0, i32 0
%5 = load i64, i64* %4
%6 = load i64, i64* @AF_INET
%7 = icmp eq i64 %5, %6
br i1 %7, label %8, label %11
8: ; preds = %3
%9 = trunc i64 %5 to i32
%10 = tail call i64 @ntohl(i32 %9)
br label %11
11: ; preds = %1, %3, %8
%12 = phi i64 [ %10, %8 ], [ 0, %3 ], [ 0, %1 ]
ret i64 %12
}