#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 /*<<< orphan*/ serveraddr;
typedef int /*<<< orphan*/ sendbuff;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int /*<<< orphan*/ *);
int /*<<< orphan*/ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int fork();
int getpid();
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ listen(int, int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ send(int, char *, scalar_t__, int /*<<< orphan*/);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ strlen(char *);
int /*<<< orphan*/ wait(int *);
int main() {
  int fd = socket(PF_INET, SOCK_STREAM, 0);
  int connfd;
  int pid;
  char sendbuff[1024];
  struct sockaddr_in serveraddr;
  serveraddr.sin_family = AF_INET;
  serveraddr.sin_addr.s_addr = htonl(INADDR_ANY);
  serveraddr.sin_port = htons(1234);
  bind(fd, (struct sockaddr *)&serveraddr, sizeof(serveraddr));
  listen(fd, 1024);
  int i;
  for (i = 0; i < 10; i++) {
    pid = fork();
    if (pid == 0) {
      while (1) {
        connfd = accept(fd, (struct sockaddr *)NULL, NULL);
        snprintf(sendbuff, sizeof(sendbuff), "accept PID is %d\n", getpid());
        send(connfd, sendbuff, strlen(sendbuff) + 1, 0);
        printf("process %d accept success!\n", getpid());
        close(connfd);
      }
    }
  }
  int status;
  wait(&status);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x450,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2dcf(%rip),%rax
mov    (%rax),%edi
mov    0x2dce(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
mov    %eax,-0x8(%rbp)
mov    0x2dd3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x418(%rbp)
mov    0x2dbc(%rip),%rax
mov    (%rax),%edi
call   1090 <htonl@plt>
mov    %eax,-0x41c(%rbp)
mov    $0x4d2,%edi
call   1050 <htons@plt>
mov    %eax,-0x420(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0xc,%edx
call   10c0 <bind@plt>
mov    -0x8(%rbp),%edi
mov    $0x400,%esi
call   10b0 <listen@plt>
movl   $0x0,-0x424(%rbp)
cmpl   $0xa,-0x424(%rbp)
jge    1353 <main+0x173>
mov    $0x0,%al
call   10f0 <fork@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jne    133a <main+0x15a>
jmp    1292 <main+0xb2>
mov    -0x8(%rbp),%edi
xor    %eax,%eax
mov    %eax,%edx
mov    %rdx,%rsi
call   10d0 <accept@plt>
mov    %eax,-0xc(%rbp)
lea    -0x410(%rbp),%rax
mov    %rax,-0x448(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0x448(%rbp),%rdi
mov    %eax,%ecx
mov    $0x400,%esi
lea    0xd32(%rip),%rdx
call   1080 <snprintf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x43c(%rbp)
lea    -0x410(%rbp),%rax
mov    %rax,-0x438(%rbp)
lea    -0x410(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x43c(%rbp),%edi
mov    -0x438(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x430(%rbp)
xor    %ecx,%ecx
call   1060 <send@plt>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xcea(%rip),%rdi
call   1070 <printf@plt>
mov    -0xc(%rbp),%edi
call   10a0 <close@plt>
jmp    1292 <main+0xb2>
jmp    133f <main+0x15f>
mov    -0x424(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x424(%rbp)
jmp    126c <main+0x8c>
lea    -0x428(%rbp),%rdi
call   10e0 <wait@plt>
xor    %eax,%eax
add    $0x450,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x410,%rsp
mov    0x2dd6(%rip),%rax
mov    (%rax),%edi
mov    0x2dd5(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
mov    %eax,%r14d
mov    0x2dda(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
mov    0x2dc5(%rip),%rax
mov    (%rax),%edi
call   1090 <htonl@plt>
mov    %eax,0x4(%rsp)
mov    $0x4d2,%edi
call   1050 <htons@plt>
mov    %eax,(%rsp)
mov    %rsp,%rsi
mov    %r14d,%edi
mov    $0xc,%edx
call   10c0 <bind@plt>
mov    %r14d,%edi
mov    $0x400,%esi
call   10b0 <listen@plt>
xor    %eax,%eax
call   10f0 <fork@plt>
test   %eax,%eax
je     12e0 <main+0x100>
xor    %eax,%eax
call   10f0 <fork@plt>
test   %eax,%eax
je     12e0 <main+0x100>
xor    %eax,%eax
call   10f0 <fork@plt>
test   %eax,%eax
je     12e0 <main+0x100>
xor    %eax,%eax
call   10f0 <fork@plt>
test   %eax,%eax
je     12e0 <main+0x100>
xor    %eax,%eax
call   10f0 <fork@plt>
test   %eax,%eax
je     12e0 <main+0x100>
xor    %eax,%eax
call   10f0 <fork@plt>
test   %eax,%eax
je     12e0 <main+0x100>
xor    %eax,%eax
call   10f0 <fork@plt>
test   %eax,%eax
je     12e0 <main+0x100>
xor    %eax,%eax
call   10f0 <fork@plt>
test   %eax,%eax
je     12e0 <main+0x100>
xor    %eax,%eax
call   10f0 <fork@plt>
test   %eax,%eax
je     12e0 <main+0x100>
xor    %eax,%eax
call   10f0 <fork@plt>
test   %eax,%eax
je     12e0 <main+0x100>
lea    0x10(%rsp),%rdi
call   10e0 <wait@plt>
xor    %eax,%eax
add    $0x410,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
nopw   0x0(%rax,%rax,1)
mov    %r14d,%edi
xor    %esi,%esi
xor    %edx,%edx
call   10d0 <accept@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xd04(%rip),%rdx
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %eax,%ecx
call   1080 <snprintf@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %ebp,%edi
mov    %rbx,%rsi
xor    %ecx,%ecx
call   1060 <send@plt>
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xcdc(%rip),%rdi
mov    %eax,%esi
call   1070 <printf@plt>
mov    %ebp,%edi
call   10a0 <close@plt>
jmp    12e0 <main+0x100>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@.str = [18 x i8] c"accept PID is %d\0A\00"
@.str.1 = [28 x i8] c"process %d accept success!\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [1024 x i8]
%6 = alloca %struct.sockaddr_in
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %1
%9 = load i32, i32* @PF_INET
%10 = load i32, i32* @SOCK_STREAM
%11 = call i32 @socket(i32 %9, i32 %10, i32 0)
store i32 %11, i32* %2
%12 = load i32, i32* @AF_INET
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, 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* %6, 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 1234)
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
store i32 %18, i32* %19
%20 = load i32, i32* %2
%21 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%22 = call i32 @bind(i32 %20, %struct.sockaddr* %21, i32 12)
%23 = load i32, i32* %2
%24 = call i32 @listen(i32 %23, i32 1024)
store i32 0, i32* %7
br label %25
25: ; preds = %50, %0
%26 = load i32, i32* %7
%27 = icmp slt i32 %26, 10
br i1 %27, label %28, label %53
28: ; preds = %25
%29 = call i32 (...) @fork()
store i32 %29, i32* %4
%30 = load i32, i32* %4
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %49
32: ; preds = %28
br label %33
33: ; preds = %32, %33
%34 = load i32, i32* %2
%35 = call i32 @accept(i32 %34, %struct.sockaddr* null, i32* null)
store i32 %35, i32* %3
%36 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%37 = call i32 (...) @getpid()
%38 = call i32 @snprintf(i8* %36, i32 1024, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %37)
%39 = load i32, i32* %3
%40 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%41 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%42 = call i64 @strlen(i8* %41)
%43 = add nsw i64 %42, 1
%44 = call i32 @send(i32 %39, i8* %40, i64 %43, i32 0)
%45 = call i32 (...) @getpid()
%46 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %45)
%47 = load i32, i32* %3
%48 = call i32 @close(i32 %47)
br label %33
49: ; preds = %28
br label %50
50: ; preds = %49
%51 = load i32, i32* %7
%52 = add nsw i32 %51, 1
store i32 %52, i32* %7
br label %25
53: ; preds = %25
%54 = call i32 @wait(i32* %8)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@.str = [18 x i8] c"accept PID is %d\0A\00"
@.str.1 = [28 x i8] c"process %d accept success!\0A\00"
define i32 @main() {
%1 = alloca [1024 x i8]
%2 = alloca %struct.sockaddr_in
%3 = alloca i32
%4 = load i32, i32* @PF_INET
%5 = load i32, i32* @SOCK_STREAM
%6 = tail call i32 @socket(i32 %4, i32 %5, i32 0)
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%8 = bitcast %struct.sockaddr_in* %2 to i8*
%9 = load i32, i32* @AF_INET
%10 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 2
store i32 %9, i32* %10
%11 = load i32, i32* @INADDR_ANY
%12 = tail call i32 @htonl(i32 %11)
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 1, i32 0
store i32 %12, i32* %13
%14 = tail call i32 @htons(i32 1234)
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 0
store i32 %14, i32* %15
%16 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%17 = call i32 @bind(i32 %6, %struct.sockaddr* %16, i32 12)
%18 = call i32 @listen(i32 %6, i32 1024)
%19 = call i32 (...) @fork()
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %46, %43, %40, %37, %34, %31, %28, %25, %22, %0
br label %52
22: ; preds = %0
%23 = call i32 (...) @fork()
%24 = icmp eq i32 %23, 0
br i1 %24, label %21, label %25
25: ; preds = %22
%26 = call i32 (...) @fork()
%27 = icmp eq i32 %26, 0
br i1 %27, label %21, label %28
28: ; preds = %25
%29 = call i32 (...) @fork()
%30 = icmp eq i32 %29, 0
br i1 %30, label %21, label %31
31: ; preds = %28
%32 = call i32 (...) @fork()
%33 = icmp eq i32 %32, 0
br i1 %33, label %21, label %34
34: ; preds = %31
%35 = call i32 (...) @fork()
%36 = icmp eq i32 %35, 0
br i1 %36, label %21, label %37
37: ; preds = %34
%38 = call i32 (...) @fork()
%39 = icmp eq i32 %38, 0
br i1 %39, label %21, label %40
40: ; preds = %37
%41 = call i32 (...) @fork()
%42 = icmp eq i32 %41, 0
br i1 %42, label %21, label %43
43: ; preds = %40
%44 = call i32 (...) @fork()
%45 = icmp eq i32 %44, 0
br i1 %45, label %21, label %46
46: ; preds = %43
%47 = call i32 (...) @fork()
%48 = icmp eq i32 %47, 0
br i1 %48, label %21, label %49
49: ; preds = %46
%50 = bitcast i32* %3 to i8*
%51 = call i32 @wait(i32* %3)
ret i32 0
52: ; preds = %21, %52
%53 = call i32 @accept(i32 %6, %struct.sockaddr* null, i32* null)
%54 = call i32 (...) @getpid()
%55 = call i32 @snprintf(i8* %7, i32 1024, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %54)
%56 = call i64 @strlen(i8* %7)
%57 = add nsw i64 %56, 1
%58 = call i32 @send(i32 %53, i8* %7, i64 %57, i32 0)
%59 = call i32 (...) @getpid()
%60 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %59)
%61 = call i32 @close(i32 %53)
br label %52
}