#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*/ uint8_t;
struct sockaddr_storage {
  int ss_family;
};
struct TYPE_4__ {
  int /*<<< orphan*/ s6_addr;
};
struct sockaddr_in6 {
  TYPE_2__ sin6_addr;
};
struct TYPE_3__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  TYPE_1__ sin_addr;
};

/* Variables and functions */
#define AF_INET 129
#define AF_INET6 128
int /*<<< orphan*/ memcpy(int /*<<< orphan*/ *, int /*<<< orphan*/ *, int);
int lw_put_sockaddr(uint8_t *dst, struct sockaddr_storage *addr) {
  switch (addr->ss_family) {
  case AF_INET: {
    struct sockaddr_in *sain = (struct sockaddr_in *)addr;
    memcpy(dst, &sain->sin_addr.s_addr, sizeof(sain->sin_addr.s_addr));
    return sizeof(sain->sin_addr.s_addr);
  }
  case AF_INET6: {
    struct sockaddr_in6 *sain = (struct sockaddr_in6 *)addr;
    memcpy(dst, &sain->sin6_addr.s6_addr, sizeof(sain->sin6_addr.s6_addr));
    return sizeof(sain->sin6_addr.s6_addr);
  }
  }
  return 0;
}


x86 assembly (clang, -O0):
<lw_put_sockaddr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
sub    $0x80,%eax
je     1172 <lw_put_sockaddr+0x62>
jmp    1139 <lw_put_sockaddr+0x29>
mov    -0x2c(%rbp),%eax
sub    $0x81,%eax
jne    1198 <lw_put_sockaddr+0x88>
jmp    114c <lw_put_sockaddr+0x3c>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    $0x4,%edx
call   1030 <memcpy@plt>
movl   $0x4,-0x4(%rbp)
jmp    119f <lw_put_sockaddr+0x8f>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    $0x4,%edx
call   1030 <memcpy@plt>
movl   $0x4,-0x4(%rbp)
jmp    119f <lw_put_sockaddr+0x8f>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lw_put_sockaddr>:
push   %rbx
mov    (%rsi),%eax
and    $0xfffffffe,%eax
xor    %ebx,%ebx
cmp    $0x80,%eax
jne    112e <lw_put_sockaddr+0x1e>
mov    $0x4,%ebx
mov    $0x4,%edx
call   1030 <memcpy@plt>
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
%struct.sockaddr_storage = type { i32 }
%struct.sockaddr_in = type { %struct.TYPE_3__ }
%struct.TYPE_3__ = type { i32 }
%struct.sockaddr_in6 = type { %struct.TYPE_4__ }
%struct.TYPE_4__ = type { i32 }
define i32 @lw_put_sockaddr(i32* %0, %struct.sockaddr_storage* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca %struct.sockaddr_storage*
%6 = alloca %struct.sockaddr_in*
%7 = alloca %struct.sockaddr_in6*
store i32* %0, i32** %4
store %struct.sockaddr_storage* %1, %struct.sockaddr_storage** %5
%8 = load %struct.sockaddr_storage*, %struct.sockaddr_storage** %5
%9 = getelementptr inbounds %struct.sockaddr_storage, %struct.sockaddr_storage* %8, i32 0, i32 0
%10 = load i32, i32* %9
switch i32 %10, label %27 [
i32 129, label %11
i32 128, label %19
]
11: ; preds = %2
%12 = load %struct.sockaddr_storage*, %struct.sockaddr_storage** %5
%13 = bitcast %struct.sockaddr_storage* %12 to %struct.sockaddr_in*
store %struct.sockaddr_in* %13, %struct.sockaddr_in** %6
%14 = load i32*, i32** %4
%15 = load %struct.sockaddr_in*, %struct.sockaddr_in** %6
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %15, i32 0, i32 0
%17 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %16, i32 0, i32 0
%18 = call i32 @memcpy(i32* %14, i32* %17, i32 4)
store i32 4, i32* %3
br label %28
19: ; preds = %2
%20 = load %struct.sockaddr_storage*, %struct.sockaddr_storage** %5
%21 = bitcast %struct.sockaddr_storage* %20 to %struct.sockaddr_in6*
store %struct.sockaddr_in6* %21, %struct.sockaddr_in6** %7
%22 = load i32*, i32** %4
%23 = load %struct.sockaddr_in6*, %struct.sockaddr_in6** %7
%24 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %23, i32 0, i32 0
%25 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %24, i32 0, i32 0
%26 = call i32 @memcpy(i32* %22, i32* %25, i32 4)
store i32 4, i32* %3
br label %28
27: ; preds = %2
store i32 0, i32* %3
br label %28
28: ; preds = %27, %19, %11
%29 = load i32, i32* %3
ret i32 %29
}

LLVM IR (-O2):
%struct.sockaddr_storage = type { i32 }
define i32 @lw_put_sockaddr(i32* %0, %struct.sockaddr_storage* %1) {
%3 = getelementptr inbounds %struct.sockaddr_storage, %struct.sockaddr_storage* %1, i64 0, i32 0
%4 = load i32, i32* %3
%5 = and i32 %4, -2
%6 = icmp eq i32 %5, 128
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = tail call i32 @memcpy(i32* %0, i32* %3, i32 4)
br label %9
9: ; preds = %2, %7
%10 = phi i32 [ 0, %2 ], [ 4, %7 ]
ret i32 %10
}