#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 msghdr {
  int dummy;
};
struct in_addr {
  int /*<<< orphan*/ member_0;
};
struct cmsghdr {
  int dummy;
};

/* Variables and functions */
struct cmsghdr *CMSG_FIRSTHDR(struct msghdr *);
struct cmsghdr *CMSG_NXTHDR(struct msghdr *, struct cmsghdr *);
struct in_addr socket_dest_ip(struct msghdr *msgh) {
  struct in_addr odst = {0};
  struct cmsghdr *cmsg = NULL;
  for (cmsg = CMSG_FIRSTHDR(msgh); cmsg != NULL;
       cmsg = CMSG_NXTHDR(msgh, cmsg)) {
  }
  return odst;
}


x86 assembly (clang, -O0):
<socket_dest_ip>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x8(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1030 <memset@plt>
movq   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <CMSG_FIRSTHDR@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1187 <socket_dest_ip+0x57>
jmp    1171 <socket_dest_ip+0x41>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <CMSG_NXTHDR@plt>
mov    %rax,-0x18(%rbp)
jmp    1161 <socket_dest_ip+0x31>
mov    -0x8(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<socket_dest_ip>:
push   %rbx
mov    %rdi,%rbx
call   1040 <CMSG_FIRSTHDR@plt>
test   %rax,%rax
je     1140 <socket_dest_ip+0x20>
xchg   %ax,%ax
mov    %rbx,%rdi
mov    %rax,%rsi
call   1030 <CMSG_NXTHDR@plt>
test   %rax,%rax
jne    1130 <socket_dest_ip+0x10>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
%struct.msghdr = type { i32 }
%struct.in_addr = type { i32 }
%struct.cmsghdr = type { i32 }
define i32 @socket_dest_ip(%struct.msghdr* %0) {
%2 = alloca %struct.in_addr
%3 = alloca %struct.msghdr*
%4 = alloca %struct.cmsghdr*
store %struct.msghdr* %0, %struct.msghdr** %3
%5 = bitcast %struct.in_addr* %2 to i8*
store %struct.cmsghdr* null, %struct.cmsghdr** %4
%6 = load %struct.msghdr*, %struct.msghdr** %3
%7 = call %struct.cmsghdr* @CMSG_FIRSTHDR(%struct.msghdr* %6)
store %struct.cmsghdr* %7, %struct.cmsghdr** %4
br label %8
8: ; preds = %12, %1
%9 = load %struct.cmsghdr*, %struct.cmsghdr** %4
%10 = icmp ne %struct.cmsghdr* %9, null
br i1 %10, label %11, label %16
11: ; preds = %8
br label %12
12: ; preds = %11
%13 = load %struct.msghdr*, %struct.msghdr** %3
%14 = load %struct.cmsghdr*, %struct.cmsghdr** %4
%15 = call %struct.cmsghdr* @CMSG_NXTHDR(%struct.msghdr* %13, %struct.cmsghdr* %14)
store %struct.cmsghdr* %15, %struct.cmsghdr** %4
br label %8
16: ; preds = %8
%17 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %2, i32 0, i32 0
%18 = load i32, i32* %17
ret i32 %18
}

LLVM IR (-O2):
%struct.msghdr = type { i32 }
%struct.cmsghdr = type { i32 }
define i32 @socket_dest_ip(%struct.msghdr* %0) {
%2 = tail call %struct.cmsghdr* @CMSG_FIRSTHDR(%struct.msghdr* %0)
%3 = icmp eq %struct.cmsghdr* %2, null
br i1 %3, label %8, label %4
4: ; preds = %1, %4
%5 = phi %struct.cmsghdr* [ %6, %4 ], [ %2, %1 ]
%6 = tail call %struct.cmsghdr* @CMSG_NXTHDR(%struct.msghdr* %0, %struct.cmsghdr* %5)
%7 = icmp eq %struct.cmsghdr* %6, null
br i1 %7, label %8, label %4
8: ; preds = %4, %1
ret i32 0
}