#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 sockaddr_in {
  int /*<<< orphan*/ sin_addr;
};
struct ifreq {
  int /*<<< orphan*/ ifr_addr;
};
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ SIOCGIFDSTADDR;
int /*<<< orphan*/ bzero(char *, int);
struct ifreq *get_ifreq(char *, int /*<<< orphan*/);
int /*<<< orphan*/ inet_ntoa(int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(char *, int /*<<< orphan*/);
char *get_if_dstaddr(char *ifname) {
  static char buf[18];
  bzero(buf, sizeof(buf));
  struct ifreq *ifr = get_ifreq(ifname, SIOCGIFDSTADDR);
  strcpy(buf, inet_ntoa(((struct sockaddr_in *)&ifr->ifr_addr)->sin_addr));
  return buf;
}


x86 assembly (clang, -O0):
<get_if_dstaddr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
lea    0x2efd(%rip),%rdi
mov    $0x12,%esi
call   1050 <bzero@plt>
mov    -0x8(%rbp),%rdi
mov    0x2e88(%rip),%rax
mov    (%rax),%esi
call   1060 <get_ifreq@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
call   1040 <inet_ntoa@plt>
mov    %eax,%esi
lea    0x2ec9(%rip),%rdi
call   1030 <strcpy@plt>
lea    0x2ebd(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_if_dstaddr>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0x2f02(%rip),%r14
mov    %r14,%rdi
mov    $0x12,%esi
call   1050 <bzero@plt>
mov    0x2e8e(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1060 <get_ifreq@plt>
mov    (%rax),%edi
call   1040 <inet_ntoa@plt>
mov    %r14,%rdi
mov    %eax,%esi
call   1030 <strcpy@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.ifreq = type { i32 }
%struct.sockaddr_in = type { i32 }
@get_if_dstaddr.buf = internal global [18 x i8] zeroinitializer
@SIOCGIFDSTADDR = global i32 0
define i8* @get_if_dstaddr(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.ifreq*
store i8* %0, i8** %2
%4 = call i32 @bzero(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @get_if_dstaddr.buf, i64 0, i64 0), i32 18)
%5 = load i8*, i8** %2
%6 = load i32, i32* @SIOCGIFDSTADDR
%7 = call %struct.ifreq* @get_ifreq(i8* %5, i32 %6)
store %struct.ifreq* %7, %struct.ifreq** %3
%8 = load %struct.ifreq*, %struct.ifreq** %3
%9 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %8, i32 0, i32 0
%10 = bitcast i32* %9 to %struct.sockaddr_in*
%11 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 0
%12 = load i32, i32* %11
%13 = call i32 @inet_ntoa(i32 %12)
%14 = call i32 @strcpy(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @get_if_dstaddr.buf, i64 0, i64 0), i32 %13)
ret i8* getelementptr inbounds ([18 x i8], [18 x i8]* @get_if_dstaddr.buf, i64 0, i64 0)
}

LLVM IR (-O2):
%struct.ifreq = type { i32 }
@get_if_dstaddr.buf = internal global [18 x i8] zeroinitializer
@SIOCGIFDSTADDR = global i32 0
define i8* @get_if_dstaddr(i8* %0) {
%2 = tail call i32 @bzero(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @get_if_dstaddr.buf, i64 0, i64 0), i32 18)
%3 = load i32, i32* @SIOCGIFDSTADDR
%4 = tail call %struct.ifreq* @get_ifreq(i8* %0, i32 %3)
%5 = getelementptr %struct.ifreq, %struct.ifreq* %4, i64 0, i32 0
%6 = load i32, i32* %5
%7 = tail call i32 @inet_ntoa(i32 %6)
%8 = tail call i32 @strcpy(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @get_if_dstaddr.buf, i64 0, i64 0), i32 %7)
ret i8* getelementptr inbounds ([18 x i8], [18 x i8]* @get_if_dstaddr.buf, i64 0, i64 0)
}