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

/* Type definitions */
struct TYPE_2__ {
  int s_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
  TYPE_1__ sin_addr;
};
struct sockaddr {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ inet_ntop(int /*<<< orphan*/, int *, char *, int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ my_itoa(int, char *, int);
scalar_t__ ntohs(int /*<<< orphan*/);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strlen(char *);
void serialize_sockaddr(struct sockaddr *address, char *result_buf) {
  char buf[20] = "";
  struct sockaddr_in *tmp_addr = (struct sockaddr_in *)address;
  char tmp_ip[20];
  int ipAddr = tmp_addr->sin_addr.s_addr;
  memset(buf, 0, strlen(buf));
  inet_ntop(AF_INET, &ipAddr, tmp_ip, 20);
  strcat(result_buf, tmp_ip);
  strcat(result_buf, ",");
  memset(buf, 0, strlen(buf));
  my_itoa((int)ntohs(tmp_addr->sin_port), buf, 10);
  strcat(result_buf, buf);
}


x86 assembly (clang, -O0):
<serialize_sockaddr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1060 <memset@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    0x4(%rax),%eax
mov    %eax,-0x54(%rbp)
lea    -0x30(%rbp),%rax
mov    %rax,-0x68(%rbp)
lea    -0x30(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x68(%rbp),%rdi
mov    %eax,%edx
xor    %esi,%esi
call   1060 <memset@plt>
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
lea    -0x50(%rbp),%rdx
lea    -0x54(%rbp),%rsi
mov    $0x14,%ecx
call   1030 <inet_ntop@plt>
mov    -0x10(%rbp),%rdi
lea    -0x50(%rbp),%rsi
call   1080 <strcat@plt>
mov    -0x10(%rbp),%rdi
lea    0xe1d(%rip),%rsi
call   1080 <strcat@plt>
lea    -0x30(%rbp),%rax
mov    %rax,-0x60(%rbp)
lea    -0x30(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x60(%rbp),%rdi
mov    %eax,%edx
xor    %esi,%esi
call   1060 <memset@plt>
mov    -0x38(%rbp),%rax
mov    (%rax),%edi
call   1070 <ntohs@plt>
mov    %eax,%edi
lea    -0x30(%rbp),%rsi
mov    $0xa,%edx
call   1040 <my_itoa@plt>
mov    -0x10(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1080 <strcat@plt>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<serialize_sockaddr>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rsi,%r12
mov    %rdi,%r15
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
movl   $0x0,0x20(%rsp)
mov    0x4(%rdi),%eax
mov    %eax,0xc(%rsp)
lea    0x10(%rsp),%r14
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %r14,%rdi
xor    %esi,%esi
mov    %eax,%edx
call   1060 <memset@plt>
mov    0x2e40(%rip),%rax
mov    (%rax),%edi
lea    0xc(%rsp),%rsi
lea    0x30(%rsp),%rbx
mov    %rbx,%rdx
mov    $0x14,%ecx
call   1030 <inet_ntop@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1080 <strcat@plt>
lea    0xe2d(%rip),%rsi
mov    %r12,%rdi
call   1080 <strcat@plt>
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %r14,%rdi
xor    %esi,%esi
mov    %eax,%edx
call   1060 <memset@plt>
mov    (%r15),%edi
call   1070 <ntohs@plt>
mov    %eax,%edi
mov    %r14,%rsi
mov    $0xa,%edx
call   1040 <my_itoa@plt>
mov    %r12,%rdi
mov    %r14,%rsi
call   1080 <strcat@plt>
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.sockaddr = type { i32 }
%struct.sockaddr_in = type { i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
@AF_INET = global i32 0
@.str = [2 x i8] c",\00"
define void @serialize_sockaddr(%struct.sockaddr* %0, i8* %1) {
%3 = alloca %struct.sockaddr*
%4 = alloca i8*
%5 = alloca [20 x i8]
%6 = alloca %struct.sockaddr_in*
%7 = alloca [20 x i8]
%8 = alloca i32
store %struct.sockaddr* %0, %struct.sockaddr** %3
store i8* %1, i8** %4
%9 = bitcast [20 x i8]* %5 to i8*
%10 = load %struct.sockaddr*, %struct.sockaddr** %3
%11 = bitcast %struct.sockaddr* %10 to %struct.sockaddr_in*
store %struct.sockaddr_in* %11, %struct.sockaddr_in** %6
%12 = load %struct.sockaddr_in*, %struct.sockaddr_in** %6
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 1
%14 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %13, i32 0, i32 0
%15 = load i32, i32* %14
store i32 %15, i32* %8
%16 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%17 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%18 = call i32 @strlen(i8* %17)
%19 = call i32 @memset(i8* %16, i32 0, i32 %18)
%20 = load i32, i32* @AF_INET
%21 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%22 = call i32 @inet_ntop(i32 %20, i32* %8, i8* %21, i32 20)
%23 = load i8*, i8** %4
%24 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%25 = call i32 @strcat(i8* %23, i8* %24)
%26 = load i8*, i8** %4
%27 = call i32 @strcat(i8* %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%28 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%29 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%30 = call i32 @strlen(i8* %29)
%31 = call i32 @memset(i8* %28, i32 0, i32 %30)
%32 = load %struct.sockaddr_in*, %struct.sockaddr_in** %6
%33 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %32, i32 0, i32 0
%34 = load i32, i32* %33
%35 = call i64 @ntohs(i32 %34)
%36 = trunc i64 %35 to i32
%37 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%38 = call i32 @my_itoa(i32 %36, i8* %37, i32 10)
%39 = load i8*, i8** %4
%40 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%41 = call i32 @strcat(i8* %39, i8* %40)
ret void
}

LLVM IR (-O2):
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@.str = [2 x i8] c",\00"
define void @serialize_sockaddr(%struct.sockaddr* nocapture %0, i8* %1) {
%3 = alloca [20 x i8]
%4 = alloca [20 x i8]
%5 = alloca i32
%6 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%8 = bitcast i32* %5 to i8*
%9 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %0, i64 1, i32 0
%10 = load i32, i32* %9
store i32 %10, i32* %5
%11 = call i32 @strlen(i8* %6)
%12 = call i32 @memset(i8* %6, i32 0, i32 %11)
%13 = load i32, i32* @AF_INET
%14 = call i32 @inet_ntop(i32 %13, i32* %5, i8* %7, i32 20)
%15 = call i32 @strcat(i8* %1, i8* %7)
%16 = call i32 @strcat(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%17 = call i32 @strlen(i8* %6)
%18 = call i32 @memset(i8* %6, i32 0, i32 %17)
%19 = getelementptr %struct.sockaddr, %struct.sockaddr* %0, i64 0, i32 0
%20 = load i32, i32* %19
%21 = call i64 @ntohs(i32 %20)
%22 = trunc i64 %21 to i32
%23 = call i32 @my_itoa(i32 %22, i8* %6, i32 10)
%24 = call i32 @strcat(i8* %1, i8* %6)
ret void
}