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

/* Variables and functions */
int ntohl(int /*<<< orphan*/);
int ntohs(int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, int, int, int, int, int);
const char *displayAddr(struct sockaddr *saddr) {
  static char strAddr[128];
  struct sockaddr_in *in = (struct sockaddr_in *)saddr;
  int port = ntohs(in->sin_port);
  int addr = ntohl(in->sin_addr.s_addr);
  sprintf(strAddr, "%d.%d.%d.%d:%d", (addr & 0xff000000) >> 24,
          (addr & 0x00ff0000) >> 16, (addr & 0x0000ff00) >> 8,
          (addr & 0x000000ff), port);
  return strAddr;
}


x86 assembly (clang, -O0):
<displayAddr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%edi
call   1030 <ntohs@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
call   1050 <ntohl@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edx
and    $0xff000000,%edx
shr    $0x18,%edx
mov    -0x18(%rbp),%ecx
and    $0xff0000,%ecx
sar    $0x10,%ecx
mov    -0x18(%rbp),%r8d
and    $0xff00,%r8d
sar    $0x8,%r8d
mov    -0x18(%rbp),%r9d
and    $0xff,%r9d
mov    -0x14(%rbp),%eax
lea    0x2eb3(%rip),%rdi
lea    0xe5c(%rip),%rsi
mov    %eax,(%rsp)
call   1040 <sprintf@plt>
lea    0x2e9d(%rip),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<displayAddr>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    0x4(%rdi),%edi
call   1030 <ntohs@plt>
mov    %eax,%ebp
mov    (%rbx),%edi
call   1050 <ntohl@plt>
mov    %eax,%ecx
movzbl %ah,%ebx
movzbl %al,%r9d
mov    %eax,%edx
shr    $0x18,%edx
shr    $0x10,%ecx
movzbl %cl,%ecx
mov    %ebp,(%rsp)
lea    0x2eeb(%rip),%rbp
lea    0xe94(%rip),%rsi
mov    %rbp,%rdi
mov    %ebx,%r8d
call   1040 <sprintf@plt>
mov    %rbp,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

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