#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 */

/* Type definitions */
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_addr;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ client_addr;

/* Variables and functions */
int accept(int, struct sockaddr *, int *);
char *inet_ntoa(int /*<<< orphan*/);
int ntohs(int /*<<< orphan*/);
int my_accept(int socket, char **addr, int *port) {
  struct sockaddr_in client_addr;
  int addrlen = sizeof(client_addr);
  int clientfd = accept(socket, (struct sockaddr *)&client_addr, &addrlen);
  *addr = inet_ntoa(client_addr.sin_addr);
  *port = ntohs(client_addr.sin_port);
  return clientfd;
}


x86 assembly (clang, -O0):
<my_accept>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x8,-0x24(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x20(%rbp),%rsi
lea    -0x24(%rbp),%rdx
call   1050 <accept@plt>
mov    %eax,-0x28(%rbp)
mov    -0x1c(%rbp),%edi
call   1030 <inet_ntoa@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%edi
call   1040 <ntohs@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_accept>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r14
mov    %rsi,%rbx
movl   $0x8,0x4(%rsp)
lea    0x8(%rsp),%rsi
lea    0x4(%rsp),%rdx
call   1050 <accept@plt>
mov    %eax,%ebp
mov    0xc(%rsp),%edi
call   1030 <inet_ntoa@plt>
mov    %rax,(%rbx)
mov    0x8(%rsp),%edi
call   1040 <ntohs@plt>
mov    %eax,(%r14)
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32 }
%struct.sockaddr = type { i32 }
define i32 @my_accept(i32 %0, i8** %1, i32* %2) {
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca %struct.sockaddr_in
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32* %2, i32** %6
store i32 8, i32* %8
%10 = load i32, i32* %4
%11 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%12 = call i32 @accept(i32 %10, %struct.sockaddr* %11, i32* %8)
store i32 %12, i32* %9
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
%14 = load i32, i32* %13
%15 = call i8* @inet_ntoa(i32 %14)
%16 = load i8**, i8*** %5
store i8* %15, i8** %16
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
%18 = load i32, i32* %17
%19 = call i32 @ntohs(i32 %18)
%20 = load i32*, i32** %6
store i32 %19, i32* %20
%21 = load i32, i32* %9
ret i32 %21
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32 }
%struct.sockaddr = type { i32 }
define i32 @my_accept(i32 %0, i8** nocapture writeonly %1, i32* nocapture writeonly %2) {
%4 = alloca %struct.sockaddr_in
%5 = alloca i32
%6 = bitcast %struct.sockaddr_in* %4 to i8*
%7 = bitcast i32* %5 to i8*
store i32 8, i32* %5
%8 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%9 = call i32 @accept(i32 %0, %struct.sockaddr* %8, i32* %5)
%10 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1
%11 = load i32, i32* %10
%12 = call i8* @inet_ntoa(i32 %11)
store i8* %12, i8** %1
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
%14 = load i32, i32* %13
%15 = call i32 @ntohs(i32 %14)
store i32 %15, i32* %2
ret i32 %9
}