#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 socklen_t;
typedef int /*<<< orphan*/ client_addr;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int accept(int, struct sockaddr *, int *);
int /*<<< orphan*/ inet_ntop(int /*<<< orphan*/, int /*<<< orphan*/ *, char *,
                             int);
unsigned short ntohs(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *, unsigned short);
int server_accept(int fd) {
  char buf[1024] = {0};
  int ret;
  unsigned short port;
  struct sockaddr_in client_addr;
  socklen_t addrlen = sizeof(client_addr);
  ret = accept(fd, (struct sockaddr *)&client_addr, &addrlen);
  inet_ntop(AF_INET, &client_addr.sin_addr, buf, sizeof(buf));
  port = ntohs(client_addr.sin_port);
  printf("New connect frome IP:%s Port:%d\n", buf, port);
  return ret;
}


x86 assembly (clang, -O0):
<server_accept>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x410(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1050 <memset@plt>
movl   $0x8,-0x424(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x420(%rbp),%rsi
lea    -0x424(%rbp),%rdx
call   1070 <accept@plt>
mov    %eax,-0x414(%rbp)
mov    0x2e4a(%rip),%rax
mov    (%rax),%edi
lea    -0x420(%rbp),%rsi
add    $0x4,%rsi
lea    -0x410(%rbp),%rdx
mov    $0x400,%ecx
call   1030 <inet_ntop@plt>
mov    -0x420(%rbp),%edi
call   1060 <ntohs@plt>
mov    %ax,-0x416(%rbp)
lea    -0x410(%rbp),%rsi
lea    0xe24(%rip),%rdi
movzwl -0x416(%rbp),%edx
call   1040 <printf@plt>
mov    -0x414(%rbp),%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<server_accept>:
push   %rbp
push   %rbx
sub    $0x418,%rsp
mov    %edi,%ebp
lea    0x10(%rsp),%rbx
mov    $0x400,%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1050 <memset@plt>
movl   $0x8,0x4(%rsp)
lea    0x8(%rsp),%rsi
lea    0x4(%rsp),%rdx
mov    %ebp,%edi
call   1070 <accept@plt>
mov    %eax,%ebp
mov    0x2e57(%rip),%rax
mov    (%rax),%edi
lea    0xc(%rsp),%rsi
mov    %rbx,%rdx
mov    $0x400,%ecx
call   1030 <inet_ntop@plt>
mov    0x8(%rsp),%edi
call   1060 <ntohs@plt>
movzwl %ax,%edx
lea    0xe48(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
mov    %ebp,%eax
add    $0x418,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@.str = [33 x i8] c"New connect frome IP:%s Port:%d\0A\00"
define i32 @server_accept(i32 %0) {
%2 = alloca i32
%3 = alloca [1024 x i8]
%4 = alloca i32
%5 = alloca i16
%6 = alloca %struct.sockaddr_in
%7 = alloca i32
store i32 %0, i32* %2
%8 = bitcast [1024 x i8]* %3 to i8*
store i32 8, i32* %7
%9 = load i32, i32* %2
%10 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%11 = call i32 @accept(i32 %9, %struct.sockaddr* %10, i32* %7)
store i32 %11, i32* %4
%12 = load i32, i32* @AF_INET
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 1
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%15 = call i32 @inet_ntop(i32 %12, i32* %13, i8* %14, i32 1024)
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
%17 = load i32, i32* %16
%18 = call zeroext i16 @ntohs(i32 %17)
store i16 %18, i16* %5
%19 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%20 = load i16, i16* %5
%21 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %19, i16 zeroext %20)
%22 = load i32, i32* %4
ret i32 %22
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@.str = [33 x i8] c"New connect frome IP:%s Port:%d\0A\00"
define i32 @server_accept(i32 %0) {
%2 = alloca [1024 x i8]
%3 = alloca %struct.sockaddr_in
%4 = alloca i32
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%6 = bitcast %struct.sockaddr_in* %3 to i8*
%7 = bitcast i32* %4 to i8*
store i32 8, i32* %4
%8 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%9 = call i32 @accept(i32 %0, %struct.sockaddr* %8, i32* %4)
%10 = load i32, i32* @AF_INET
%11 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
%12 = call i32 @inet_ntop(i32 %10, i32* %11, i8* %5, i32 1024)
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
%14 = load i32, i32* %13
%15 = call zeroext i16 @ntohs(i32 %14)
%16 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %5, i16 zeroext %15)
ret i32 %9
}