#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 in6_addr {
  int dummy;
};
struct sockaddr_in6 {
  struct in6_addr sin6_addr;
};
struct in_addr {
  int dummy;
};
struct sockaddr_in {
  struct in_addr sin_addr;
};
struct sockaddr {
  int sa_family;
};
struct nlmsghdr {
  int dummy;
};

/* Variables and functions */
#define AF_INET 129
#define AF_INET6 128
void *rta_put(struct nlmsghdr *, int, int);
__attribute__((visibility("hidden"))) int
rta_put_address(struct nlmsghdr *msg, int type, struct sockaddr *adr) {
  switch (adr->sa_family) {
  case AF_INET: {
    struct in_addr *i = rta_put(msg, type, 4);
    *i = ((struct sockaddr_in *)adr)->sin_addr;
    break;
  }
  case AF_INET6: {
    struct in6_addr *i6 = rta_put(msg, type, 16);
    *i6 = ((struct sockaddr_in6 *)adr)->sin6_addr;
    break;
  }
  default:
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<rta_put_address>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
sub    $0x80,%eax
je     1175 <rta_put_address+0x65>
jmp    113c <rta_put_address+0x2c>
mov    -0x34(%rbp),%eax
sub    $0x81,%eax
jne    119b <rta_put_address+0x8b>
jmp    114f <rta_put_address+0x3f>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    $0x4,%edx
call   1030 <rta_put@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rcx),%ecx
mov    %ecx,(%rax)
jmp    11a7 <rta_put_address+0x97>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    $0x10,%edx
call   1030 <rta_put@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rcx),%ecx
mov    %ecx,(%rax)
jmp    11a7 <rta_put_address+0x97>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ae <rta_put_address+0x9e>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rta_put_address>:
push   %rbx
mov    %rdx,%rbx
mov    (%rdx),%ecx
cmp    $0x81,%ecx
je     1132 <rta_put_address+0x22>
mov    $0xffffffff,%eax
cmp    $0x80,%ecx
jne    1142 <rta_put_address+0x32>
mov    $0x10,%edx
jmp    1137 <rta_put_address+0x27>
mov    $0x4,%edx
call   1030 <rta_put@plt>
mov    (%rbx),%ecx
mov    %ecx,(%rax)
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
%struct.nlmsghdr = type { i32 }
%struct.sockaddr = type { i32 }
%struct.in_addr = type { i32 }
%struct.in6_addr = type { i32 }
%struct.sockaddr_in = type { %struct.in_addr }
%struct.sockaddr_in6 = type { %struct.in6_addr }
define hidden i32 @rta_put_address(%struct.nlmsghdr* %0, i32 %1, %struct.sockaddr* %2) {
%4 = alloca i32
%5 = alloca %struct.nlmsghdr*
%6 = alloca i32
%7 = alloca %struct.sockaddr*
%8 = alloca %struct.in_addr*
%9 = alloca %struct.in6_addr*
store %struct.nlmsghdr* %0, %struct.nlmsghdr** %5
store i32 %1, i32* %6
store %struct.sockaddr* %2, %struct.sockaddr** %7
%10 = load %struct.sockaddr*, %struct.sockaddr** %7
%11 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %10, i32 0, i32 0
%12 = load i32, i32* %11
switch i32 %12, label %35 [
i32 129, label %13
i32 128, label %24
]
13: ; preds = %3
%14 = load %struct.nlmsghdr*, %struct.nlmsghdr** %5
%15 = load i32, i32* %6
%16 = call i8* @rta_put(%struct.nlmsghdr* %14, i32 %15, i32 4)
%17 = bitcast i8* %16 to %struct.in_addr*
store %struct.in_addr* %17, %struct.in_addr** %8
%18 = load %struct.in_addr*, %struct.in_addr** %8
%19 = load %struct.sockaddr*, %struct.sockaddr** %7
%20 = bitcast %struct.sockaddr* %19 to %struct.sockaddr_in*
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %20, i32 0, i32 0
%22 = bitcast %struct.in_addr* %18 to i8*
%23 = bitcast %struct.in_addr* %21 to i8*
br label %36
24: ; preds = %3
%25 = load %struct.nlmsghdr*, %struct.nlmsghdr** %5
%26 = load i32, i32* %6
%27 = call i8* @rta_put(%struct.nlmsghdr* %25, i32 %26, i32 16)
%28 = bitcast i8* %27 to %struct.in6_addr*
store %struct.in6_addr* %28, %struct.in6_addr** %9
%29 = load %struct.in6_addr*, %struct.in6_addr** %9
%30 = load %struct.sockaddr*, %struct.sockaddr** %7
%31 = bitcast %struct.sockaddr* %30 to %struct.sockaddr_in6*
%32 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %31, i32 0, i32 0
%33 = bitcast %struct.in6_addr* %29 to i8*
%34 = bitcast %struct.in6_addr* %32 to i8*
br label %36
35: ; preds = %3
store i32 -1, i32* %4
br label %37
36: ; preds = %24, %13
store i32 0, i32* %4
br label %37
37: ; preds = %36, %35
%38 = load i32, i32* %4
ret i32 %38
}

LLVM IR (-O2):
%struct.nlmsghdr = type { i32 }
%struct.sockaddr = type { i32 }
define hidden i32 @rta_put_address(%struct.nlmsghdr* %0, i32 %1, %struct.sockaddr* nocapture %2) {
%4 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %2, i64 0, i32 0
%5 = load i32, i32* %4
switch i32 %5, label %12 [
i32 129, label %7
i32 128, label %6
]
6: ; preds = %3
br label %7
7: ; preds = %3, %6
%8 = phi i32 [ 16, %6 ], [ 4, %3 ]
%9 = tail call i8* @rta_put(%struct.nlmsghdr* %0, i32 %1, i32 %8)
%10 = bitcast i8* %9 to i32*
%11 = load i32, i32* %4
store i32 %11, i32* %10
br label %12
12: ; preds = %7, %3
%13 = phi i32 [ -1, %3 ], [ 0, %7 ]
ret i32 %13
}