#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*/ servaddr;
typedef int /*<<< orphan*/ cliaddr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ Bind(int, struct sockaddr *, int);
scalar_t__ EINTR;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ Listen(int, int);
int /*<<< orphan*/ SOCK_STREAM;
int Socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int accept(int, struct sockaddr *, int *);
int /*<<< orphan*/ err_sys(char *);
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ service(int);
int main(void) {
  int listenfd, connfd;
  socklen_t clilen;
  struct sockaddr_in cliaddr, servaddr;
  listenfd = Socket(AF_INET, SOCK_STREAM, 0);
  memset(&servaddr, 0, sizeof(servaddr));
  servaddr.sin_family = AF_INET;
  servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
  servaddr.sin_port = htons(5780);
  Bind(listenfd, (struct sockaddr *)&servaddr, sizeof(servaddr));
  Listen(listenfd, 1024);
  for (;;) {
    clilen = sizeof(cliaddr);
    if ((connfd = accept(listenfd, (struct sockaddr *)&cliaddr, &clilen)) < 0) {
      if (errno == EINTR)
        continue;
      else
        err_sys("accept error");
    }
    service(connfd);
    exit(1);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e32(%rip),%rax
mov    (%rax),%edi
mov    0x2e11(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1090 <Socket@plt>
mov    %eax,-0x8(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1060 <memset@plt>
mov    0x2e06(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    0x2df2(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %eax,-0x2c(%rbp)
mov    $0x1694,%edi
call   1040 <htons@plt>
mov    %eax,-0x30(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0xc,%edx
call   1080 <Bind@plt>
mov    -0x8(%rbp),%edi
mov    $0x400,%esi
call   1070 <Listen@plt>
movl   $0xc,-0x10(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x20(%rbp),%rsi
lea    -0x10(%rbp),%rdx
call   10b0 <accept@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jge    1276 <main+0xd6>
mov    0x2d7b(%rip),%rax
mov    (%rax),%rax
mov    0x2d69(%rip),%rcx
cmp    (%rcx),%rax
jne    1265 <main+0xc5>
jmp    1223 <main+0x83>
lea    0xd94(%rip),%rdi
call   1030 <err_sys@plt>
jmp    1276 <main+0xd6>
mov    -0xc(%rbp),%edi
call   10a0 <service@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    0x2e33(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2e11(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1090 <Socket@plt>
mov    %eax,%ebx
lea    0x8(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1060 <memset@plt>
mov    0x0(%rbp),%eax
mov    %eax,0x10(%rsp)
mov    0x2df4(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %eax,0xc(%rsp)
mov    $0x1694,%edi
call   1040 <htons@plt>
mov    %eax,0x8(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0xc,%edx
call   1080 <Bind@plt>
mov    %ebx,%edi
mov    $0x400,%esi
call   1070 <Listen@plt>
lea    0x18(%rsp),%r14
lea    0x4(%rsp),%r15
mov    0x2d97(%rip),%r12
mov    0x2d88(%rip),%r13
nopl   0x0(%rax,%rax,1)
movl   $0xc,0x4(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    %r15,%rdx
call   10b0 <accept@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    1271 <main+0xd1>
mov    (%r12),%rax
cmp    0x0(%r13),%rax
je     1240 <main+0xa0>
lea    0xd94(%rip),%rdi
call   1030 <err_sys@plt>
mov    %ebp,%edi
call   10a0 <service@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>

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
@errno = global i64 0
@EINTR = global i64 0
@.str = [13 x i8] c"accept error\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.sockaddr_in
%6 = alloca %struct.sockaddr_in
store i32 0, i32* %1
%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* %2
%10 = call i32 @memset(%struct.sockaddr_in* %6, i32 0, i32 12)
%11 = load i32, i32* @AF_INET
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 2
store i32 %11, i32* %12
%13 = load i32, i32* @INADDR_ANY
%14 = call i32 @htonl(i32 %13)
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 1
%16 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %15, i32 0, i32 0
store i32 %14, i32* %16
%17 = call i32 @htons(i32 5780)
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
store i32 %17, i32* %18
%19 = load i32, i32* %2
%20 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%21 = call i32 @Bind(i32 %19, %struct.sockaddr* %20, i32 12)
%22 = load i32, i32* %2
%23 = call i32 @Listen(i32 %22, i32 1024)
br label %24
24: ; preds = %33, %0
store i32 12, i32* %4
%25 = load i32, i32* %2
%26 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%27 = call i32 @accept(i32 %25, %struct.sockaddr* %26, i32* %4)
store i32 %27, i32* %3
%28 = icmp slt i32 %27, 0
br i1 %28, label %29, label %37
29: ; preds = %24
%30 = load i64, i64* @errno
%31 = load i64, i64* @EINTR
%32 = icmp eq i64 %30, %31
br i1 %32, label %33, label %34
33: ; preds = %29
br label %24
34: ; preds = %29
%35 = call i32 @err_sys(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %36
36: ; preds = %34
br label %37
37: ; preds = %36, %24
%38 = load i32, i32* %3
%39 = call i32 @service(i32 %38)
%40 = call i32 @exit(i32 1)
unreachable
}

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
@errno = global i64 0
@EINTR = global i64 0
@.str = [13 x i8] c"accept error\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.sockaddr_in
%3 = alloca %struct.sockaddr_in
%4 = bitcast i32* %1 to i8*
%5 = bitcast %struct.sockaddr_in* %2 to i8*
%6 = bitcast %struct.sockaddr_in* %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 @memset(%struct.sockaddr_in* %3, i32 0, i32 12)
%11 = load i32, i32* @AF_INET
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %11, i32* %12
%13 = load i32, i32* @INADDR_ANY
%14 = call i32 @htonl(i32 %13)
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
store i32 %14, i32* %15
%16 = call i32 @htons(i32 5780)
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %16, i32* %17
%18 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%19 = call i32 @Bind(i32 %9, %struct.sockaddr* %18, i32 12)
%20 = call i32 @Listen(i32 %9, i32 1024)
%21 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
br label %22
22: ; preds = %25, %0
store i32 12, i32* %1
%23 = call i32 @accept(i32 %9, %struct.sockaddr* %21, i32* %1)
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %31
25: ; preds = %22
%26 = load i64, i64* @errno
%27 = load i64, i64* @EINTR
%28 = icmp eq i64 %26, %27
br i1 %28, label %22, label %29
29: ; preds = %25
%30 = call i32 @err_sys(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %31
31: ; preds = %22, %29
%32 = call i32 @service(i32 %23)
%33 = call i32 @exit(i32 1)
unreachable
}