#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_3__ TYPE_1__;

/* Type definitions */
struct TYPE_3__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  void *sin_port;
  TYPE_1__ sin_addr;
  void *sin_family;
};
typedef int /*<<< orphan*/ addr2;
typedef int /*<<< orphan*/ addr1;

/* Variables and functions */
void *AF_INET;
void *htons(int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ inet_aton(char *, TYPE_1__ *);
char *inet_ntoa(TYPE_1__);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int ntohs(void *);
int /*<<< orphan*/ printf(char *, char *, int);
void old_address() {
  struct sockaddr_in addr1, addr2;
  memset(&addr1, 0, sizeof(addr1));
  addr1.sin_family = AF_INET;
  addr1.sin_port = htons(13);
  addr1.sin_addr.s_addr = inet_addr("127.0.0.1");
  printf("addr1 ip:%s, port:%u\n", inet_ntoa(addr1.sin_addr),
         ntohs(addr1.sin_port));
  memset(&addr2, 0, sizeof(addr2));
  addr2.sin_family = AF_INET;
  addr2.sin_port = htons(13);
  inet_aton("127.0.0.1", &addr2.sin_addr);
  printf("add2 ip:%s, port:%u\n", inet_ntoa(addr2.sin_addr),
         ntohs(addr2.sin_port));
}


x86 assembly (clang, -O0):
<old_address>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1060 <memset@plt>
mov    0x2e59(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x8(%rbp)
mov    $0xd,%edi
call   1040 <htons@plt>
mov    %rax,-0x18(%rbp)
lea    0xe55(%rip),%rdi
call   1070 <inet_addr@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%edi
call   1030 <inet_ntoa@plt>
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rdi
call   1090 <ntohs@plt>
mov    -0x40(%rbp),%rsi
mov    %eax,%edx
lea    0xe35(%rip),%rdi
call   1050 <printf@plt>
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1060 <memset@plt>
mov    0x2df7(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    $0xd,%edi
call   1040 <htons@plt>
mov    %rax,-0x30(%rbp)
lea    -0x30(%rbp),%rsi
add    $0x8,%rsi
lea    0xdeb(%rip),%rdi
call   1080 <inet_aton@plt>
mov    -0x28(%rbp),%edi
call   1030 <inet_ntoa@plt>
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rdi
call   1090 <ntohs@plt>
mov    -0x38(%rbp),%rsi
mov    %eax,%edx
lea    0xde4(%rip),%rdi
call   1050 <printf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<old_address>:
push   %r15
push   %r14
push   %rbx
sub    $0x30,%rsp
lea    0x18(%rsp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1060 <memset@plt>
mov    0x2e57(%rip),%r15
mov    (%r15),%rax
mov    %rax,0x28(%rsp)
mov    $0xd,%edi
call   1040 <htons@plt>
mov    %rax,0x18(%rsp)
lea    0xe51(%rip),%r14
mov    %r14,%rdi
call   1070 <inet_addr@plt>
mov    %eax,0x20(%rsp)
mov    %eax,%edi
call   1030 <inet_ntoa@plt>
mov    %rax,%rbx
mov    0x18(%rsp),%rdi
call   1090 <ntohs@plt>
lea    0xe34(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1050 <printf@plt>
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1060 <memset@plt>
mov    (%r15),%rax
mov    %rax,0x10(%rsp)
mov    $0xd,%edi
call   1040 <htons@plt>
mov    %rax,(%rsp)
lea    0x8(%rsp),%rsi
mov    %r14,%rdi
call   1080 <inet_aton@plt>
mov    0x8(%rsp),%edi
call   1030 <inet_ntoa@plt>
mov    %rax,%rbx
mov    (%rsp),%rdi
call   1090 <ntohs@plt>
lea    0xdf2(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1050 <printf@plt>
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i8*, %struct.TYPE_3__, i8* }
%struct.TYPE_3__ = type { i32 }
@AF_INET = global i8* null
@.str = [10 x i8] c"127.0.0.1\00"
@.str.1 = [22 x i8] c"addr1 ip:%s, port:%u\0A\00"
@.str.2 = [21 x i8] c"add2 ip:%s, port:%u\0A\00"
define void @old_address() {
%1 = alloca %struct.sockaddr_in
%2 = alloca %struct.sockaddr_in
%3 = call i32 @memset(%struct.sockaddr_in* %1, i32 0, i32 24)
%4 = load i8*, i8** @AF_INET
%5 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i32 0, i32 2
store i8* %4, i8** %5
%6 = call i8* @htons(i32 13)
%7 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i32 0, i32 0
store i8* %6, i8** %7
%8 = call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%9 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i32 0, i32 1
%10 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %9, i32 0, i32 0
store i32 %8, i32* %10
%11 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i32 0, i32 1
%12 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %11, i32 0, i32 0
%13 = load i32, i32* %12
%14 = call i8* @inet_ntoa(i32 %13)
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i32 0, i32 0
%16 = load i8*, i8** %15
%17 = call i32 @ntohs(i8* %16)
%18 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %14, i32 %17)
%19 = call i32 @memset(%struct.sockaddr_in* %2, i32 0, i32 24)
%20 = load i8*, i8** @AF_INET
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i32 0, i32 2
store i8* %20, i8** %21
%22 = call i8* @htons(i32 13)
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i32 0, i32 0
store i8* %22, i8** %23
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i32 0, i32 1
%25 = call i32 @inet_aton(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), %struct.TYPE_3__* %24)
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i32 0, i32 1
%27 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %26, i32 0, i32 0
%28 = load i32, i32* %27
%29 = call i8* @inet_ntoa(i32 %28)
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i32 0, i32 0
%31 = load i8*, i8** %30
%32 = call i32 @ntohs(i8* %31)
%33 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %29, i32 %32)
ret void
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i8*, %struct.TYPE_3__, i8* }
%struct.TYPE_3__ = type { i32 }
@AF_INET = global i8* null
@.str = [10 x i8] c"127.0.0.1\00"
@.str.1 = [22 x i8] c"addr1 ip:%s, port:%u\0A\00"
@.str.2 = [21 x i8] c"add2 ip:%s, port:%u\0A\00"
define void @old_address() {
%1 = alloca %struct.sockaddr_in
%2 = alloca %struct.sockaddr_in
%3 = bitcast %struct.sockaddr_in* %1 to i8*
%4 = bitcast %struct.sockaddr_in* %2 to i8*
%5 = call i32 @memset(%struct.sockaddr_in* %1, i32 0, i32 24)
%6 = load i8*, i8** @AF_INET
%7 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i8* %6, i8** %7
%8 = call i8* @htons(i32 13)
%9 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0
store i8* %8, i8** %9
%10 = call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%11 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1, i32 0
store i32 %10, i32* %11
%12 = call i8* @inet_ntoa(i32 %10)
%13 = load i8*, i8** %9
%14 = call i32 @ntohs(i8* %13)
%15 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %12, i32 %14)
%16 = call i32 @memset(%struct.sockaddr_in* %2, i32 0, i32 24)
%17 = load i8*, i8** @AF_INET
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 2
store i8* %17, i8** %18
%19 = call i8* @htons(i32 13)
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 0
store i8* %19, i8** %20
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 1
%22 = call i32 @inet_aton(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), %struct.TYPE_3__* %21)
%23 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %21, i64 0, i32 0
%24 = load i32, i32* %23
%25 = call i8* @inet_ntoa(i32 %24)
%26 = load i8*, i8** %20
%27 = call i32 @ntohs(i8* %26)
%28 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %25, i32 %27)
ret void
}