#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 in_addr {
  int s_addr;
  int /*<<< orphan*/ member_0;
};
struct in6_addr {
  int *s6_addr;
};

/* Variables and functions */
struct in_addr convert_ipv6_to_ipv4(struct in6_addr *ip6) {
  struct in_addr result = {0};
  result.s_addr = (ip6->s6_addr[12] << 24) + (ip6->s6_addr[13] << 16) +
                  (ip6->s6_addr[14] << 8) + (ip6->s6_addr[15]);
  return result;
}


x86 assembly (clang, -O0):
<convert_ipv6_to_ipv4>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x8(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1030 <memset@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    0x30(%rax),%eax
shl    $0x18,%eax
mov    -0x10(%rbp),%rcx
mov    (%rcx),%rcx
mov    0x34(%rcx),%ecx
shl    $0x10,%ecx
add    %ecx,%eax
mov    -0x10(%rbp),%rcx
mov    (%rcx),%rcx
mov    0x38(%rcx),%ecx
shl    $0x8,%ecx
add    %ecx,%eax
mov    -0x10(%rbp),%rcx
mov    (%rcx),%rcx
add    0x3c(%rcx),%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<convert_ipv6_to_ipv4>:
mov    (%rdi),%rcx
mov    0x30(%rcx),%eax
mov    0x34(%rcx),%edx
shl    $0x18,%eax
shl    $0x10,%edx
add    %eax,%edx
mov    0x38(%rcx),%eax
shl    $0x8,%eax
add    %edx,%eax
add    0x3c(%rcx),%eax
ret

LLVM IR (-O0):
%struct.in6_addr = type { i32* }
%struct.in_addr = type { i32, i32 }
define i64 @convert_ipv6_to_ipv4(%struct.in6_addr* %0) {
%2 = alloca %struct.in_addr
%3 = alloca %struct.in6_addr*
store %struct.in6_addr* %0, %struct.in6_addr** %3
%4 = bitcast %struct.in_addr* %2 to i8*
%5 = load %struct.in6_addr*, %struct.in6_addr** %3
%6 = getelementptr inbounds %struct.in6_addr, %struct.in6_addr* %5, i32 0, i32 0
%7 = load i32*, i32** %6
%8 = getelementptr inbounds i32, i32* %7, i64 12
%9 = load i32, i32* %8
%10 = shl i32 %9, 24
%11 = load %struct.in6_addr*, %struct.in6_addr** %3
%12 = getelementptr inbounds %struct.in6_addr, %struct.in6_addr* %11, i32 0, i32 0
%13 = load i32*, i32** %12
%14 = getelementptr inbounds i32, i32* %13, i64 13
%15 = load i32, i32* %14
%16 = shl i32 %15, 16
%17 = add nsw i32 %10, %16
%18 = load %struct.in6_addr*, %struct.in6_addr** %3
%19 = getelementptr inbounds %struct.in6_addr, %struct.in6_addr* %18, i32 0, i32 0
%20 = load i32*, i32** %19
%21 = getelementptr inbounds i32, i32* %20, i64 14
%22 = load i32, i32* %21
%23 = shl i32 %22, 8
%24 = add nsw i32 %17, %23
%25 = load %struct.in6_addr*, %struct.in6_addr** %3
%26 = getelementptr inbounds %struct.in6_addr, %struct.in6_addr* %25, i32 0, i32 0
%27 = load i32*, i32** %26
%28 = getelementptr inbounds i32, i32* %27, i64 15
%29 = load i32, i32* %28
%30 = add nsw i32 %24, %29
%31 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %2, i32 0, i32 0
store i32 %30, i32* %31
%32 = bitcast %struct.in_addr* %2 to i64*
%33 = load i64, i64* %32
ret i64 %33
}

LLVM IR (-O2):
%struct.in6_addr = type { i32* }
define i64 @convert_ipv6_to_ipv4(%struct.in6_addr* nocapture %0) {
%2 = getelementptr inbounds %struct.in6_addr, %struct.in6_addr* %0, i64 0, i32 0
%3 = load i32*, i32** %2
%4 = getelementptr inbounds i32, i32* %3, i64 12
%5 = load i32, i32* %4
%6 = shl i32 %5, 24
%7 = getelementptr inbounds i32, i32* %3, i64 13
%8 = load i32, i32* %7
%9 = shl i32 %8, 16
%10 = add nsw i32 %9, %6
%11 = getelementptr inbounds i32, i32* %3, i64 14
%12 = load i32, i32* %11
%13 = shl i32 %12, 8
%14 = add nsw i32 %10, %13
%15 = getelementptr inbounds i32, i32* %3, i64 15
%16 = load i32, i32* %15
%17 = add nsw i32 %14, %16
%18 = zext i32 %17 to i64
ret i64 %18
}