#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 dummy;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ srvaddr;
typedef int socklen_t;
typedef int /*<<< orphan*/ cliaddr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int *);
int /*<<< orphan*/ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fill_values(struct sockaddr_in *);
int /*<<< orphan*/ listen(int, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
void tcp_listener() {
  int sockfd, connfd;
  struct sockaddr_in srvaddr, cliaddr;
  socklen_t clilen;
  char clibuff[1024];
  sockfd = socket(AF_INET, SOCK_STREAM, 0);
  fill_values(&srvaddr);
  bind(sockfd, (struct sockaddr *)&srvaddr, sizeof(srvaddr));
  listen(sockfd, 1024);
  clilen = sizeof(cliaddr);
  connfd = accept(sockfd, (struct sockaddr *)&cliaddr, &clilen);
  while (1) {
  }
  close(connfd);
}


x86 assembly (clang, -O0):
<tcp_listener>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    0x2e86(%rip),%rax
mov    (%rax),%edi
mov    0x2e6d(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1070 <socket@plt>
mov    %eax,-0x4(%rbp)
lea    -0x10(%rbp),%rdi
call   1030 <fill_values@plt>
mov    -0x4(%rbp),%edi
lea    -0x10(%rbp),%rsi
mov    $0x4,%edx
call   1050 <bind@plt>
mov    -0x4(%rbp),%edi
mov    $0x400,%esi
call   1040 <listen@plt>
movl   $0x4,-0x1c(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x18(%rbp),%rsi
lea    -0x1c(%rbp),%rdx
call   1060 <accept@plt>
mov    %eax,-0x8(%rbp)
jmp    11b8 <tcp_listener+0x68>

x86 assembly (clang, -O2):
<tcp_listener>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    0x2e8a(%rip),%rax
mov    (%rax),%edi
mov    0x2e71(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1070 <socket@plt>
mov    %eax,%ebx
lea    0x10(%rsp),%r14
mov    %r14,%rdi
call   1030 <fill_values@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x4,%edx
call   1050 <bind@plt>
mov    %ebx,%edi
mov    $0x400,%esi
call   1040 <listen@plt>
movl   $0x4,0x4(%rsp)
lea    0x8(%rsp),%rsi
lea    0x4(%rsp),%rdx
mov    %ebx,%edi
call   1060 <accept@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
jmp    11c0 <tcp_listener+0x70>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
define void @tcp_listener() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.sockaddr_in
%4 = alloca %struct.sockaddr_in
%5 = alloca i32
%6 = alloca [1024 x i8]
%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 = call i32 @fill_values(%struct.sockaddr_in* %3)
%11 = load i32, i32* %1
%12 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%13 = call i32 @bind(i32 %11, %struct.sockaddr* %12, i32 4)
%14 = load i32, i32* %1
%15 = call i32 @listen(i32 %14, i32 1024)
store i32 4, i32* %5
%16 = load i32, i32* %1
%17 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%18 = call i32 @accept(i32 %16, %struct.sockaddr* %17, i32* %5)
store i32 %18, i32* %2
br label %19
19: ; preds = %0, %19
br label %19
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
define void @tcp_listener() {
%1 = alloca %struct.sockaddr_in
%2 = alloca %struct.sockaddr_in
%3 = alloca i32
%4 = bitcast %struct.sockaddr_in* %1 to i8*
%5 = bitcast %struct.sockaddr_in* %2 to i8*
%6 = bitcast i32* %3 to i8*
%7 = load i32, i32* @AF_INET
%8 = load i32, i32* @SOCK_STREAM
%9 = tail call i32 @socket(i32 %7, i32 %8, i32 0)
%10 = call i32 @fill_values(%struct.sockaddr_in* %1)
%11 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%12 = call i32 @bind(i32 %9, %struct.sockaddr* %11, i32 4)
%13 = call i32 @listen(i32 %9, i32 1024)
store i32 4, i32* %3
%14 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%15 = call i32 @accept(i32 %9, %struct.sockaddr* %14, i32* %3)
br label %16
16: ; preds = %16, %0
br label %16
}