#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 {
  int /*<<< orphan*/ sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ sin;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ getpeername(int, struct sockaddr *, int *);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ memset(void *, int /*<<< orphan*/, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ start_server();
int execute_getpeername() {
  start_server();
  int sfd = socket(AF_INET, SOCK_STREAM, 0);
  struct sockaddr_in sin;
  memset((void *)&sin, 0, sizeof(sin));
  sin.sin_family = AF_INET;
  sin.sin_addr.s_addr = htonl(INADDR_ANY);
  sin.sin_port = htons(25588);
  socklen_t sin_len = sizeof(struct sockaddr);
  connect(sfd, (struct sockaddr *)&sin, sin_len);
  socklen_t len = sizeof(struct sockaddr);
  struct sockaddr_in sock;
  getpeername(sfd, (struct sockaddr *)&sock, &len);
  return 0;
}


x86 assembly (clang, -O0):
<execute_getpeername>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    $0x0,%al
call   1080 <start_server@plt>
mov    0x2e62(%rip),%rax
mov    (%rax),%edi
mov    0x2e41(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1090 <socket@plt>
mov    %eax,-0x4(%rbp)
lea    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1060 <memset@plt>
mov    0x2e36(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
mov    0x2e22(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %eax,-0xc(%rbp)
mov    $0x63f4,%edi
call   1040 <htons@plt>
mov    %eax,-0x10(%rbp)
movl   $0x4,-0x14(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1070 <connect@plt>
movl   $0x4,-0x18(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x28(%rbp),%rsi
lea    -0x18(%rbp),%rdx
call   1030 <getpeername@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<execute_getpeername>:
push   %r15
push   %r14
push   %rbx
sub    $0x30,%rsp
xor    %eax,%eax
call   1080 <start_server@plt>
mov    0x2e61(%rip),%r15
mov    (%r15),%edi
mov    0x2e3f(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1090 <socket@plt>
mov    %eax,%ebx
lea    0x10(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1060 <memset@plt>
mov    (%r15),%eax
mov    %eax,0x18(%rsp)
mov    0x2e22(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %eax,0x14(%rsp)
mov    $0x63f4,%edi
call   1040 <htons@plt>
mov    %eax,0x10(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x4,%edx
call   1070 <connect@plt>
movl   $0x4,0xc(%rsp)
lea    0x20(%rsp),%rsi
lea    0xc(%rsp),%rdx
mov    %ebx,%edi
call   1030 <getpeername@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@INADDR_ANY = global i32 0
define i32 @execute_getpeername() {
%1 = alloca i32
%2 = alloca %struct.sockaddr_in
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.sockaddr_in
%6 = call i32 (...) @start_server()
%7 = load i32, i32* @AF_INET
%8 = load i32, i32* @SOCK_STREAM
%9 = call i32 @socket(i32 %7, i32 %8, i32 0)
store i32 %9, i32* %1
%10 = bitcast %struct.sockaddr_in* %2 to i8*
%11 = call i32 @memset(i8* %10, i32 0, i32 12)
%12 = load i32, i32* @AF_INET
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i32 0, i32 2
store i32 %12, i32* %13
%14 = load i32, i32* @INADDR_ANY
%15 = call i32 @htonl(i32 %14)
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i32 0, i32 1
%17 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %16, i32 0, i32 0
store i32 %15, i32* %17
%18 = call i32 @htons(i32 25588)
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i32 0, i32 0
store i32 %18, i32* %19
store i32 4, i32* %3
%20 = load i32, i32* %1
%21 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%22 = load i32, i32* %3
%23 = call i32 @connect(i32 %20, %struct.sockaddr* %21, i32 %22)
store i32 4, i32* %4
%24 = load i32, i32* %1
%25 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%26 = call i32 @getpeername(i32 %24, %struct.sockaddr* %25, i32* %4)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@INADDR_ANY = global i32 0
define i32 @execute_getpeername() {
%1 = alloca %struct.sockaddr_in
%2 = alloca i32
%3 = alloca %struct.sockaddr_in
%4 = tail call i32 (...) @start_server()
%5 = load i32, i32* @AF_INET
%6 = load i32, i32* @SOCK_STREAM
%7 = tail call i32 @socket(i32 %5, i32 %6, i32 0)
%8 = bitcast %struct.sockaddr_in* %1 to i8*
%9 = call i32 @memset(i8* %8, i32 0, i32 12)
%10 = load i32, i32* @AF_INET
%11 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i32 %10, i32* %11
%12 = load i32, i32* @INADDR_ANY
%13 = call i32 @htonl(i32 %12)
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1, i32 0
store i32 %13, i32* %14
%15 = call i32 @htons(i32 25588)
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0
store i32 %15, i32* %16
%17 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%18 = call i32 @connect(i32 %7, %struct.sockaddr* %17, i32 4)
%19 = bitcast i32* %2 to i8*
store i32 4, i32* %2
%20 = bitcast %struct.sockaddr_in* %3 to i8*
%21 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%22 = call i32 @getpeername(i32 %7, %struct.sockaddr* %21, i32* %2)
ret i32 0
}