#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 sockaddr_s {
  int dummy;
};
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
  TYPE_1__ sin_addr;
};

/* Variables and functions */
int ntohl(int /*<<< orphan*/);
int ntohs(int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, int, int, int, int, int);
char *WINS_AddrToString(struct sockaddr_s *addr) {
  static char buffer[22];
  int haddr;
  haddr = ntohl(((struct sockaddr_in *)addr)->sin_addr.s_addr);
  sprintf(buffer, "%d.%d.%d.%d:%d", (haddr >> 24) & 0xff, (haddr >> 16) & 0xff,
          (haddr >> 8) & 0xff, haddr & 0xff,
          ntohs(((struct sockaddr_in *)addr)->sin_port));
  return buffer;
}


x86 assembly (clang, -O0):
<WINS_AddrToString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%edi
call   1050 <ntohl@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
sar    $0x18,%eax
and    $0xff,%eax
mov    %eax,-0x1c(%rbp)
mov    -0xc(%rbp),%eax
sar    $0x10,%eax
and    $0xff,%eax
mov    %eax,-0x18(%rbp)
mov    -0xc(%rbp),%eax
sar    $0x8,%eax
and    $0xff,%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
and    $0xff,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
call   1030 <ntohs@plt>
mov    -0x1c(%rbp),%edx
mov    -0x18(%rbp),%ecx
mov    -0x14(%rbp),%r8d
mov    -0x10(%rbp),%r9d
lea    0x2eb0(%rip),%rdi
lea    0xe59(%rip),%rsi
mov    %eax,(%rsp)
call   1040 <sprintf@plt>
lea    0x2e9a(%rip),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<WINS_AddrToString>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
mov    0x4(%rdi),%edi
call   1050 <ntohl@plt>
mov    %eax,%ebx
mov    %eax,%ecx
movzbl %bh,%edx
mov    %edx,%r12d
movzbl %bl,%r15d
shr    $0x18,%ebx
shr    $0x10,%ecx
movzbl %cl,%ebp
mov    (%r14),%edi
call   1030 <ntohs@plt>
mov    %eax,(%rsp)
lea    0x2ee0(%rip),%r14
lea    0xe89(%rip),%rsi
mov    %ebx,%edx
mov    %r14,%rdi
mov    %ebp,%ecx
mov    %r12d,%r8d
mov    %r15d,%r9d
call   1040 <sprintf@plt>
mov    %r14,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_s = type { i32 }
%struct.sockaddr_in = type { i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
@WINS_AddrToString.buffer = internal global [22 x i8] zeroinitializer
@.str = [15 x i8] c"%d.%d.%d.%d:%d\00"
define i8* @WINS_AddrToString(%struct.sockaddr_s* %0) {
%2 = alloca %struct.sockaddr_s*
%3 = alloca i32
store %struct.sockaddr_s* %0, %struct.sockaddr_s** %2
%4 = load %struct.sockaddr_s*, %struct.sockaddr_s** %2
%5 = bitcast %struct.sockaddr_s* %4 to %struct.sockaddr_in*
%6 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 1
%7 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %6, i32 0, i32 0
%8 = load i32, i32* %7
%9 = call i32 @ntohl(i32 %8)
store i32 %9, i32* %3
%10 = load i32, i32* %3
%11 = ashr i32 %10, 24
%12 = and i32 %11, 255
%13 = load i32, i32* %3
%14 = ashr i32 %13, 16
%15 = and i32 %14, 255
%16 = load i32, i32* %3
%17 = ashr i32 %16, 8
%18 = and i32 %17, 255
%19 = load i32, i32* %3
%20 = and i32 %19, 255
%21 = load %struct.sockaddr_s*, %struct.sockaddr_s** %2
%22 = bitcast %struct.sockaddr_s* %21 to %struct.sockaddr_in*
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %22, i32 0, i32 0
%24 = load i32, i32* %23
%25 = call i32 @ntohs(i32 %24)
%26 = call i32 @sprintf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @WINS_AddrToString.buffer, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %12, i32 %15, i32 %18, i32 %20, i32 %25)
ret i8* getelementptr inbounds ([22 x i8], [22 x i8]* @WINS_AddrToString.buffer, i64 0, i64 0)
}

LLVM IR (-O2):
%struct.sockaddr_s = type { i32 }
@WINS_AddrToString.buffer = internal global [22 x i8] zeroinitializer
@.str = [15 x i8] c"%d.%d.%d.%d:%d\00"
define i8* @WINS_AddrToString(%struct.sockaddr_s* nocapture %0) {
%2 = getelementptr inbounds %struct.sockaddr_s, %struct.sockaddr_s* %0, i64 1, i32 0
%3 = load i32, i32* %2
%4 = tail call i32 @ntohl(i32 %3)
%5 = lshr i32 %4, 24
%6 = lshr i32 %4, 16
%7 = and i32 %6, 255
%8 = lshr i32 %4, 8
%9 = and i32 %8, 255
%10 = and i32 %4, 255
%11 = getelementptr %struct.sockaddr_s, %struct.sockaddr_s* %0, i64 0, i32 0
%12 = load i32, i32* %11
%13 = tail call i32 @ntohs(i32 %12)
%14 = tail call i32 @sprintf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @WINS_AddrToString.buffer, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %5, i32 %7, i32 %9, i32 %10, i32 %13)
ret i8* getelementptr inbounds ([22 x i8], [22 x i8]* @WINS_AddrToString.buffer, i64 0, i64 0)
}